Skip to content

Commit f02284d

Browse files
committed
Automatically handle attributes by obj data parsing
1 parent 99bdb46 commit f02284d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

frigate/events/maintainer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from frigate.comms.events_updater import EventEndPublisher, EventUpdateSubscriber
88
from frigate.config import FrigateConfig
9+
from frigate.config.classification import ObjectClassificationType
910
from frigate.events.types import EventStateEnum, EventTypeEnum
1011
from frigate.models import Event
1112
from frigate.util.builtin import to_relative_box
@@ -247,6 +248,18 @@ def handle_object_detection(
247248
"recognized_license_plate"
248249
][1]
249250

251+
# only overwrite attribute-type custom model fields in the database if they're set
252+
for name, model_config in self.config.classification.custom.items():
253+
if (
254+
model_config.object_config
255+
and model_config.object_config.classification_type
256+
== ObjectClassificationType.attribute
257+
):
258+
value = event_data.get(name)
259+
if value is not None:
260+
event[Event.data][name] = value[0]
261+
event[Event.data][f"{name}_score"] = value[1]
262+
250263
(
251264
Event.insert(event)
252265
.on_conflict(

frigate/track/tracked_object.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,14 @@ def update(
377377
return (thumb_update, significant_change, path_update, autotracker_update)
378378

379379
def to_dict(self) -> dict[str, Any]:
380-
event = {
380+
# Tracking internals excluded from output (centroid, estimate, estimate_velocity)
381+
_EXCLUDED_OBJ_DATA_KEYS = {
382+
"centroid",
383+
"estimate",
384+
"estimate_velocity",
385+
}
386+
387+
event: dict[str, Any] = {
381388
"id": self.obj_data["id"],
382389
"camera": self.camera_config.name,
383390
"frame_time": self.obj_data["frame_time"],
@@ -412,6 +419,11 @@ def to_dict(self) -> dict[str, Any]:
412419
"recognized_license_plate": self.obj_data.get("recognized_license_plate"),
413420
}
414421

422+
# Add any other obj_data keys (e.g. custom attribute fields) not yet included
423+
for key, value in self.obj_data.items():
424+
if key not in _EXCLUDED_OBJ_DATA_KEYS and key not in event:
425+
event[key] = value
426+
415427
return event
416428

417429
def is_active(self) -> bool:

0 commit comments

Comments
 (0)