Repository navigation
Expand file tree
/
Copy pathmain_cam.cpp
More file actions
83 lines (62 loc) · 1.5 KB
/
Copy pathmain_cam.cpp
File metadata and controls
83 lines (62 loc) · 1.5 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <opencv2/opencv.hpp>
#include "kfebtracker.h"
#define CAMERA 0
bool mousePress;
bool rectOK;
cv::Rect initRect;
static void onMouse( int event, int x, int y, int, void* ){
if( event != cv::EVENT_LBUTTONDOWN || rectOK)
return;
if(mousePress){
initRect.width = x - initRect.x;
initRect.height = y - initRect.y;
rectOK = true;
}
if(!mousePress){
initRect.x = x;
initRect.y = y;
mousePress = true;
}
}
int main(void){
// interface
mousePress = false;
rectOK = false;
KFebTracker tracker;
tracker.init("AK");
cv::Mat image;
bool run = 1;
cv::VideoCapture cam(CAMERA);
if(!cam.isOpened()){
std::cout << "Error: Camera not found!\n";
return 1;
}
cam >> image;
cv::imshow("result", image);
cv::setMouseCallback("result", onMouse,0);
while(!mousePress){
cam >> image;
cv::imshow("result", image);
cv::waitKey(10);
}
while(!rectOK){
cv::waitKey(10);
}
tracker.initTrackers(image, initRect);
while (run){
// Read image
cam >> image;
if(image.empty()){
break;
}
//Report result
cv::Rect output = tracker.track(image);
cv::Mat saida = image.clone();
cv::rectangle(saida, output, cv::Scalar(0,255,0), 2);
cv::imshow("result", saida);
char key = cv::waitKey(10);
if(key == 27)
break;
}
return 0;
}