36 cv::Rect_<float> bb_test,
37 cv::Rect_<float> bb_gt)
39 float bb_test_centroid_x = (bb_test.x + bb_test.width / 2);
40 float bb_test_centroid_y = (bb_test.y + bb_test.height / 2);
42 float bb_gt_centroid_x = (bb_gt.x + bb_gt.width / 2);
43 float bb_gt_centroid_y = (bb_gt.y + bb_gt.height / 2);
45 double distance = (double)sqrt(pow(bb_gt_centroid_x - bb_test_centroid_x, 2) + pow(bb_gt_centroid_y - bb_test_centroid_y, 2));
51void apply_nms(vector<TrackingBox>& detections,
double nms_iou_thresh) {
52 if (detections.empty())
return;
56 return a.confidence > b.confidence;
59 vector<bool> suppressed(detections.size(),
false);
61 for (
size_t i = 0; i < detections.size(); ++i) {
62 if (suppressed[i])
continue;
64 for (
size_t j = i + 1; j < detections.size(); ++j) {
65 if (suppressed[j])
continue;
67 if (detections[i].classId == detections[j].classId &&
75 vector<TrackingBox> filtered;
76 for (
size_t i = 0; i < detections.size(); ++i) {
78 filtered.push_back(detections[i]);
81 detections = filtered;
84void SortTracker::update(vector<cv::Rect> detections_cv,
int frame_count,
double image_diagonal, std::vector<float> confidences, std::vector<int> classIds)
86 vector<TrackingBox> detections;
91 for (
unsigned int i = 0; i < detections_cv.size(); i++)
97 tb.
box = cv::Rect_<float>(detections_cv[i]);
100 detections.push_back(tb);
109 for (
unsigned int i = 0; i < detections_cv.size(); i++)
111 if (confidences[i] <
_min_conf)
continue;
114 tb.
box = cv::Rect_<float>(detections_cv[i]);
117 detections.push_back(tb);
125 int frame_age = frame_count - it->frame;
126 if (frame_age >=
_max_age || frame_age < 0)
136 for (
unsigned int i = 0; i <
trackers.size();)
138 cv::Rect_<float> pBox =
trackers[i].predict();
139 if (pBox.x >= 0 && pBox.y >= 0)
149 detNum = detections.size();
154 for (
unsigned int i = 0; i <
trkNum; i++)
156 for (
unsigned int j = 0; j <
detNum; j++)
166 cost_matrix[i][j] = 1 - iou + (1 - detections[j].confidence) * 0.1;
182 for (
unsigned int n = 0; n <
detNum; n++)
185 for (
unsigned int i = 0; i <
trkNum; ++i)
194 for (
unsigned int i = 0; i <
trkNum; ++i)
203 for (
unsigned int i = 0; i <
trkNum; ++i)
220 trackers[trkIdx].update(detections[detIdx].box);
221 trackers[trkIdx].classId = detections[detIdx].classId;
222 trackers[trkIdx].confidence = detections[detIdx].confidence;
234 for (
unsigned int i = 0; i <
trackers.size();)
247 for (
unsigned int i = 0; i <
trackers.size();)
256 res.
frame = frame_count;
SortTracker(int max_age=50, int min_hits=5, int max_missed=7, double min_iou=0.1, double nms_iou_thresh=0.5, double min_conf=0.3)
void update(std::vector< cv::Rect > detection, int frame_count, double image_diagonal, std::vector< float > confidences, std::vector< int > classIds)