forked from zlingkang/pedestrian_detection_and_tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
60 lines (50 loc) · 1.48 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
#include "det_and_track.h"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
int main( int argc, char** argv )
{
DetAndTrack dtObject;
cv::VideoCapture cap("../MOT17-11.mp4");
//cv::VideoCapture cap(0);
cv::Mat frame;
cap >> frame;
dtObject.setFrame(frame);
std::thread detThread(&DetAndTrack::detectionTask, &dtObject);
std::thread trackThread(&DetAndTrack::trackTask, &dtObject);
while(true)
{
cap >> frame;
if(frame.empty())
{
break;
}
cv::Mat result = frame.clone();
//uncomment the next line when reading from a video
std::this_thread::sleep_for(std::chrono::milliseconds(40));
std::vector<cv::Rect> boxes;
std::vector<cv::Scalar> colors;
std::cout << "set new frame.." << std::endl;
dtObject.mutex_.lock();
boxes = dtObject.getBox();
colors = dtObject.getColor();
dtObject.setFrame(frame);
dtObject.mutex_.unlock();
int i = 0;
for(auto box:boxes)
{
cv::rectangle(result, box, colors[i], 2, 1);
//cv::rectangle(result, box, cv::Scalar(0,0,255), 2, 1);
i ++;
std::cout << box << std::endl;
}
std::cout << "start drawing.." << std::endl;
cv::imshow("detandtrack", result);
if(cv::waitKey(1) == 27)
{
break;
}
}
detThread.join();
trackThread.join();
return 0;
}