-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
75 lines (64 loc) · 2.71 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "FrameStreamer.hpp"
#include "Logger.hpp"
#include "PoseEstimator.hpp"
#include <chrono>
#include <filesystem>
#include <iostream>
#include <memory.h>
#include <opencv2/core.hpp>
#include <opencv2/dnn.hpp>
int main( )
{
std::unique_ptr<Logger::ILogger> logger = std::make_unique<Logger::CoutLogger>( Logger::Priority::Info );
PoseEstimator model( std::move( logger ) );
const std::string modelFile = "yolov7-w6-pose.onnx"; // "Yolov5s6_pose_640.onnx"; // "yolov7-w6-pose.onnx";
model.Initialize(
std::filesystem::path( __FILE__ ).remove_filename( ).append( modelFile ).wstring( ).c_str( ),
PoseEstimator::RuntimeBackend::TensorRT,
"yolo-pose"
);
auto RunPoseEstimation = [ &model ]( const cv::Mat& frame ) {
// * Preprocess data
const PoseEstimator::InputSize modelInputSize = model.GetModelInputSize( );
constexpr int batchSize = 1;
const int size[] = { batchSize, modelInputSize.channels, modelInputSize.width, modelInputSize.height };
cv::Mat inputBlob( 4, size, CV_32F );
cv::dnn::blobFromImage(
frame,
inputBlob,
0.00392156862745098,
cv::Size( modelInputSize.width, modelInputSize.height ),
cv::Scalar( 0, 0, 0, 0 ),
true,
false,
CV_32F
);
// * Forward propagate
std::vector<PoseEstimator::Detection> output;
model.Forward( output, ( float* ) inputBlob.data, 640, 640, 3 );
return FrameStreamer::Result{
output,
{ .wFactor = static_cast<float>( frame.cols ) / static_cast<float>( modelInputSize.width ),
.hFactor = static_cast<float>( frame.rows ) / static_cast<float>( modelInputSize.height ) } };
};
// const std::string imgFile = "data/img.png";
// auto fs = CreateFrameStreamer<ImageStreamer>(
// std::filesystem::path( __FILE__ ).remove_filename( ).append( imgFile ).string( )
// );
const std::string videoFile = "data/dancer.mp4";
const auto fs = CreateFrameStreamer<VideoStreamer>(
std::filesystem::path( __FILE__ ).remove_filename( ).append( videoFile ).string( )
);
if ( fs )
fs->Run( RunPoseEstimation );
}
// TODO: Fix find path for onnx
// TODO: Proxy onnxruntime
// TODO: Implement a CameraStreamer
// TODO: Add a frame counter in the image
// TODO: Pimpl to avoid exposing cv::videoio outwards (and ort api from pose estimator)
// TODO: Capture if trying to load image to video streamer
// TODO: Returns silently if cannot find video file
// TODO: Resize video to specified size
// TODO: Pause & step video
// TODO: Separate types to specific headers such as bounding box etc to reduce PoseEstimator dependancies