Skip to content

trackforge / utils / assignment


Module assignment

Greedy linear assignment shared by the trackers.

All four trackers resolve a cost matrix into matches the same way: enumerate every (row, column) cost, sort ascending, and greedily accept a pair when both its row and column are still free and the cost does not exceed the threshold.

Quick Reference

Item Kind Description
greedy_match fn Greedily match rows to columns of a cost matrix.
iou_match fn Greedily associate track boxes to detection boxes by IoU.

Functions

greedy_match

fn greedy_match(cost_matrix: &[Vec<f32>], threshold: f32) -> (Vec<(usize, usize)>, Vec<usize>, Vec<usize>)

Greedily match rows to columns of a cost matrix.

cost_matrix[r][c] is the cost of pairing row r with column c. Pairs are accepted in ascending cost order while both endpoints are unmatched and the cost is <= threshold.

Returns (matches, unmatched_rows, unmatched_cols) where each match is a (row, col) pair. The unmatched vectors are sorted ascending.

iou_match

fn iou_match(track_boxes: &[[f32; 4]], det_boxes: &[[f32; 4]], cost_threshold: f32) -> (Vec<(usize, usize)>, Vec<usize>, Vec<usize>)

Greedily associate track boxes to detection boxes by IoU.

Builds the 1 - IoU cost matrix between track_boxes and det_boxes and runs greedy_match on it. cost_threshold is the maximum acceptable 1 - IoU cost, so a pair is matched only when IoU >= 1 - cost_threshold.

Returns (matches, unmatched_tracks, unmatched_dets) where each match is a (track, detection) pair. When either side is empty no match is possible and the full index range of the non-empty side is returned as unmatched.