Add multitracker and metrics
[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(int id) : id(id)
9 {
10     status = TrackerStatus::Fire;
11     preStatus = TrackerStatus::Fire;
12 }
13
14 Tracker::~Tracker()
15 {
16 }
17
18 void Tracker::addPatch(Patch* p)
19 {
20     patches.push_back(p);
21     if (patches.size() > Metrics::MaxPatch){
22         patches.erase(patches.end());
23     }
24 }
25
26 void Tracker::updateState(const Mat& image)
27 {
28     preStatus = this->status;
29     int lost_age = this->age - this->last_active;
30     int active_age = this->last_active;
31
32     if (lost_age >= MaxLost){
33         status = TrackerStatus::Delete;
34     } else if (lost_age >= 1 && active_age == 1){
35         status = TrackerStatus::Delete;
36     } else if (lost_age >= 1) {
37         status = TrackerStatus::Lost;
38     }
39 }