-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
115 lines (97 loc) · 3.17 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <opencv2/opencv.hpp>
#include <iostream>
#include "config.hpp"
#include "objectdetector.hpp"
#include "trackinglist.hpp"
#include "chronometer.hpp"
#include "drawer.hpp"
using namespace std;
int main(void)
{
////////////////////////////////////////
////////////////////////////////////////
// INITIALIZE VARIABLES AND VECOTR //
////////////////////////////////////////
////////////////////////////////////////
Config config;
TrackingList trackingList(config);
Drawer drawer(config);
Chronometer chronometer;
ObjectDetector detector(config);
int trackingID = 0;
int detectionRate = config.detectionRate;
cv::VideoCapture cap;
if (config.captureFromVideo)
{
cap.open(config.videoAddress);
if (!cap.isOpened())
{
cout << "no video provided, sth went wrong" << endl;
exit(-1);
}
}
else if (config.captureFromCamera)
{
cap.open(config.cameraDevice);
if (!cap.isOpened())
{
cout << "no capture device, sth went wrong" << endl;
exit(-1);
}
cap.set(cv::CAP_PROP_FRAME_WIDTH, config.outputWindowWidth);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, config.outputWindowHeight);
}
else
{
cout << "no input specified" << endl;
exit(-1);
}
cv::Mat frame;
cv::namedWindow("result", 1);
int frameNo = 0;
////////////////////////////////////////
////////////////////////////////////////
// MAIN LOOP //
////////////////////////////////////////
////////////////////////////////////////
for (chronometer.tic();; frameNo++)
{
cap >> frame;
detector.clearList();
if (frameNo % detectionRate == 0)
{
bool newDetection = detector.detect(frame);
trackingList.cleanTrackers();
trackingList.removeFailedTrackers(detector);
if (newDetection)
{
for (int i = 0; i < detector.detectionLabels.size(); i++)
{
int intersectionIndex = trackingList.checkIntersection(detector, i);
if (intersectionIndex == -1)
trackingList.initTracker(frame, detector, i, trackingID);
else
trackingList.adjustTracker(frame, intersectionIndex, detector, i);
}
}
}
trackingList.updateTrackers(frame);
drawer.draw(frame, trackingList);
cv::imshow("result", frame);
if (cv::waitKey(30) >= 0)
break;
}
////////////////////////////////////////
////////////////////////////////////////
// END OF MAIN LOOP //
////////////////////////////////////////
////////////////////////////////////////
cap.release();
cout << "FrameRate: " << (double)frameNo / (chronometer.toc() / 1000) << endl;
return 0;
////////////////////////////////////////
////////////////////////////////////////
// END OF program //
////////////////////////////////////////
////////////////////////////////////////
}