X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=src%2FMultiTracker.cpp;h=c87395ef3415c1da78da878eaa40aa2b9fcc568d;hb=b5f0328f4054d19fcf8a6b870d5448be8087d29c;hp=b1f380eb73e8b7f769014bfad62c96e06075dd20;hpb=209cfd9fe0ea398b794d1d1995629a826125f035;p=trackerpp.git diff --git a/src/MultiTracker.cpp b/src/MultiTracker.cpp index b1f380e..c87395e 100644 --- a/src/MultiTracker.cpp +++ b/src/MultiTracker.cpp @@ -13,7 +13,8 @@ static const cv::Size PREFERRED_SIZE = Size(64, 128); #define MaxCost 100000 -MultiTracker::MultiTracker() +MultiTracker::MultiTracker(EngineWPtr e) +: engine(e) { LOG_DEBUG(TAG, "init - loading model.pkl"); predictor = PredictorWrapper::create("./python/model.pkl"); @@ -30,6 +31,24 @@ 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) { @@ -60,9 +79,7 @@ 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); - //TODO - double iou_ratio = 0.03; - feature.push_back(iou_ratio); + feature.push_back(calc_iou_ratio(d1, d2)); return feature; } @@ -82,32 +99,41 @@ double MultiTracker::distance(TrackerPtr tracker, const cv::Mat& image, const De return prob; } +static long cc = 0; + 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++){ - // TODO - cost_matrix(i, j) = distance(trackers[i], image, detections[j]); + //if (calc_iou_ratio(trackers[i], detections[j]) < -0.1) + // cost_matrix(i, j) = MaxCost; + //else + cost_matrix(i, j) = distance(trackers[i], image, detections[j]); } } - // assignment Eigen::VectorXi tracker_inds, bb_inds; linear_sum_assignment(cost_matrix, tracker_inds, bb_inds); // handle unmatched trackers - vector unmatched_trackers; + //vector unmatched_trackers; for (int i = 0; i < row; i++){ if (!(tracker_inds.array() == i).any()){ - unmatched_trackers.push_back(trackers[i]); + trackers[i]->updateState(image); } } - for (auto t : unmatched_trackers){ - t->updateState(image); - } // handle unmatched detections vector unmatched_detection; @@ -127,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) @@ -155,7 +178,6 @@ PatchPtr MultiTracker::createPatch(const Mat& image, const Detection& detect) float sranges[] = {0, 256}; const float* ranges[] = {hranges, sranges}; calcHist(&hsv, 1, channels, Mat(), hist, 2, histSize, ranges, true, false); - Size sm = hist.size(); patch->image_crop = im.clone(); patch->detection = detect;