#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();
}
{
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);
#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
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]);
}
}
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);
+ }
}