guard norfair distance against non-finite and zero-area boxes that could crash autotracking cameras (#23475)

This commit is contained in:
Josh Hawkins
2026-06-13 16:23:30 -05:00
committed by GitHub
parent d7ad3ba699
commit 8be7a97fa6
3 changed files with 131 additions and 0 deletions
+11
View File
@@ -45,6 +45,17 @@ def distance(detection: np.ndarray, estimate: np.ndarray) -> float:
estimate_dim = np.diff(estimate, axis=0).flatten()
detection_dim = np.diff(detection, axis=0).flatten()
# Guard against degenerate or non-finite boxes
if (
not np.all(np.isfinite(estimate_dim))
or not np.all(np.isfinite(detection_dim))
or estimate_dim[0] <= 0
or estimate_dim[1] <= 0
or detection_dim[0] <= 0
or detection_dim[1] <= 0
):
return float("inf")
# get bottom center positions
detection_position = np.array(
[np.average(detection[:, 0]), np.max(detection[:, 1])]