From 7ded3e2dff14c986688b121a4de29fd8222c471f Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Sun, 6 Mar 2022 13:11:17 -0700 Subject: [PATCH] Fix overwriting of objects --- frigate/object_processing.py | 59 +++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/frigate/object_processing.py b/frigate/object_processing.py index c5b27c632..896c04b2e 100644 --- a/frigate/object_processing.py +++ b/frigate/object_processing.py @@ -555,20 +555,22 @@ class CameraState: ) # keep track of all labels detected for this camera - all_labels_count = 0 + total_label_count = 0 # report on detected objects for obj_name, count in obj_counter.items(): - all_labels_count += count - + total_label_count += count + if count != self.object_counts[obj_name]: self.object_counts[obj_name] = count for c in self.callbacks["object_status"]: c(self.name, obj_name, count) - + # publish for all labels detected for this camera - for c in self.callbacks["object_status"]: - c(self.name, "all", all_labels_count) + if total_label_count != self.object_counts.get("all"): + self.object_counts["all"] = total_label_count + for c in self.callbacks["object_status"]: + c(self.name, "all", total_label_count) # expire any objects that are >0 and no longer detected expired_objects = [ @@ -577,6 +579,10 @@ class CameraState: if count > 0 and obj_name not in obj_counter ] for obj_name in expired_objects: + # Ignore the artificial all label + if obj_name is "all": + continue + self.object_counts[obj_name] = 0 for c in self.callbacks["object_status"]: c(self.name, obj_name, 0) @@ -898,12 +904,16 @@ class TrackedObjectProcessor(threading.Thread): for obj in camera_state.tracked_objects.values() if zone in obj.current_zones and not obj.false_positive ) + total_label_count = 0 # update counts and publish status for label in set(self.zone_data[zone].keys()) | set(obj_counter.keys()): + # Ignore the artificial all label + if label is "all": + continue + # if we have previously published a count for this zone/label zone_label = self.zone_data[zone][label] - all_labels_count = 0 if camera in zone_label: current_count = sum(zone_label.values()) zone_label[camera] = ( @@ -916,9 +926,10 @@ class TrackedObjectProcessor(threading.Thread): new_count, retain=False, ) - + # Set the count for the /zone/all topic. - all_labels_count += new_count + total_label_count += new_count + # if this is a new zone/label combo for this camera else: if label in obj_counter: @@ -928,16 +939,30 @@ class TrackedObjectProcessor(threading.Thread): obj_counter[label], retain=False, ) - - # Set the count for the /zone/all topic. - all_labels_count += obj_counter[label] - - # Publish count of all objects for this zone. - # TODO may need to check and only publish if - # value has changed from previous publish count?? + + # Set the count for the /zone/all topic. + total_label_count += obj_counter[label] + + # if we have previously published a count for this zone all labels + zone_label = self.zone_data[zone]["all"] + logger.info(f'zone info {zone_label} with count {total_label_count}') + if camera in zone_label: + current_count = sum(zone_label.values()) + zone_label[camera] = total_label_count + new_count = sum(zone_label.values()) + + if new_count != current_count: + self.client.publish( + f"{self.topic_prefix}/{zone}/all", + new_count, + retain=False, + ) + # if this is a new zone all label for this camera + else: + zone_label[camera] = total_label_count self.client.publish( f"{self.topic_prefix}/{zone}/all", - all_labels_count, + total_label_count, retain=False, )