feat: Add minimum affinity filter to affinity result grouping
- Introduced a `min_affinity` parameter to the `affinity_result_by_tracking` function, allowing users to specify a threshold for filtering affinity results. - Updated the logic to skip results with affinities below the specified minimum, enhancing the relevance of grouped detections. - Improved function documentation to include details about the new parameter and its purpose.
This commit is contained in:
@ -1197,13 +1197,22 @@ display(affinities)
|
||||
# %%
|
||||
def affinity_result_by_tracking(
|
||||
results: Iterable[AffinityResult],
|
||||
min_affinity: float = 0.0,
|
||||
) -> dict[TrackingID, list[Detection]]:
|
||||
"""
|
||||
Group affinity results by target ID.
|
||||
|
||||
Args:
|
||||
results: the affinity results to group
|
||||
min_affinity: the minimum affinity to consider
|
||||
Returns:
|
||||
a dictionary mapping tracking IDs to a list of detections
|
||||
"""
|
||||
res: dict[TrackingID, list[Detection]] = defaultdict(list)
|
||||
for affinity_result in results:
|
||||
for _affinity, t, d in affinity_result.tracking_association():
|
||||
for affinity, t, d in affinity_result.tracking_association():
|
||||
if affinity < min_affinity:
|
||||
continue
|
||||
res[t.id].append(d)
|
||||
return res
|
||||
|
||||
|
||||
Reference in New Issue
Block a user