diff --git a/frigate/camera/state.py b/frigate/camera/state.py index 267c7d457..0684b2dc9 100644 --- a/frigate/camera/state.py +++ b/frigate/camera/state.py @@ -53,17 +53,6 @@ class CameraState: self.callbacks = defaultdict(list) self.ptz_autotracker_thread = ptz_autotracker_thread self.prev_enabled = self.camera_config.enabled - self.requires_face_detection = ( - self.config.face_recognition.enabled - and "face" not in self.config.objects.all_objects - ) - - def get_max_update_frequency(self, obj: TrackedObject) -> int: - return ( - 1 - if self.requires_face_detection and obj.obj_data["label"] == "person" - else 5 - ) def get_current_frame(self, draw_options: dict[str, Any] = {}): with self.current_frame_lock: @@ -298,14 +287,18 @@ class CameraState: updated_obj.last_updated = frame_time - # if it has been more than max_update_frequency seconds since the last thumb update + # if it has been more than 5 seconds since the last thumb update # and the last update is greater than the last publish or - # the object has changed significantly + # the object has changed significantly or + # we are due for an attribute update if ( - frame_time - updated_obj.last_published - > self.get_max_update_frequency(updated_obj) - and updated_obj.last_updated > updated_obj.last_published - ) or significant_update: + ( + frame_time - updated_obj.last_published > 5 + and updated_obj.last_updated > updated_obj.last_published + ) + or significant_update + or updated_obj.should_update_attribute() + ): # call event handlers for c in self.callbacks["update"]: c(self.name, updated_obj, frame_name) diff --git a/frigate/track/tracked_object.py b/frigate/track/tracked_object.py index 978671512..ee9883d37 100644 --- a/frigate/track/tracked_object.py +++ b/frigate/track/tracked_object.py @@ -1,5 +1,6 @@ """Object attribute.""" +import datetime import logging import math import os @@ -71,6 +72,14 @@ class TrackedObject: self.velocity_angle = 0 self.path_data = [] self.previous = self.to_dict() + self.requires_face_detection = ( + self.camera_config.face_recognition.enabled + and "face" not in self.camera_config.objects.track + ) + self.requires_lpr_detection = ( + self.camera_config.lpr.enabled + and "license_plate" not in self.camera_config.objects.track + ) @property def max_severity(self) -> Optional[str]: @@ -338,6 +347,22 @@ class TrackedObject: self.current_zones = current_zones return (thumb_update, significant_change, autotracker_update) + def should_update_attribute(self) -> bool: + """Decides if attributes should be checked.""" + if self.obj_data["label"] == "person" and not self.requires_face_detection: + return False + elif self.obj_data["label"] == "car" and not self.requires_lpr_detection: + return False + + now = datetime.datetime.now().timestamp() + + if now + 0.5 > self.last_published: + self.last_published = now + print(f"running manual attribute update") + return True + + return False + def to_dict(self): event = { "id": self.obj_data["id"],