Skip to content

NVR with realtime local object detection for IP cameras

Sub label api score (#7113)

Nicolas Mowen6adc81014576
diff --git a/docs/docs/integrations/api.md b/docs/docs/integrations/api.md
index f36f337704..50b4e6d752 100644
--- a/docs/docs/integrations/api.md
+++ b/docs/docs/integrations/api.md
@@ -217,7 +217,8 @@ Sub labels must be 100 characters or shorter.
```json
{
- "subLabel": "some_string"
+ "subLabel": "some_string",
+ "subLabelScore": 0.79,
}
```
diff --git a/docs/docs/integrations/mqtt.md b/docs/docs/integrations/mqtt.md
index 43539d461c..8f690bcaab 100644
--- a/docs/docs/integrations/mqtt.md
+++ b/docs/docs/integrations/mqtt.md
@@ -74,7 +74,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,
+ "sub_label": ["John Smith", 0.79],
"top_score": 0.958984375,
"false_positive": false,
"start_time": 1607123955.475377,
diff --git a/frigate/http.py b/frigate/http.py
index 95fd255021..08201b1774 100644
--- a/frigate/http.py
+++ b/frigate/http.py
@@ -370,10 +370,9 @@ def set_sub_label(id):
jsonify({"success": False, "message": "Event " + id + " not found"}), 404
)
- if request.json:
- new_sub_label = request.json.get("subLabel")
- else:
- new_sub_label = None
+ json: dict[str, any] = request.get_json(silent=True) or {}
+ new_sub_label = json.get("subLabel")
+ new_score = json.get("subLabelScore")
if new_sub_label and len(new_sub_label) > 100:
return make_response(
@@ -387,6 +386,18 @@ def set_sub_label(id):
400,
)
+ if new_score is not None and (new_score > 1.0 or new_score < 0):
+ return make_response(
+ jsonify(
+ {
+ "success": False,
+ "message": new_score
+ + " does not fit within the expected bounds 0 <= score <= 1.0",
+ }
+ ),
+ 400,
+ )
+
if not event.end_time:
tracked_obj: TrackedObject = (
current_app.detected_frames_processor.camera_states[
@@ -395,9 +406,15 @@ def set_sub_label(id):
)
if tracked_obj:
- tracked_obj.obj_data["sub_label"] = new_sub_label
+ tracked_obj.obj_data["sub_label"] = (new_sub_label, new_score)
event.sub_label = new_sub_label
+
+ if new_score:
+ data = event.data
+ data["sub_label_score"] = new_score
+ event.data = data
+
event.save()
return make_response(
jsonify(