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
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
@ -567,8 +567,10 @@ class CameraState:
c(self.name, obj_name, count)
# publish for all labels detected for this camera
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", all_labels_count)
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] = (
@ -918,7 +928,8 @@ class TrackedObjectProcessor(threading.Thread):
)
# 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:
@ -930,14 +941,28 @@ class TrackedObjectProcessor(threading.Thread):
)
# 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.
# TODO may need to check and only publish if
# value has changed from previous publish count??
# 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",
all_labels_count,
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",
total_label_count,
retain=False,
)