forked from Smorodov/Multitarget-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoExample.h
More file actions
79 lines (62 loc) · 2 KB
/
VideoExample.h
File metadata and controls
79 lines (62 loc) · 2 KB
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
76
77
78
79
#pragma once
#include <iostream>
#include <vector>
#include <map>
#include <thread>
#include <mutex>
#include <chrono>
#include <condition_variable>
#include <atomic>
#include "BaseDetector.h"
#include "Ctracker.h"
///
/// \brief The VideoExample class
///
class VideoExample
{
public:
VideoExample(const cv::CommandLineParser& parser);
VideoExample(const VideoExample&) = delete;
VideoExample(VideoExample&&) = delete;
VideoExample& operator=(const VideoExample&) = delete;
VideoExample& operator=(VideoExample&&) = delete;
virtual ~VideoExample() = default;
void AsyncProcess();
void SyncProcess();
protected:
std::unique_ptr<BaseDetector> m_detector;
std::unique_ptr<CTracker> m_tracker;
bool m_showLogs = true;
float m_fps = 25;
int m_captureTimeOut = 60000;
int m_trackingTimeOut = 60000;
static void CaptureAndDetect(VideoExample* thisPtr, std::atomic<bool>& stopCapture);
virtual bool InitDetector(cv::UMat frame) = 0;
virtual bool InitTracker(cv::UMat frame) = 0;
void Detection(cv::Mat frame, regions_t& regions);
void Tracking(cv::Mat frame, const regions_t& regions);
virtual void DrawData(cv::Mat frame, int framesCounter, int currTime) = 0;
void DrawTrack(cv::Mat frame, int resizeCoeff, const TrackingObject& track, bool drawTrajectory = true);
private:
bool m_isTrackerInitialized = false;
bool m_isDetectorInitialized = false;
std::string m_inFile;
std::string m_outFile;
int m_fourcc = cv::VideoWriter::fourcc('M', 'J', 'P', 'G');
int m_startFrame = 0;
int m_endFrame = 0;
int m_finishDelay = 0;
std::vector<cv::Scalar> m_colors;
struct FrameInfo
{
cv::Mat m_frame;
regions_t m_regions;
int64 m_dt = 0;
std::condition_variable m_cond;
std::mutex m_mutex;
bool m_captured = false;
};
FrameInfo m_frameInfo[2];
bool OpenCapture(cv::VideoCapture& capture);
bool WriteFrame(cv::VideoWriter& writer, const cv::Mat& frame);
};