complete the metris functions
authorPeng Li <seudut@gmail.com>
Sun, 22 Jul 2018 11:20:06 +0000 (19:20 +0800)
committerPeng Li <seudut@gmail.com>
Sun, 22 Jul 2018 11:20:06 +0000 (19:20 +0800)
include/MultiTracker.h
src/Metrics.cpp [deleted file]
src/MultiTracker.cpp

index 66ea04e..07bd5db 100644 (file)
@@ -38,7 +38,6 @@ namespace suanzi {
     public:
         ~Patch(){};
         cv::Mat image_crop;
-        //std::vector<double> features;
         // hog is a hog descriptor of the image (calculated by hog.compute. size is 3780 )
         // hue is a histogram of the image, (calcHist(), is a Mat with (width x height) 64 x 45)
         std::pair<std::vector<double>, cv::Mat> features;
diff --git a/src/Metrics.cpp b/src/Metrics.cpp
deleted file mode 100644 (file)
index 4ff14ea..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "Logger.h"
-#include "Metrics.h"
-
-using namespace suanzi;
-using namespace cv;
-
-Metrics::Metrics(const std::string& clf_path)
-{
-    if (clf_path.empty()){
-
-    } else {
-
-    }
-}
index 0b4dab5..c87395e 100644 (file)
@@ -31,10 +31,23 @@ 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)
 {
-    // TODO
-    return 0.1;
+    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)
@@ -66,8 +79,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);
 
-    double iou_ratio = calc_iou_ratio(d1, d2);
-    feature.push_back(iou_ratio);
+    feature.push_back(calc_iou_ratio(d1, d2));
 
     return feature;
 }
@@ -141,12 +153,9 @@ void MultiTracker::update(unsigned int total, const Detection* detections, const
     PatchPtr pp = createPatch(image, dd);
 }
 
-// Get image crop from input image within given bounding box - Detecinon
 static cv::Mat image_crop(const cv::Mat& image, const Detection& bb)
 {
-    // RECT
-    // TODO;
-    return image.clone();
+    return image(getRectInDetection(bb));
 }
 
 PatchPtr MultiTracker::createPatch(const Mat& image, const Detection& detect)