-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (53 loc) · 1.79 KB
/
main.cpp
File metadata and controls
66 lines (53 loc) · 1.79 KB
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
#include "SCGMM_JT.h"
cv::Mat origImg, segImg, gtImg;
cv::Mat fgdSamples, bgdSamples;
int main(int argc, char *argv[]) {
vector<cv::Mat> origImgs, gtImgs;
cout << "Reading " << argv[1] << " original and ground truth images... ";
getImgSeqFromDir(argv[2], argv[3], atoi(argv[1]), origImgs, gtImgs);
cout << "Done!" << endl;
origImg = origImgs.front();
gtImg = gtImgs.front();
cv::namedWindow("original");
cv::namedWindow("ground truth");
cv::imshow("original", origImg);
cv::imshow("ground truth", gtImg);
/*
* Use the whole image to be our training samples for initialization.
*/
for (int i = 0; i < gtImg.rows; i++) {
for (int j = 0; j < gtImg.cols; j++) {
cv::Mat sample = (cv::Mat_<double>(1, 5) << j, i, origImg.at<cv::Vec3b>(i, j)[0], origImg.at<cv::Vec3b>(i, j)[1], origImg.at<cv::Vec3b>(i, j)[2]);
if (gtImg.at<cv::Vec3b>(i, j) == cv::Vec3b(255, 255, 255))
fgdSamples.push_back(sample);
else
bgdSamples.push_back(sample);
}
}
while (1) {
int key = cv::waitKey(1);
if (key == 27)
break;
else if (key == 's') {
clock_t start, end;
SCGMM_JT model;
cout << "Initializing SCGMM Joint Tracking... ";
start = clock();
model.init(origImg, fgdSamples, bgdSamples);
end = clock();
cout << "Done! (" << (end - start) / (double)CLOCKS_PER_SEC << "s)" << endl;
for (int imgIndex = 0; imgIndex < origImgs.size(); imgIndex++) {
cout << "Processing frame " << imgIndex << "... ";
start = clock();
model.run(origImgs.at(imgIndex), segImg);
end = clock();
cout << "Done! (" << (end - start) / (double)CLOCKS_PER_SEC << "s)" << endl;
cout << "Accuracy: " << calcAccuracy(segImg, gtImgs.at(imgIndex)) << endl;
stringstream ss;
ss << "result/" << imgIndex << ".png";
cv::imwrite(ss.str(), segImg);
}
}
}
return 0;
}