Fix issue boostpython not stopped by Ctrl+c
[trackerpp.git] / src / Tracker.cpp
1 #include "Tracker.h"
2
3 using namespace suanzi;
4 using namespace cv;
5
6 static const int MaxLost = 5;
7
8 Tracker::Tracker(const cv::Mat& image,int id) : id(id)
9 {
10     status = TrackerStatus::Fire;
11     preStatus = TrackerStatus::Fire;
12
13     // TODO
14     // init KalmanFilter
15     this->kf.transitionMatrix = (Mat_<float>(4, 4) << 
16                                                 1, 0, 1, 0,
17                                                 0, 1, 0, 1,
18                                                 0, 0, 1, 0,
19                                                 0, 0, 0, 1);
20
21     this->kf.measurementMatrix = (Mat_<float>(2, 2) << 
22                                                 1, 0, 0, 0,
23                                                 0, 1, 0, 0);
24
25     this->kf.processNoiseCov = 1e-5 * Mat_<float>::eye(4, 4);
26     this->kf.measurementNoiseCov = 1e-1 * Mat_<float>::ones(2, 2);
27     this->kf.errorCovPost = 1. * Mat_<float>::ones(4, 4);
28 }
29
30 Tracker::~Tracker()
31 {
32 }
33
34 //void Tracker::addPatch(Patch* p)
35 //{
36 //    patches.push_back(p);
37 //    if (patches.size() > Metrics::MaxPatch){
38 //        patches.erase(patches.end());
39 //    }
40 //}
41 //
42 void Tracker::updateState(const Mat& image)
43 {
44     preStatus = this->status;
45     int lost_age = this->age - this->last_active;
46     int active_age = this->last_active;
47
48     if (lost_age >= MaxLost){
49         status = TrackerStatus::Delete;
50     } else if (lost_age >= 1 && active_age == 1){
51         status = TrackerStatus::Delete;
52     } else if (lost_age >= 1) {
53         status = TrackerStatus::Lost;
54     }
55 }