-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.cpp
56 lines (47 loc) · 1.33 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
#include "det_and_track.h"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
int main( int argc, char** argv )
{
DetAndTrack dtObject;
//cv::VideoCapture cap("/home/lingkang/Videos/band.mp4");
cv::VideoCapture cap(0);
cv::Mat frame;
int cnt = 20;
while(cnt --)
{
cap >> frame;
}
dtObject.setFrame(frame);
std::thread detThread(&DetAndTrack::detectionTask, &dtObject);
std::thread trackThread(&DetAndTrack::trackTask, &dtObject);
while(true)
{
cap >> frame;
//uncomment the next line when reading from a video
//std::this_thread::sleep_for(std::chrono::milliseconds(35));
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(frame, box, colors[i], 2, 1);
i ++;
}
std::cout << "start drawing.." << std::endl;
cv::imshow("detandtrack", frame);
if(cv::waitKey(1) == 27)
{
break;
}
}
detThread.join();
trackThread.join();
return 0;
}