Fix overwriting of objects

This commit is contained in:
Nick Mowen 2022-03-06 13:11:17 -07:00
parent 150fc25fc9
commit 7ded3e2dff

View File

@ -555,11 +555,11 @@ class CameraState:
) )
# keep track of all labels detected for this camera # keep track of all labels detected for this camera
all_labels_count = 0 total_label_count = 0
# report on detected objects # report on detected objects
for obj_name, count in obj_counter.items(): for obj_name, count in obj_counter.items():
all_labels_count += count total_label_count += count
if count != self.object_counts[obj_name]: if count != self.object_counts[obj_name]:
self.object_counts[obj_name] = count self.object_counts[obj_name] = count
@ -567,8 +567,10 @@ class CameraState:
c(self.name, obj_name, count) c(self.name, obj_name, count)
# publish for all labels detected for this camera # publish for all labels detected for this camera
for c in self.callbacks["object_status"]: if total_label_count != self.object_counts.get("all"):
c(self.name, "all", all_labels_count) 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 # expire any objects that are >0 and no longer detected
expired_objects = [ expired_objects = [
@ -577,6 +579,10 @@ class CameraState:
if count > 0 and obj_name not in obj_counter if count > 0 and obj_name not in obj_counter
] ]
for obj_name in expired_objects: for obj_name in expired_objects:
# Ignore the artificial all label
if obj_name is "all":
continue
self.object_counts[obj_name] = 0 self.object_counts[obj_name] = 0
for c in self.callbacks["object_status"]: for c in self.callbacks["object_status"]:
c(self.name, obj_name, 0) c(self.name, obj_name, 0)
@ -898,12 +904,16 @@ class TrackedObjectProcessor(threading.Thread):
for obj in camera_state.tracked_objects.values() for obj in camera_state.tracked_objects.values()
if zone in obj.current_zones and not obj.false_positive if zone in obj.current_zones and not obj.false_positive
) )
total_label_count = 0
# update counts and publish status # update counts and publish status
for label in set(self.zone_data[zone].keys()) | set(obj_counter.keys()): 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 # if we have previously published a count for this zone/label
zone_label = self.zone_data[zone][label] zone_label = self.zone_data[zone][label]
all_labels_count = 0
if camera in zone_label: if camera in zone_label:
current_count = sum(zone_label.values()) current_count = sum(zone_label.values())
zone_label[camera] = ( zone_label[camera] = (
@ -918,7 +928,8 @@ class TrackedObjectProcessor(threading.Thread):
) )
# Set the count for the /zone/all topic. # 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 # if this is a new zone/label combo for this camera
else: else:
if label in obj_counter: if label in obj_counter:
@ -929,15 +940,29 @@ class TrackedObjectProcessor(threading.Thread):
retain=False, retain=False,
) )
# Set the count for the /zone/all topic. # Set the count for the /zone/all topic.
all_labels_count += obj_counter[label] total_label_count += obj_counter[label]
# Publish count of all objects for this zone. # if we have previously published a count for this zone all labels
# TODO may need to check and only publish if zone_label = self.zone_data[zone]["all"]
# value has changed from previous publish count?? 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( self.client.publish(
f"{self.topic_prefix}/{zone}/all", f"{self.topic_prefix}/{zone}/all",
all_labels_count, total_label_count,
retain=False, retain=False,
) )