Skip to content

Commit 53bf44c

Browse files
author
bochinski
committed
small improvement
1 parent 4ada0c0 commit 53bf44c

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

iou_tracker.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from time import time
99

10-
from util import load_mot, save_to_csv, iou
10+
from util import load_mot, iou
1111

1212

1313
def track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min):
@@ -36,23 +36,21 @@ def track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min):
3636

3737
updated_tracks = []
3838
for track in tracks_active:
39-
# matches = [det for det in dets if track.get_iou(det['bbox']) >= min_iou]
40-
# high_matches = [match for match in matches if match['score'] >= thresh_high]
41-
high_matches = [det for det in dets if iou(track['bboxes'][-1], det['bbox']) >= sigma_iou]
39+
if len(dets) > 0:
40+
# get det with highest iou
41+
best_match = max(dets, key=lambda x: iou(track['bboxes'][-1], x['bbox']))
42+
if iou(track['bboxes'][-1], best_match['bbox']) >= sigma_iou:
43+
track['bboxes'].append(best_match['bbox'])
44+
track['max_score'] = max(track['max_score'], best_match['score'])
4245

43-
if len(high_matches) > 0:
44-
# extract best matching detection
45-
best_match = max(high_matches, key=lambda x: iou(track['bboxes'][-1], x['bbox']))
46-
track['bboxes'].append(best_match['bbox'])
47-
track['max_score'] = max(track['max_score'], best_match['score'])
46+
updated_tracks.append(track)
4847

49-
updated_tracks.append(track)
48+
# remove from best matching detection from detections
49+
del dets[dets.index(best_match)]
5050

51-
# remove from detections
52-
del dets[dets.index(best_match)]
53-
54-
else:
55-
# finish track when there is no suitable match
51+
# if track was not updated
52+
if len(updated_tracks) == 0 or track is not updated_tracks[-1]:
53+
# finish track when the conditions are met
5654
if track['max_score'] >= sigma_h and len(track['bboxes']) >= t_min:
5755
tracks_finished.append(track)
5856

0 commit comments

Comments
 (0)