Skip the BGR conversion when there are no detections

Hoisting the YUV to BGR conversion out of the detection loop made it run even
on frames with an empty detection list, where the previous per-detection code
converted nothing at all. match_and_update is called with an empty list
whenever detection is disabled, and whenever motion triggered detection but
the detector returned no trackable objects, so this is the common case on a
camera that is mostly idle.

A wasted full-frame conversion costs 0.69 ms / 2.8 MB at 1280x720 and
2.89 ms / 12.3 MB at 2688x1520 - 4x to 17x more than the contrast LUT saves
per frame - which would have made this change a net regression for
autotracking cameras.
This commit is contained in:
Mika 2026-08-13 23:13:56 +02:00
parent 231c648e87
commit d93f296691

View File

@ -526,9 +526,14 @@ class NorfairTracker(ObjectTracker):
# Convert the frame to BGR once per call for histogram embeddings rather
# than once per detection; every detection histograms a region of the
# same frame.
# same frame. Skipped when there are no detections, so a frame without
# objects costs no conversion at all.
bgr_frame: np.ndarray | None = None
if yuv_frame is not None and self.ptz_metrics.autotracker_enabled.value:
if (
detections
and yuv_frame is not None
and self.ptz_metrics.autotracker_enabled.value
):
bgr_frame = cv2.cvtColor(yuv_frame, cv2.COLOR_YUV2BGR_I420)
for obj in detections: