|
7 | 7 |
|
8 | 8 | from time import time |
9 | 9 |
|
10 | | -from util import load_mot, save_to_csv, iou |
| 10 | +from util import load_mot, iou |
11 | 11 |
|
12 | 12 |
|
13 | 13 | 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): |
36 | 36 |
|
37 | 37 | updated_tracks = [] |
38 | 38 | 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']) |
42 | 45 |
|
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) |
48 | 47 |
|
49 | | - updated_tracks.append(track) |
| 48 | + # remove from best matching detection from detections |
| 49 | + del dets[dets.index(best_match)] |
50 | 50 |
|
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 |
56 | 54 | if track['max_score'] >= sigma_h and len(track['bboxes']) >= t_min: |
57 | 55 | tracks_finished.append(track) |
58 | 56 |
|
|
0 commit comments