From a1ae5b67d85e8d0a3697258107f35db1f1757551 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sat, 1 Oct 2022 08:00:56 -0600 Subject: [PATCH] Mqtt sub labels (#3899) * Set sub label on object data if event is in progress * Include sub_label in dict * Don't need to set and passively get * Formatting * Don't expect event to be valid * Update docs to reflect that sub label is included --- docs/docs/integrations/mqtt.md | 2 ++ frigate/http.py | 13 ++++++++++++- frigate/object_processing.py | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/docs/integrations/mqtt.md b/docs/docs/integrations/mqtt.md index 7d5aeb049..30e8b2152 100644 --- a/docs/docs/integrations/mqtt.md +++ b/docs/docs/integrations/mqtt.md @@ -45,6 +45,7 @@ Message published for each changed event. The first message is published when th "frame_time": 1607123961.837752, "snapshot_time": 1607123961.837752, "label": "person", + "sub_label": null, "top_score": 0.958984375, "false_positive": false, "start_time": 1607123955.475377, @@ -69,6 +70,7 @@ Message published for each changed event. The first message is published when th "frame_time": 1607123962.082975, "snapshot_time": 1607123961.837752, "label": "person", + "sub_label": null, "top_score": 0.958984375, "false_positive": false, "start_time": 1607123955.475377, diff --git a/frigate/http.py b/frigate/http.py index f6c9ca003..dd56486f2 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -28,6 +28,7 @@ from playhouse.shortcuts import model_to_dict from frigate.const import CLIPS_DIR from frigate.models import Event, Recordings +from frigate.object_processing import TrackedObject, TrackedObjectProcessor from frigate.stats import stats_snapshot from frigate.version import VERSION @@ -211,7 +212,7 @@ def delete_retain(id): @bp.route("/events//sub_label", methods=("POST",)) def set_sub_label(id): try: - event = Event.get(Event.id == id) + event: Event = Event.get(Event.id == id) except DoesNotExist: return make_response( jsonify({"success": False, "message": "Event " + id + " not found"}), 404 @@ -234,6 +235,16 @@ def set_sub_label(id): 400, ) + if not event.end_time: + tracked_obj: TrackedObject = ( + current_app.detected_frames_processor.camera_states[event.camera].get( + event.id + ) + ) + + if tracked_obj: + tracked_obj.obj_data["sub_label"] = new_sub_label + event.sub_label = new_sub_label event.save() return make_response( diff --git a/frigate/object_processing.py b/frigate/object_processing.py index 3712d517c..56acf7667 100644 --- a/frigate/object_processing.py +++ b/frigate/object_processing.py @@ -180,6 +180,7 @@ class TrackedObject: "frame_time": self.obj_data["frame_time"], "snapshot_time": snapshot_time, "label": self.obj_data["label"], + "sub_label": self.obj_data.get("sub_label"), "top_score": self.top_score, "false_positive": self.false_positive, "start_time": self.obj_data["start_time"],