From d93f296691bba288e4e671c6c4cf13244d94d8d0 Mon Sep 17 00:00:00 2001 From: Mika <19797875+it-rec@users.noreply.github.com> Date: Thu, 13 Aug 2026 23:13:56 +0200 Subject: [PATCH] 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. --- frigate/track/norfair_tracker.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frigate/track/norfair_tracker.py b/frigate/track/norfair_tracker.py index 6158076751..986f056ada 100644 --- a/frigate/track/norfair_tracker.py +++ b/frigate/track/norfair_tracker.py @@ -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: