8e5caaf491ad7e2ccdf5f3bc883306ed3750ab49
[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: Kalman filter
14     this->kf.transitionMatrix = (Mat_<float>(4, 4) << 
15                                                 1, 0, 1, 0,
16                                                 0, 1, 0, 1,
17                                                 0, 0, 1, 0,
18                                                 0, 0, 0, 1);
19
20     this->kf.measurementMatrix = (Mat_<float>(2, 2) << 
21                                                 1, 0, 0, 0,
22                                                 0, 1, 0, 0);
23
24     this->kf.processNoiseCov = 1e-5 * Mat_<float>::eye(4, 4);
25     this->kf.measurementNoiseCov = 1e-1 * Mat_<float>::ones(2, 2);
26     this->kf.errorCovPost = 1. * Mat_<float>::ones(4, 4);
27 }
28
29 Tracker::~Tracker()
30 {
31     patches.clear();
32 }
33
34 void Tracker::updateState(const Mat& image)
35 {
36     preStatus = this->status;
37     int lost_age = this->age - this->last_active;
38     int active_age = this->last_active;
39
40     if (lost_age >= MaxLost){
41         status = TrackerStatus::Delete;
42     } else if (lost_age >= 1 && active_age == 1){
43         status = TrackerStatus::Delete;
44     } else if (lost_age >= 1) {
45         status = TrackerStatus::Lost;
46     }
47 }
48
49 void Tracker::addPatch(PatchPtr p)
50 {
51     this->patches.push_back(p);
52 }