diff --git a/algorithm/mot/sv_mot.cpp b/algorithm/mot/sv_mot.cpp index 609cc07..73701c3 100644 --- a/algorithm/mot/sv_mot.cpp +++ b/algorithm/mot/sv_mot.cpp @@ -195,6 +195,8 @@ void SORT::update(TargetsInFrame& tgts) tracklet.age = 0; tracklet.hits = 1; tracklet.misses = 0; + tracklet.frame_id=tgts.frame_id; + tracklet.tentative = true; // initate the motion pair, Matrix > motion = kf.initiate(tracklet.bbox); tracklet.mean = motion.first; @@ -243,12 +245,13 @@ void SORT::update(TargetsInFrame& tgts) int detectionIndex = match.second; if (trackletIndex >= 0 && detectionIndex >= 0) { - if (iouMatrix[match.first][match.second] >= 0) + if (iouMatrix[match.first][match.second] >= _iou_threshold)//iou_thrshold { sv::Box box; tgts.targets[detectionIndex].getBox(box); this->_tracklets[trackletIndex].age = 0; this->_tracklets[trackletIndex].hits++; + this->_tracklets[trackletIndex].frame_id=tgts.frame_id; this->_tracklets[trackletIndex].bbox << box.x1, box.y1, box.x2-box.x1, box.y2-box.y1; auto[mean, covariance] = kf.update(this->_tracklets[trackletIndex].mean, this->_tracklets[trackletIndex].covariance, box); @@ -274,6 +277,8 @@ void SORT::update(TargetsInFrame& tgts) tracklet.age = 0; tracklet.hits = 1; tracklet.misses = 0; + tracklet.frame_id=tgts.frame_id; + tracklet.tentative = true; auto[new_mean, new_covariance] = kf.initiate(tracklet.bbox); tracklet.mean = new_mean; @@ -284,6 +289,19 @@ void SORT::update(TargetsInFrame& tgts) this->_tracklets.push_back(tracklet); } } + for (auto& tracklet : this->_tracklets) + { + if (tracklet.hits >= _min_hits) + { + tracklet.tentative = false; + } + if ((tgts.frame_id-tracklet.frame_id <= _max_age) || (!tracklet.tentative && tracklet.frame_id==tgts.frame_id)) + { + _new_tracklets.push_back(tracklet); + } + } + _tracklets = _new_tracklets; + std::vector ().swap(_new_tracklets); } } diff --git a/include/sv_mot.h b/include/sv_mot.h index 105ab59..54964bf 100644 --- a/include/sv_mot.h +++ b/include/sv_mot.h @@ -55,6 +55,8 @@ public: int age; int hits; int misses; + int frame_id=0; + bool tentative; std::vector features; Eigen::Matrix mean; Eigen::Matrix covariance; @@ -93,6 +95,7 @@ private: int _min_hits; int _next_tracklet_id; std::vector _tracklets; + std::vector _new_tracklets; };