Fix issue boostpython not stopped by Ctrl+c
[trackerpp.git] / src / MultiTracker.cpp
index d0e7048..01e60c5 100644 (file)
@@ -2,13 +2,18 @@
 #include "Metrics.h"
 #include <algorithm>
 #include "hungarian.h"
+#include "Logger.h"
 
 using namespace suanzi;
 using namespace cv;
 using namespace Eigen;
 
+static const std::string TAG = "MultiTracker";
 MultiTracker::MultiTracker(MetricsPtr m) : metrics(m)
 {
+    LOG_DEBUG(TAG, "init - load model.pkl");
+    predictor = PredictorWrapper::create("./python/model.pkl");
+    predictor->dump();
 }
 
 
@@ -16,19 +21,19 @@ MultiTracker::~MultiTracker()
 {
     trackers.clear();
 }
-
-TrackerPtr MultiTracker::createTracker(int id)
-{
-    TrackerPtr t (new Tracker(id));
-    addTracker(t);
-    return t;
-}
-
-void MultiTracker::addTracker(TrackerPtr t)
-{
-    trackers.push_back(t);
-}
-
+//
+//TrackerPtr MultiTracker::createTracker(int id)
+//{
+//    TrackerPtr t (new Tracker(id));
+//    addTracker(t);
+//    return t;
+//}
+//
+//void MultiTracker::addTracker(TrackerPtr t)
+//{
+//    trackers.push_back(t);
+//}
+//
 void MultiTracker::removeTracker(TrackerPtr t)
 {
 //    trackers.erase(t);
@@ -49,6 +54,11 @@ void calculate_edistance()
 
 #define MaxCost  100000
 
+static double distance(TrackerPtr t, const cv::Mat& image, const Detection& d)
+{
+    return 0.1;
+}
+
 void MultiTracker::update(unsigned int total, const Detection* detections, const Mat& image)
 {
     // correct_trackers
@@ -58,13 +68,9 @@ void MultiTracker::update(unsigned int total, const Detection* detections, const
     MatrixXi cost_matrix = MatrixXi::Zero(row, col);
     for (int i = 0; i < row; i++){
         for (int j = 0; j < col; j++){
-            TrackerPtr tracker = trackers[i];
-            Detection det = detections[j];
-
-            int cost = MaxCost;
-
             // TODO
-            cost_matrix(i, j) = cost;
+            // int cost = MaxCost;
+            cost_matrix(i, j) = distance(trackers[i], image, detections[j]);
         }
     }
 
@@ -72,20 +78,28 @@ void MultiTracker::update(unsigned int total, const Detection* detections, const
     VectorXi tracker_inds, bb_inds;
     linear_sum_assignment(cost_matrix, tracker_inds, bb_inds);
 
-    // handle the result
+    // handle unmatched trackers
     vector<TrackerPtr> unmatched_trackers;
-    vector<Detection> unmatched_detection;
     for (int i = 0; i < row; i++){
         if (!(tracker_inds.array() == i).any()){
             unmatched_trackers.push_back(trackers[i]);
         }
     }
+    for (auto t : unmatched_trackers){
+        t->updateState(image);
+    }
+
+
+    // handle unmatched detections
+    vector<int> unmatched_detection;
     for(int j = 0; j < col; j++){
         if (!(bb_inds.array() == j).any()){
-            unmatched_detection.push_back(detections[j]);
+            unmatched_detection.push_back(j);
         }
     }
-
-
     // create new trackers for new detections
+    for (auto i : unmatched_detection){
+        TrackerPtr t (new Tracker(image));
+        this->trackers.push_back(t);
+    }
 }