X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=src%2FMultiTracker.cpp;h=a7f5e596a490bb16eb0215c34c43b2d22d3699f8;hb=db369d962b595544373b417ae9a76e7268eb12fb;hp=c87395ef3415c1da78da878eaa40aa2b9fcc568d;hpb=b5f0328f4054d19fcf8a6b870d5448be8087d29c;p=trackerpp.git diff --git a/src/MultiTracker.cpp b/src/MultiTracker.cpp index c87395e..a7f5e59 100644 --- a/src/MultiTracker.cpp +++ b/src/MultiTracker.cpp @@ -3,6 +3,7 @@ #include #include "hungarian.h" #include "Logger.h" +#include "Utils.h" using namespace suanzi; using namespace cv; @@ -11,18 +12,16 @@ using namespace std; static const std::string TAG = "MultiTracker"; static const cv::Size PREFERRED_SIZE = Size(64, 128); -#define MaxCost 100000 +static const double MaxCost = 100000; +static const int MaxPath = 5; MultiTracker::MultiTracker(EngineWPtr e) : engine(e) { LOG_DEBUG(TAG, "init - loading model.pkl"); - predictor = PredictorWrapper::create("./python/model.pkl"); + predictor = PredictorWrapper::create("./python", "./python/model.pkl"); predictor->dump(); this->descriptor = {Size(64, 128), Size(16, 16), Size(8, 8), Size(8, 8), 9}; - - std::vector ff (40, 1); - double prob = predictor->predict(4, ff); } MultiTracker::~MultiTracker() @@ -31,25 +30,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 similarity(const PatchPtr p1, const PatchPtr p2) { std::vector feature; @@ -79,12 +59,11 @@ static std::vector 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; } - double MultiTracker::distance(TrackerPtr tracker, const cv::Mat& image, const Detection& d) { PatchPtr patch = createPatch(image, d); @@ -99,27 +78,21 @@ double MultiTracker::distance(TrackerPtr tracker, const cv::Mat& image, const De return prob; } -static long cc = 0; +static float calc_iou_ratio(const Detection& d1, const Detection& d2) +{ + return calc_iou_ratio(getRectInDetection(d1), getRectInDetection(d2)); +} void MultiTracker::update(unsigned int total, const Detection* detections, const Mat& image) { - ////// - if ((cc % 50) == 0){ - if (EnginePtr e = engine.lock()){ - e->onStatusChanged(); - } - } - cc++; - - ////// int row = trackers.size(); int col = total; Eigen::MatrixXi cost_matrix = Eigen::MatrixXi::Zero(row, col); for (int i = 0; i < row; i++){ for (int j = 0; j < col; j++){ - //if (calc_iou_ratio(trackers[i], detections[j]) < -0.1) - // cost_matrix(i, j) = MaxCost; - //else + if (calc_iou_ratio(trackers[i]->detection, detections[j]) < -0.1) + cost_matrix(i, j) = MaxCost; + else cost_matrix(i, j) = distance(trackers[i], image, detections[j]); } }