-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathheadTracking.cpp
101 lines (80 loc) · 3.03 KB
/
headTracking.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
#include <iostream>
#include "global.hpp"
#include "Tracker.hpp"
#include "cvLib.hpp"
using namespace std;
using namespace cv;
int main(int argc, char* argv[]) {
/* Basic info */
if (argc != 3) {
cout << "hogHeadDet input-vid-path "
<< "display-result[y/n]" << endl;
exit(-1);
}
cout << "OpenCV version " << CV_VERSION << endl;
/* Initialization */
Mat frame; // to store video frames
vector<Rect> found; // to store detection results
unsigned int count = 160; // initialize the fist frame to be decoded, 80
vector<TrackingObj> tracker; // a tracker to monitor all heads
/* Build detector */
HOGDescriptor hog(winSize, blockSize, blockStride, cellSize, nbins);
buildDetector(hog, detectorPath);
/* Read in frames and process */
VideoCapture targetVid(argv[1]);
if(!targetVid.isOpened()) {
cout << "open failed." << endl;
exit(-1);
}
unsigned int totalFrame = targetVid.get(CV_CAP_PROP_FRAME_COUNT);
/* Set current to a pre-defined frame */
targetVid.set(CV_CAP_PROP_POS_FRAMES, count);
for(;;) {
count++;
targetVid >> frame;
if(frame.empty()) {
break;
}
/* get frame progress */
sprintf(countStr, "%04d", count); // padding with zeros
cout << "------------------------------------------"
<< "------------------------------------------" << endl;
cout << "frame\t" << countStr << "/" << totalFrame << endl;
/* process a frame and get detection result */
resize(frame, frame, imgSize); // set to same-scale as train
hog.detectMultiScale(frame, found, 0, winStride, Size(0, 0), 1.05, 3);
/* remove inner boxes */
found = rmInnerBoxes(found);
/* extend bounding box */
extBBox(found);
Mat dispFrame;
frame.copyTo(dispFrame);
/* draw bounding box */
drawBBox(found, dispFrame);
/* put information on image */
putText(dispFrame,
"frame " + string(countStr) + "/" + to_string(totalFrame),
cvPoint(20, 20), FONT_HERSHEY_COMPLEX_SMALL,
0.8, cvScalar(0, 0, 0)); // frame progress
/* Display image */
// imshow("demo", dispFrame);
// pauseFrame(1);
/* get cropped images in detRests */
updateTracker(found, frame, tracker);
// countRests(detRests); // count detection results counting
/* save cropped image */
// svCroppedImg(found, frame);
/* counting */
// countHead(detRests, frame, memoHead, up, down);
putText(dispFrame, "up: " + to_string(upAccum) +
" down: " + to_string(downAccum),
cvPoint(20, 40), FONT_HERSHEY_COMPLEX_SMALL,
0.8, cvScalar(0, 0, 0)); // up / down counting
/* show detection result */
if (string(argv[2]) == "y") {
imshow("demo", dispFrame);
pauseFrame(1);
}
}
return 0;
}