Files
supervision/tests/tracker/test_byte_tracker.py
T
0a95bae8a8 chore: bump minimum Python to 3.10 (#2260)
- Drop Python 3.9 from CI test matrix
- requires-python = ">=3.10" in pyproject.toml
- ruff target-version py39 → py310
- mypy python_version 3.9 → 3.10
- Remove Python 3.9 classifier

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-06-29 14:45:30 +02:00

64 lines
2.2 KiB
Python

import numpy as np
import pytest
import supervision as sv
@pytest.mark.parametrize(
("detections", "expected_results"),
[
(
[
sv.Detections(
xyxy=np.array([[10, 10, 20, 20], [30, 30, 40, 40]]),
class_id=np.array([1, 1]),
confidence=np.array([1, 1]),
),
sv.Detections(
xyxy=np.array([[10, 10, 20, 20], [30, 30, 40, 40]]),
class_id=np.array([1, 1]),
confidence=np.array([1, 1]),
),
],
sv.Detections(
xyxy=np.array([[10, 10, 20, 20], [30, 30, 40, 40]]),
class_id=np.array([1, 1]),
confidence=np.array([1, 1]),
tracker_id=np.array([1, 2]),
),
),
],
)
def test_byte_tracker(
detections: list[sv.Detections],
expected_results: sv.Detections,
) -> None:
byte_tracker = sv.ByteTrack()
tracked_detections = [byte_tracker.update_with_detections(d) for d in detections]
assert tracked_detections[-1] == expected_results
def test_byte_tracker_does_not_skip_external_ids_for_short_lived_tracks() -> None:
def detections_from_boxes(boxes: list[list[float]]) -> sv.Detections:
return sv.Detections(
xyxy=np.array(boxes, dtype=np.float32),
class_id=np.zeros(len(boxes), dtype=int),
confidence=np.ones(len(boxes), dtype=np.float32),
)
# A transient false-positive appears and disappears before becoming confirmed.
# It should not consume an external tracker id.
frames = [
detections_from_boxes([[0, 0, 10, 10]]),
detections_from_boxes([[0, 0, 10, 10], [100, 100, 110, 110]]),
detections_from_boxes([[0, 0, 10, 10]]),
detections_from_boxes([[0, 0, 10, 10], [200, 200, 210, 210]]),
detections_from_boxes([[0, 0, 10, 10], [200, 200, 210, 210]]),
]
byte_tracker = sv.ByteTrack(minimum_consecutive_frames=1)
tracked = [byte_tracker.update_with_detections(frame) for frame in frames]
assert tracked[-1].tracker_id is not None
assert np.array_equal(np.sort(tracked[-1].tracker_id), np.array([1, 2]))