-
Notifications
You must be signed in to change notification settings - Fork 14
/
kfebtracker.cpp
95 lines (83 loc) · 2.35 KB
/
kfebtracker.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
#include "kfebtracker.h"
KFebTracker::KFebTracker()
{
asms = tASMS(ajuste, 1.0f);
kcf = tKCF(ajuste, 1.15f);
cbt = tCBT(ajuste, 0.45f);
vdp = tVDP(ajuste, 0.60f);
ncc = tncc(ajuste, 0.7f);
}
/* Initiation Parameters
* A = ASMS
* K = KCF
* C = CBT
* V = VDP
* N = NCC
*
* (Send string "AKN" to initialize the tracker with ASMS, KCF and NCC)
*/
void KFebTracker::init(std::string initPar){
trackers.clear();
for(int i = 0; i < (int)initPar.length(); i++){
switch (initPar[i]) {
case 'A':
trackers.push_back(&asms);
break;
case 'K':
trackers.push_back(&kcf);
break;
case 'C':
trackers.push_back(&cbt);
break;
case 'V':
trackers.push_back(&vdp);
break;
case 'N':
trackers.push_back(&ncc);
break;
default:
break;
}
}
}
void KFebTracker::initTrackers(cv::Mat image, cv::Rect region){
// Inicialization
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);
}
cv::Rect KFebTracker::track(cv::Mat image){
// 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();
}
// 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();
//Report result
return fusion.getResult();
}