-
Notifications
You must be signed in to change notification settings - Fork 30
/
runtracker-IMG.cpp
141 lines (107 loc) · 3.06 KB
/
runtracker-IMG.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
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "kcftracker.hpp"
#include <dirent.h>
#include <time.h>
using namespace std;
using namespace cv;
int main(int argc, char* argv[]){
if (argc > 5) return -1;
bool HOG = true;
bool FIXEDWINDOW = false;
bool MULTISCALE = true;
bool SILENT = false;
bool LAB = false;
for(int i = 0; i < argc; i++){
if ( strcmp (argv[i], "hog") == 0 )
HOG = true;
if ( strcmp (argv[i], "fixed_window") == 0 )
FIXEDWINDOW = true;
if ( strcmp (argv[i], "singlescale") == 0 )
MULTISCALE = false;
if ( strcmp (argv[i], "show") == 0 )
SILENT = false;
if ( strcmp (argv[i], "lab") == 0 ){
LAB = true;
HOG = true;
}
if ( strcmp (argv[i], "gray") == 0 )
HOG = false;
}
// Create KCFTracker object
KCFTracker tracker(HOG, FIXEDWINDOW, MULTISCALE, LAB);
// Frame readed
Mat frame;
// Tracker results
Rect result;
string base = "Test/CarDark/";
// Path to list.txt
ifstream listFile;
string fileName = base + "images.txt";
listFile.open(fileName);
// Read groundtruth for the 1st frame
ifstream groundtruthFile;
string groundtruth = base + "init.txt";
groundtruthFile.open(groundtruth);
string firstLine;
getline(groundtruthFile, firstLine);
groundtruthFile.close();
istringstream ss(firstLine);
printf("%s\n", groundtruth.c_str());
// Read groundtruth like a dumb
// float x1, y1, x2, y2;
float xMin;
float yMin;
float width;
float height;
ss >> xMin;
ss >> yMin;
ss >> width;
ss >> height;
// Using min and max of X and Y for groundtruth rectangle
// printf("%f:%f:%f:%f\n", width, height, xMin, yMin);
// Read Images
ifstream listFramesFile;
string listFrames = base + "images.txt";
listFramesFile.open(listFrames);
string frameName;
// Write Results
// ofstream resultsFile;
// string resultsPath = "output.txt";
// resultsFile.open(resultsPath);
// Frame counter
int nFrames = 0;
clock_t start,end; // typedef long clock_t
start = clock();
while ( getline(listFramesFile, frameName) ){
frameName = frameName;
// Read each frame from the list
frame = imread(base + frameName, CV_LOAD_IMAGE_COLOR);
// First frame, give the groundtruth to the tracker
if (nFrames == 0) {
tracker.init( Rect(xMin, yMin, width, height), frame );
rectangle( frame, Point( xMin, yMin ), Point( xMin+width, yMin+height), Scalar( 0, 255, 255 ), 1, 8 );
// resultsFile << xMin << "," << yMin << "," << width << "," << height << endl;
}
// Update
else{
result = tracker.update(frame);
rectangle( frame, Point( result.x, result.y ), Point( result.x+result.width, result.y+result.height), Scalar( 0, 255, 255 ), 1, 8 );
// resultsFile << result.x << "," << result.y << "," << result.width << "," << result.height << endl;
}
nFrames++;
if (!SILENT){
imshow("Image", frame);
waitKey(1);
}
}
end = clock();
double duration =(double)(end-start)/CLOCKS_PER_SEC;
printf("%f\n",nFrames/duration);
// resultsFile.close();
listFile.close();
}