From 039148397bc00d325e4b0a4784b3eb8665a83e35 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Sat, 12 Apr 2025 16:11:10 -0500 Subject: [PATCH] Save initial frame of new objects to frame cache Objects that move quickly through the frame and are only seen briefly may not have the update() method called to save thumbnail_data, and may not have the initial frame saved to the tracked object frame cache. This caused a "Frame missing from frame cache" message that was patched by #7313 but this sometimes caused the wrong frame to be chosen for the thumb/snapshot. --- frigate/camera/state.py | 21 +++++++++++++++++++++ frigate/track/tracked_object.py | 8 +++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/frigate/camera/state.py b/frigate/camera/state.py index fee6e4e233..c307bea1e5 100644 --- a/frigate/camera/state.py +++ b/frigate/camera/state.py @@ -263,6 +263,27 @@ class CameraState: current_detections[id], ) + # add initial frame to frame cache + self.frame_cache[frame_time] = np.copy(current_frame) + + # save initial thumbnail data and best object + thumbnail_data = { + "frame_time": frame_time, + "box": new_obj.obj_data["box"], + "area": new_obj.obj_data["area"], + "region": new_obj.obj_data["region"], + "score": new_obj.obj_data["score"], + "attributes": new_obj.obj_data["attributes"], + "current_estimated_speed": 0, + "velocity_angle": 0, + "path_data": [], + "recognized_license_plate": None, + "recognized_license_plate_score": None, + } + new_obj.thumbnail_data = thumbnail_data + tracked_objects[id].thumbnail_data = thumbnail_data + self.best_objects[new_obj.obj_data["label"]] = new_obj + # call event handlers for c in self.callbacks["start"]: c(self.name, new_obj, frame_name) diff --git a/frigate/track/tracked_object.py b/frigate/track/tracked_object.py index b7c3af287f..58a4e0b83b 100644 --- a/frigate/track/tracked_object.py +++ b/frigate/track/tracked_object.py @@ -144,8 +144,14 @@ class TrackedObject: obj_data, self.camera_config.frame_shape, ): + # use the current frame time if the object's frame time isn't in the frame cache + selected_frame_time = ( + current_frame_time + if obj_data["frame_time"] not in self.frame_cache.keys() + else obj_data["frame_time"] + ) self.thumbnail_data = { - "frame_time": current_frame_time, + "frame_time": selected_frame_time, "box": obj_data["box"], "area": obj_data["area"], "region": obj_data["region"],