|
|
|
|
|
|
|
|
from .utils import iou |
|
|
|
|
|
|
|
|
def track_iou(detections, sigma_l, sigma_h, sigma_iou, t_min): |
|
|
""" |
|
|
Simple IOU based tracker. |
|
|
See "High-Speed Tracking-by-Detection Without Using Image Information by E. Bochinski, V. Eiselein, T. Sikora" for |
|
|
more information. |
|
|
|
|
|
Args: |
|
|
detections (list): list of detections per frame, usually generated by util.load_mot |
|
|
sigma_l (float): low detection threshold. |
|
|
sigma_h (float): high detection threshold. |
|
|
sigma_iou (float): IOU threshold. |
|
|
t_min (float): minimum track length in frames. |
|
|
|
|
|
Returns: |
|
|
list: list of tracks. |
|
|
""" |
|
|
|
|
|
tracks_active = [] |
|
|
tracks_finished = [] |
|
|
|
|
|
for frame_num, detections_frame in enumerate(detections, start=1): |
|
|
|
|
|
dets = [det for det in detections_frame if det['score'] >= sigma_l] |
|
|
|
|
|
updated_tracks = [] |
|
|
for track in tracks_active: |
|
|
if len(dets) > 0: |
|
|
|
|
|
best_match = max(dets, key=lambda x: iou(track['bboxes'][-1], x['bbox'])) |
|
|
if iou(track['bboxes'][-1], best_match['bbox']) >= sigma_iou: |
|
|
track['bboxes'].append(best_match['bbox']) |
|
|
track['max_score'] = max(track['max_score'], best_match['score']) |
|
|
|
|
|
updated_tracks.append(track) |
|
|
|
|
|
|
|
|
del dets[dets.index(best_match)] |
|
|
|
|
|
|
|
|
if len(updated_tracks) == 0 or track is not updated_tracks[-1]: |
|
|
|
|
|
if track['max_score'] >= sigma_h and len(track['bboxes']) >= t_min: |
|
|
tracks_finished.append(track) |
|
|
|
|
|
|
|
|
new_tracks = [{'bboxes': [det['bbox']], 'max_score': det['score'], 'start_frame': frame_num} for det in dets] |
|
|
tracks_active = updated_tracks + new_tracks |
|
|
|
|
|
|
|
|
tracks_finished += [track for track in tracks_active |
|
|
if track['max_score'] >= sigma_h and len(track['bboxes']) >= t_min] |
|
|
|
|
|
return tracks_finished |
|
|
|