add utils.cpp and testcase
[trackerpp.git] / src / MultiTracker.cpp
index c87395e..f3a7cad 100644 (file)
@@ -3,6 +3,7 @@
 #include <algorithm>
 #include "hungarian.h"
 #include "Logger.h"
+#include "Utils.h"
 
 using namespace suanzi;
 using namespace cv;
@@ -31,25 +32,6 @@ MultiTracker::~MultiTracker()
     trackers.clear();
 }
 
-static Rect getRectInDetection(const Detection& d)
-{
-    Rect r;
-    r.x = d.center_x - d.width / 2;
-    r.y = d.center_y - d.height / 2;
-    r.width = d.width;
-    r.height = d.height;
-    return r;
-}
-
-static double calc_iou_ratio(const Detection& d1, const Detection& d2)
-{
-    Rect r1 = getRectInDetection (d1);
-    Rect r2 = getRectInDetection (d2);
-    Rect r_inner = r1 & r1;
-    Rect r_union  = r1 | r2;
-    return 1.0 * r_inner.area() / r_union.area();
-}
-
 static std::vector<double> similarity(const PatchPtr p1, const PatchPtr p2)
 {
     std::vector<double> feature;
@@ -79,7 +61,7 @@ static std::vector<double> similarity(const PatchPtr p1, const PatchPtr p2)
     double center_distance = sqrt(pow((d1.center_x - d2.center_x), 2) + pow((d1.center_y - d2.center_y), 2));
     feature.push_back(center_distance / (d1.width + d1.height + d2.width + d2.height) * 4);
 
-    feature.push_back(calc_iou_ratio(d1, d2));
+    feature.push_back(calc_iou_ratio(getRectInDetection(d1), getRectInDetection(d2)));
 
     return feature;
 }