-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortTracker.cpp
More file actions
55 lines (47 loc) · 1.69 KB
/
SortTracker.cpp
File metadata and controls
55 lines (47 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "SortTracker.h"
namespace tracker
{
SortTracker::SortTracker(int max_age, int min_hits, float iou_threshold)
{
this->max_age = max_age;
this->min_hits = min_hits;
this->iou_threshold = iou_threshold;
this->tracks.clear();
this->frame_count = 0;
}
SortTracker::~SortTracker() {}
void SortTracker::update(std::vector<Detection>& dets)
{
this->frame_count++;
std::remove_if(this->tracks.begin(), this->tracks.end(), [](SortTrack& track){
Detection det = track.predict();
if (det.bbox.x1 < 0 || det.bbox.y1 < 0 || det.bbox.x2 || det.bbox.y2 < 0)
return true;
return false;
});
std::vector<std::pair<int, int>> matched;
std::vector<int> unmatched_dets;
std::vector<int> unmatched_tracks;
associate_detections_to_trackers(dets, this->tracks, this->iou_threshold, matched, unmatched_dets, unmatched_tracks);
// update matched trackers with assigned detections
for (int i = 0; i < matched.size(); i++) {
int track_idx = matched[i].first;
int det_idx = matched[i].second;
this->tracks[track_idx].update(dets[det_idx]);
dets[det_idx].trackid = this->tracks[track_idx].id;
}
// create and initialize new trackers fo unmatched detections
for (int i = 0; i < unmatched_dets.size(); i++) {
int det_idx = unmatched_dets[i];
SortTrack track(dets[det_idx]);
this->tracks.push_back(track);
dets[det_idx].trackid = track.id;
}
// remove all old tracks
std::remove_if(this->tracks.begin(), this->tracks.end(), [this](SortTrack& track){
if (track.time_since_update > this->max_age)
return true;
return false;
});
}
}