Simplify check

This commit is contained in:
Nicolas Mowen 2025-04-09 19:37:24 -06:00
parent f2361cb81e
commit 6279e8fa3a
2 changed files with 10 additions and 24 deletions

View File

@ -269,8 +269,10 @@ class CameraState:
for id in updated_ids: for id in updated_ids:
updated_obj = tracked_objects[id] updated_obj = tracked_objects[id]
thumb_update, significant_update, autotracker_update = updated_obj.update( thumb_update, significant_update, path_update, autotracker_update = (
frame_time, current_detections[id], current_frame is not None updated_obj.update(
frame_time, current_detections[id], current_frame is not None
)
) )
if autotracker_update or significant_update: if autotracker_update or significant_update:
@ -290,14 +292,14 @@ class CameraState:
# if it has been more than 5 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 # and the last update is greater than the last publish or
# the object has changed significantly or # the object has changed significantly or
# we are due for an attribute update # the object moved enough to update the path
if ( if (
( (
frame_time - updated_obj.last_published > 5 frame_time - updated_obj.last_published > 5
and updated_obj.last_updated > updated_obj.last_published and updated_obj.last_updated > updated_obj.last_published
) )
or significant_update or significant_update
or updated_obj.should_update_attribute() or path_update
): ):
# call event handlers # call event handlers
for c in self.callbacks["update"]: for c in self.callbacks["update"]:

View File

@ -1,6 +1,5 @@
"""Object attribute.""" """Object attribute."""
import datetime
import logging import logging
import math import math
import os import os
@ -126,6 +125,7 @@ class TrackedObject:
def update(self, current_frame_time: float, obj_data, has_valid_frame: bool): def update(self, current_frame_time: float, obj_data, has_valid_frame: bool):
thumb_update = False thumb_update = False
significant_change = False significant_change = False
path_update = False
autotracker_update = False autotracker_update = False
# if the object is not in the current frame, add a 0.0 to the score history # if the object is not in the current frame, add a 0.0 to the score history
if obj_data["frame_time"] != current_frame_time: if obj_data["frame_time"] != current_frame_time:
@ -333,37 +333,21 @@ class TrackedObject:
if not self.path_data: if not self.path_data:
self.path_data.append((bottom_center, obj_data["frame_time"])) self.path_data.append((bottom_center, obj_data["frame_time"]))
path_update = True
elif ( elif (
math.dist(self.path_data[-1][0], bottom_center) >= threshold math.dist(self.path_data[-1][0], bottom_center) >= threshold
or len(self.path_data) == 1 or len(self.path_data) == 1
): ):
# check Euclidean distance before appending # check Euclidean distance before appending
self.path_data.append((bottom_center, obj_data["frame_time"])) self.path_data.append((bottom_center, obj_data["frame_time"]))
path_update = True
logger.debug( logger.debug(
f"Point tracking: {obj_data['id']}, {bottom_center}, {obj_data['frame_time']}" f"Point tracking: {obj_data['id']}, {bottom_center}, {obj_data['frame_time']}"
) )
self.obj_data.update(obj_data) self.obj_data.update(obj_data)
self.current_zones = current_zones self.current_zones = current_zones
return (thumb_update, significant_change, autotracker_update) return (thumb_update, significant_change, path_update, autotracker_update)
def should_update_attribute(self) -> bool:
"""Decides if attributes should be checked."""
if not self.active:
return False
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
return True
return False
def to_dict(self): def to_dict(self):
event = { event = {