Add multitracker and metrics
[trackerpp.git] / src / Tracker.cpp
index 79fd941..2d353a7 100644 (file)
@@ -1,11 +1,39 @@
 #include "Tracker.h"
 
 using namespace suanzi;
+using namespace cv;
 
-Tracker::Tracker()
+static const int MaxLost = 5;
+
+Tracker::Tracker(int id) : id(id)
 {
+    status = TrackerStatus::Fire;
+    preStatus = TrackerStatus::Fire;
 }
 
 Tracker::~Tracker()
 {
 }
+
+void Tracker::addPatch(Patch* p)
+{
+    patches.push_back(p);
+    if (patches.size() > Metrics::MaxPatch){
+        patches.erase(patches.end());
+    }
+}
+
+void Tracker::updateState(const Mat& image)
+{
+    preStatus = this->status;
+    int lost_age = this->age - this->last_active;
+    int active_age = this->last_active;
+
+    if (lost_age >= MaxLost){
+        status = TrackerStatus::Delete;
+    } else if (lost_age >= 1 && active_age == 1){
+        status = TrackerStatus::Delete;
+    } else if (lost_age >= 1) {
+        status = TrackerStatus::Lost;
+    }
+}