-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.cpp
145 lines (118 loc) · 2.76 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <ctime>
#include <iostream>
#include <sstream>
#include <fstream>
#include <windows.h>
#include "tracker.h"
#include "detector.h"
#include "dataReader.h"
#include "multiTrackAssociation.h"
#include "parameter.h"
using namespace cv;
using namespace std;
static string _sequence_path_;
static string _detection_xml_file_;
//Configuration
int MAX_TRACKER_NUM;
int MAX_TEMPLATE_SIZE;
int EXPERT_THRESH;
double BODYSIZE_TO_DETECTION_RATIO;
double TRACKING_TO_BODYSIZE_RATIO;
int FRAME_RATE;
double TIME_WINDOW_SIZE;
double HOG_DETECT_FRAME_RATIO;
void read_config()
{
ifstream conf_file("config.txt");
if (!conf_file.is_open())
{
cerr<<"fail to load config.txt."<<endl;
exit(1);
}
string line;
while (conf_file.good())
{
getline(conf_file,line);
istringstream line_s(line);
string field;
line_s>>field;
if (field.compare("MAX_TRACKER_NUM:")==0)
line_s>>MAX_TRACKER_NUM;
else if (field.compare("FRAME_RATE:")==0)
line_s>>FRAME_RATE;
else if (field.compare("TIME_WINDOW_SIZE:")==0)
line_s>>TIME_WINDOW_SIZE;
else if (field.compare("HOG_DETECT_FRAME_RATIO:")==0)
line_s>>HOG_DETECT_FRAME_RATIO;
else if (field.compare("MAX_TEMPLATE_SIZE:")==0)
line_s>>MAX_TEMPLATE_SIZE;
else if (field.compare("EXPERT_THRESH:")==0)
line_s>>EXPERT_THRESH;
else if (field.compare("BODYSIZE_TO_DETECTION_RATIO:")==0)
line_s>>BODYSIZE_TO_DETECTION_RATIO;
else if (field.compare("TRACKING_TO_BODYSIZE_RATIO:")==0)
line_s>>TRACKING_TO_BODYSIZE_RATIO;
}
conf_file.close();
}
void multiTrack(int readerType,int detectorType)
{
namedWindow("multiTrack",CV_WINDOW_AUTOSIZE);
SeqReader* reader;
Mat frame;
reader = new VideoReader(_sequence_path_);
Sleep(1000);
reader->readImg(frame);
if (frame.data==NULL)
{
cerr<<"fail to open pictures!"<<endl;
return ;
}
Detector* detector;
detector = new FaceDetector();
TrakerManager mTrack(detector,frame,EXPERT_THRESH);
for (int frameCount=0;frame.data!=NULL;frameCount++)
{
mTrack.doWork(frame);
if (frame.cols>640)
resize(frame, frame, Size(640, frame.rows / (frame.cols/640)));
imshow("multiTrack", frame);
reader->readImg(frame);
char c = waitKey(33);
if(c == 'q') break;
else if (c=='p')
{
waitKey(0);
}
else if(c != -1)
{
mTrack.setKey(c);
}
}
delete reader;
delete detector;
}
void help()
{
cout << "usage: \n\n"
"1.\n"
"FacedetectAndTracking <sequence_path> \n"
"(调用视频:<sequence_path>为视频地址)\n\n"
"2.\n"
"FacedetectAndTracking <sequence_path> \n"
"(调用摄像头:<sequence_path>为摄像头编号,自带为0,usb摄像头插的为1)\n\n";
getchar();
}
int main(int argc,char** argv)
{
if (argc !=2)
{
help();
exit(1);
}
read_config();
_sequence_path_=string(argv[1]);
int seq_format=VIDEO;
multiTrack(seq_format, FACE);
return 0;
}