3 using namespace suanzi;
7 static const int MaxLost = 5;
9 Tracker::Tracker(const cv::Mat& image, const Detection& detection, int id) : id(id)
11 status = TrackerStatus::Fire;
12 preStatus = TrackerStatus::Fire;
14 // TODO: Kalman filter
15 this->kf.transitionMatrix = (Mat_<double>(4, 4) <<
21 this->kf.measurementMatrix = (Mat_<double>(2, 2) <<
25 this->kf.processNoiseCov = 1e-5 * Mat_<double>::eye(4, 4);
26 this->kf.measurementNoiseCov = 1e-1 * Mat_<double>::ones(2, 2);
27 this->kf.errorCovPost = 1. * Mat_<double>::ones(4, 4);
28 //this->kf.statePre = 0.1 * Matx_<int, 4, 1>::randn(4, 1);
30 randn(this->kf.statePre, Scalar::all(0), Scalar::all(0.1));
31 this->kf.statePost = (Mat_<double>(4, 1) << detection.center_x, detection.center_y, 0, 0);
39 void Tracker::updateState(const Mat& image)
41 preStatus = this->status;
42 int lost_age = this->age - this->last_active;
43 int active_age = this->last_active;
45 if (lost_age >= MaxLost){
46 status = TrackerStatus::Delete;
47 } else if (lost_age >= 1 && active_age == 1){
48 status = TrackerStatus::Delete;
49 } else if (lost_age >= 1) {
50 status = TrackerStatus::Lost;
54 void Tracker::addPatch(PatchPtr p)
56 this->patches.push_back(p);
59 void Tracker::correct(const cv::Mat& image, const Detection& detection)
63 status = TrackerStatus::Active;