This commit is contained in:
Josh Hawkins 2025-03-12 10:15:14 -05:00
parent f305ff3a5a
commit 64851aeb54
6 changed files with 61 additions and 9 deletions

View File

@ -340,6 +340,8 @@ def events_explore(limit: int = 10):
"average_estimated_speed",
"velocity_angle",
"path_data",
"identifier",
"identifier_score",
]
},
"event_count": label_counts[event.label],
@ -627,6 +629,8 @@ def events_search(request: Request, params: EventsSearchQueryParams = Depends())
"average_estimated_speed",
"velocity_angle",
"path_data",
"identifier",
"identifier_score",
]
}

View File

@ -137,12 +137,13 @@ class CameraState:
# draw the bounding boxes on the frame
box = obj["box"]
text = (
obj["label"]
obj["sub_label"][0]
if (
not obj.get("sub_label")
or not is_label_printable(obj["sub_label"][0])
obj.get("sub_label") and is_label_printable(obj["sub_label"][0])
)
else obj["sub_label"][0]
else obj.get("identifier", [None])[0]
if (obj.get("identifier") and obj["identifier"][0])
else obj["label"]
)
draw_box_with_label(
frame_copy,

View File

@ -14,6 +14,7 @@ class EventMetadataTypeEnum(str, Enum):
manual_event_end = "manual_event_end"
regenerate_description = "regenerate_description"
sub_label = "sub_label"
identifier = "identifier"
class EventMetadataPublisher(Publisher):

View File

@ -1054,13 +1054,20 @@ class LicensePlateProcessingMixin:
for plate in plates
)
),
top_plate,
None,
)
# Send the result to the API
self.sub_label_publisher.publish(
EventMetadataTypeEnum.sub_label, (id, sub_label, avg_confidence)
)
# If it's a known plate, publish to sub_label
if sub_label is not None:
self.sub_label_publisher.publish(
EventMetadataTypeEnum.sub_label, (id, sub_label, avg_confidence)
)
# If it's not a known plate, publish to identifier instead
else:
self.sub_label_publisher.publish(
EventMetadataTypeEnum.identifier, (id, top_plate, avg_confidence)
)
self.detected_license_plates[id] = {
"plate": top_plate,
"char_confidences": top_char_confidences,

View File

@ -346,6 +346,41 @@ class TrackedObjectProcessor(threading.Thread):
return True
def set_identifier(
self, event_id: str, identifier: str | None, score: float | None
) -> None:
"""Update identifier for given event id."""
tracked_obj: TrackedObject = None
for state in self.camera_states.values():
tracked_obj = state.tracked_objects.get(event_id)
if tracked_obj is not None:
break
try:
event: Event = Event.get(Event.id == event_id)
except DoesNotExist:
event = None
if not tracked_obj and not event:
return
if tracked_obj:
tracked_obj.obj_data["identifier"] = (identifier, score)
if event:
data = event.data
data["identifier"] = identifier
if identifier is None:
data["identifier_score"] = None
elif score is not None:
data["identifier_score"] = score
event.data = data
event.save()
return True
def create_manual_event(self, payload: tuple) -> None:
(
frame_time,
@ -507,6 +542,9 @@ class TrackedObjectProcessor(threading.Thread):
if topic.endswith(EventMetadataTypeEnum.sub_label.value):
(event_id, sub_label, score) = payload
self.set_sub_label(event_id, sub_label, score)
if topic.endswith(EventMetadataTypeEnum.identifier.value):
(event_id, identifier, score) = payload
self.set_identifier(event_id, identifier, score)
elif topic.endswith(EventMetadataTypeEnum.manual_event_create.value):
self.create_manual_event(payload)
elif topic.endswith(EventMetadataTypeEnum.manual_event_end.value):

View File

@ -365,6 +365,7 @@ class TrackedObject:
"average_estimated_speed": self.average_estimated_speed,
"velocity_angle": self.velocity_angle,
"path_data": self.path_data,
"identifier": self.obj_data.get("identifier"),
}
return event