forked from psenna/KF-EBT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
144 lines (110 loc) · 4.01 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
// VOT test
#include <opencv2/opencv.hpp>
#include <unistd.h>
#include "trackers/tasms.h"
#include "trackers/tkcf.h"
#include "trackers/tcbt.h"
#include "trackers/tmosse.h"
#include "trackers/tvdp.h"
#include "trackers/tgrayasms.h"
#include "trackers/tncc.h"
#include "kfebt.h"
#include "trax.h"
int main(int argc, char *argv[]){
float ajuste = 0.30;
// Alocate trackers
tASMS asms(ajuste, 1.0);
tKCF kcf(ajuste, 1.10);
tCBT cbt(ajuste, 0.45);
tVDP vdp(ajuste, 0.60);
tncc ncc(ajuste, 0.75);
KFEBT fusion;
std::vector<BTracker*> trackers;
//trackers.push_back(&cbt);
//trackers.push_back(&vdp);
trackers.push_back(&kcf);
trackers.push_back(&asms);
trackers.push_back(&ncc);
trax_handle* trax;
trax_metadata* config = trax_metadata_create(TRAX_REGION_RECTANGLE, TRAX_IMAGE_PATH, "KFebT", "KFebT", "none");
trax_image* img = NULL;
trax_region* rect = NULL;
// Call trax_server_setup to initialize trax protocol
trax = trax_server_setup(config, trax_no_log);
cv::Rect region;
cv::Mat image;
std::vector<float> uncertainty, trackersResults;
bool run = 1;
while (run){
trax_properties* prop = trax_properties_create();
int tr = trax_server_wait(trax, &img, &rect, prop);
if (tr == TRAX_INITIALIZE){
float x, y, width, height;
trax_region_get_rectangle(rect, &x, &y, &width, &height);
region.x = x;
region.y = y;
region.width = width;
region.height = height;
image = cv::imread(img->data);
// Inicializatiuon
for(unsigned int i = 0; i < trackers.size(); i++){
trackers[i]->init(image, region);
}
// Alocate KFEBT
fusion = KFEBT(9, 3*trackers.size(), 0, 0.05, region);
if(argc >= 7){
float adj = atof(argv[5]);
fusion.setProcessCov(adj);
}
trax_server_reply(trax, rect, NULL);
} else if (tr == TRAX_FRAME) {
// Read image
image = cv::imread(img->data);
if(image.empty()){
break;
}
// Start trackers
for(unsigned int i = 0; i < trackers.size(); i++){
trackers[i]->newFrame(image, fusion.getPrediction());
trackers[i]->start();
}
// Wait and get results
uncertainty.clear();
trackersResults.clear();
for(unsigned int i = 0; i < trackers.size(); i++){
trackers[i]->wait();
uncertainty.insert(uncertainty.end(), trackers[i]->stateUncertainty.begin(), trackers[i]->stateUncertainty.end());
trackersResults.insert(trackersResults.end(), trackers[i]->state.begin(), trackers[i]->state.end());
}
// Correct the KF
fusion.correct(trackersResults, uncertainty);
// Model Update
for(unsigned int i = 0; i < trackers.size(); i++){
trackers[i]->start();
}
//Report result
cv::Rect output = fusion.getResult();
trax_region* region = trax_region_create_rectangle(output.x, output.y, output.width, output.height);
trax_server_reply(trax, region, NULL);
trax_region_release(®ion);
// Wait trackers update process
for(unsigned int i = 0; i < trackers.size(); i++){
trackers[i]->wait();
}
// Feedback
for(unsigned int i = 0; i < trackers.size(); i++){
trackers[i]->correctState(fusion.getFusion());
}
// Predict next frame state
fusion.predict();
} else {
run = 0;
}
trax_properties_release(&prop);
trax_metadata_release(&config);
/*cv::rectangle(image, fusion.getResult(), cv::Scalar(255, 0, 0));
cv::imshow("resp", image);
cv::waitKey(0);*/
}
return 0;
}