NVR with realtime local object detection for IP cameras
TypeScript aicameragoogle-coralhome-assistanthome-automationhomeautomationmqttnvrobject-detectionrealtimertsptensorflow
Add face and lpr to tracked object update topic (#17940)
Nicolas Mowen4b4053d174d5
diff --git a/docs/docs/integrations/mqtt.md b/docs/docs/integrations/mqtt.mdindex 4139efaf34..d6dcaa3fb4 100644--- a/docs/docs/integrations/mqtt.md+++ b/docs/docs/integrations/mqtt.md@@ -104,7 +104,9 @@ Message published for each changed tracked object. The first message is publishe### `frigate/tracked_object_update`-Message published for updates to tracked object metadata, for example when GenAI runs and returns a tracked object description.+Message published for updates to tracked object metadata, for example:++#### Generative AI Description Update```json{@@ -114,6 +116,33 @@ Message published for updates to tracked object metadata, for example when GenAI}```+#### Face Recognition Update++```json+{+ "type": "face",+ "id": "1607123955.475377-mxklsc",+ "name": "John",+ "score": 0.95,+ "camera": "front_door_cam",+ "timestamp": 1607123958.748393,+}+```++#### License Plate Recognition Update++```json+{+ "type": "lpr",+ "id": "1607123955.475377-mxklsc",+ "name": "John's Car",+ "plate": "123ABC",+ "score": 0.95,+ "camera": "driveway_cam",+ "timestamp": 1607123958.748393,+}+```+### `frigate/reviews`Message published for each changed review item. The first message is published when the `detection` or `alert` is initiated. When additional objects are detected or when a zone change occurs, it will publish a, `update` message with the same id. When the review activity has ended a final `end` message is published.diff --git a/frigate/comms/dispatcher.py b/frigate/comms/dispatcher.pyindex 4c0b0a8ffe..87891ec88d 100644--- a/frigate/comms/dispatcher.py+++ b/frigate/comms/dispatcher.py@@ -135,6 +135,7 @@ class Dispatcher:"type": TrackedObjectUpdateTypesEnum.description,"id": event.id,"description": event.data["description"],+ "camera": event.camera,}),)diff --git a/frigate/data_processing/common/license_plate/mixin.py b/frigate/data_processing/common/license_plate/mixin.pyindex e471aa3048..8dea639d6a 100644--- a/frigate/data_processing/common/license_plate/mixin.py+++ b/frigate/data_processing/common/license_plate/mixin.py@@ -2,6 +2,7 @@import base64import datetime+import jsonimport loggingimport mathimport os@@ -23,6 +24,7 @@ from frigate.comms.event_metadata_updater import ()from frigate.const import CLIPS_DIRfrom frigate.embeddings.onnx.lpr_embedding import LPR_EMBEDDING_SIZE+from frigate.types import TrackedObjectUpdateTypesEnumfrom frigate.util.builtin import EventsPerSecondfrom frigate.util.image import area@@ -1510,6 +1512,20 @@ class LicensePlateProcessingMixin:)# always publish to recognized_license_plate field+ self.requestor.send_data(+ "tracked_object_update",+ json.dumps(+ {+ "type": TrackedObjectUpdateTypesEnum.lpr,+ "name": sub_label,+ "plate": top_plate,+ "score": avg_confidence,+ "id": id,+ "camera": camera,+ "timestamp": start,+ }+ ),+ )self.sub_label_publisher.publish(EventMetadataTypeEnum.recognized_license_plate,(id, top_plate, avg_confidence),diff --git a/frigate/data_processing/post/license_plate.py b/frigate/data_processing/post/license_plate.pyindex e439fb7635..e7d4ca6e57 100644--- a/frigate/data_processing/post/license_plate.py+++ b/frigate/data_processing/post/license_plate.py@@ -9,6 +9,7 @@ from peewee import DoesNotExistfrom frigate.comms.embeddings_updater import EmbeddingsRequestEnumfrom frigate.comms.event_metadata_updater import EventMetadataPublisher+from frigate.comms.inter_process import InterProcessRequestorfrom frigate.config import FrigateConfigfrom frigate.data_processing.common.license_plate.mixin import (WRITE_DEBUG_IMAGES,@@ -31,11 +32,13 @@ class LicensePlatePostProcessor(LicensePlateProcessingMixin, PostProcessorApi):def __init__(self,config: FrigateConfig,+ requestor: InterProcessRequestor,sub_label_publisher: EventMetadataPublisher,metrics: DataProcessorMetrics,model_runner: LicensePlateModelRunner,detected_license_plates: dict[str, dict[str, any]],):+ self.requestor = self.requestorself.detected_license_plates = detected_license_platesself.model_runner = model_runnerself.lpr_config = config.lprdiff --git a/frigate/data_processing/real_time/face.py b/frigate/data_processing/real_time/face.pyindex fb55bb7d21..d91ab9b80f 100644--- a/frigate/data_processing/real_time/face.py+++ b/frigate/data_processing/real_time/face.py@@ -2,6 +2,7 @@import base64import datetime+import jsonimport loggingimport osimport random@@ -17,6 +18,7 @@ from frigate.comms.event_metadata_updater import (EventMetadataPublisher,EventMetadataTypeEnum,)+from frigate.comms.inter_process import InterProcessRequestorfrom frigate.config import FrigateConfigfrom frigate.const import FACE_DIR, MODEL_CACHE_DIRfrom frigate.data_processing.common.face.model import (@@ -24,6 +26,7 @@ from frigate.data_processing.common.face.model import (FaceNetRecognizer,FaceRecognizer,)+from frigate.types import TrackedObjectUpdateTypesEnumfrom frigate.util.builtin import EventsPerSecondfrom frigate.util.image import area@@ -42,11 +45,13 @@ class FaceRealTimeProcessor(RealTimeProcessorApi):def __init__(self,config: FrigateConfig,+ requestor: InterProcessRequestor,sub_label_publisher: EventMetadataPublisher,metrics: DataProcessorMetrics,):super().__init__(config, metrics)self.face_config = config.face_recognition+ self.requestor = requestorself.sub_label_publisher = sub_label_publisherself.face_detector: cv2.FaceDetectorYN = Noneself.requires_face_detection = "face" not in self.config.objects.all_objects@@ -157,8 +162,9 @@ class FaceRealTimeProcessor(RealTimeProcessorApi):def process_frame(self, obj_data: dict[str, any], frame: np.ndarray):"""Look for faces in image."""self.metrics.face_rec_fps.value = self.faces_per_second.eps()+ camera = obj_data["camera"]- if not self.config.cameras[obj_data["camera"]].face_recognition.enabled:+ if not self.config.cameras[camera].face_recognition.enabled:returnstart = datetime.datetime.now().timestamp()@@ -245,7 +251,7 @@ class FaceRealTimeProcessor(RealTimeProcessorApi):if (not face_boxor area(face_box)- < self.config.cameras[obj_data["camera"]].face_recognition.min_area+ < self.config.cameras[camera].face_recognition.min_area):logger.debug(f"Invalid face box {face}")return@@ -286,6 +292,20 @@ class FaceRealTimeProcessor(RealTimeProcessorApi):self.person_face_history[id])+ self.requestor.send_data(+ "tracked_object_update",+ json.dumps(+ {+ "type": TrackedObjectUpdateTypesEnum.face,+ "name": weighted_sub_label,+ "score": weighted_score,+ "id": id,+ "camera": camera,+ "timestamp": start,+ }+ ),+ )+if weighted_score >= self.face_config.recognition_threshold:self.sub_label_publisher.publish(EventMetadataTypeEnum.sub_label,diff --git a/frigate/data_processing/real_time/license_plate.py b/frigate/data_processing/real_time/license_plate.pyindex 95d53a3438..8649680733 100644--- a/frigate/data_processing/real_time/license_plate.py+++ b/frigate/data_processing/real_time/license_plate.py@@ -5,6 +5,7 @@ import loggingimport numpy as npfrom frigate.comms.event_metadata_updater import EventMetadataPublisher+from frigate.comms.inter_process import InterProcessRequestorfrom frigate.config import FrigateConfigfrom frigate.data_processing.common.license_plate.mixin import (LicensePlateProcessingMixin,@@ -23,11 +24,13 @@ class LicensePlateRealTimeProcessor(LicensePlateProcessingMixin, RealTimeProcessdef __init__(self,config: FrigateConfig,+ requestor: InterProcessRequestor,sub_label_publisher: EventMetadataPublisher,metrics: DataProcessorMetrics,model_runner: LicensePlateModelRunner,detected_license_plates: dict[str, dict[str, any]],):+ self.requestor = requestorself.detected_license_plates = detected_license_platesself.model_runner = model_runnerself.lpr_config = config.lprdiff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.pyindex ba9b42f77c..07115ca944 100644--- a/frigate/embeddings/maintainer.py+++ b/frigate/embeddings/maintainer.py@@ -135,6 +135,7 @@ class EmbeddingMaintainer(threading.Thread):self.realtime_processors.append(LicensePlateRealTimeProcessor(self.config,+ self.requestor,self.event_metadata_publisher,metrics,lpr_model_runner,@@ -149,6 +150,7 @@ class EmbeddingMaintainer(threading.Thread):self.post_processors.append(LicensePlatePostProcessor(self.config,+ self.requestor,self.event_metadata_publisher,metrics,lpr_model_runner,@@ -583,6 +585,7 @@ class EmbeddingMaintainer(threading.Thread):"type": TrackedObjectUpdateTypesEnum.description,"id": event.id,"description": description,+ "camera": event.camera,},)diff --git a/frigate/types.py b/frigate/types.pyindex 2422c5551c..ee48cc02b8 100644--- a/frigate/types.py+++ b/frigate/types.py@@ -25,3 +25,5 @@ class ModelStatusTypesEnum(str, Enum):class TrackedObjectUpdateTypesEnum(str, Enum):description = "description"+ face = "face"+ lpr = "lpr"diff --git a/web/public/locales/en/views/faceLibrary.json b/web/public/locales/en/views/faceLibrary.jsonindex cec5e8d7db..08ba2c673f 100644--- a/web/public/locales/en/views/faceLibrary.json+++ b/web/public/locales/en/views/faceLibrary.json@@ -65,6 +65,7 @@"addFaceLibrary": "{{name}} has successfully been added to the Face Library!","deletedFace_one": "Successfully deleted {{count}} face.","deletedFace_other": "Successfully deleted {{count}} faces.",+ "deletedName_zero": "Empty collection deleted successfully.","deletedName_one": "{{count}} face has been successfully deleted.","deletedName_other": "{{count}} faces have been successfully deleted.","renamedFace": "Successfully renamed face to {{name}}",diff --git a/web/public/locales/yue_Hant/audio.json b/web/public/locales/yue-Hant/audio.jsonsimilarity index 100%rename from web/public/locales/yue_Hant/audio.jsonrename to web/public/locales/yue-Hant/audio.jsondiff --git a/web/public/locales/yue_Hant/components/auth.json b/web/public/locales/yue-Hant/components/auth.jsonsimilarity index 100%rename from web/public/locales/yue_Hant/components/auth.jsonrename to web/public/locales/yue-Hant/components/auth.jsondiff --git a/web/public/locales/yue_Hant/components/icons.json b/web/public/locales/yue-Hant/components/icons.jsonsimilarity index 100%rename from web/public/locales/yue_Hant/components/icons.jsonrename to web/public/locales/yue-Hant/components/icons.jsondiff --git a/web/public/locales/yue_Hant/components/input.json b/web/public/locales/yue-Hant/components/input.jsonsimilarity index 100%rename from web/public/locales/yue_Hant/components/input.jsonrename to web/public/locales/yue-Hant/components/input.jsondiff --git a/web/public/locales/yue_Hant/objects.json b/web/public/locales/yue-Hant/objects.jsonsimilarity index 100%rename from web/public/locales/yue_Hant/objects.jsonrename to web/public/locales/yue-Hant/objects.jsondiff --git a/web/public/locales/yue_Hant/views/configEditor.json b/web/public/locales/yue-Hant/views/configEditor.jsonsimilarity index 100%rename from web/public/locales/yue_Hant/views/configEditor.jsonrename to web/public/locales/yue-Hant/views/configEditor.jsondiff --git a/web/public/locales/yue_Hant/views/events.json b/web/public/locales/yue-Hant/views/events.jsonsimilarity index 100%rename from web/public/locales/yue_Hant/views/events.jsonrename to web/public/locales/yue-Hant/views/events.jsondiff --git a/web/public/locales/yue_Hant/views/recording.json b/web/public/locales/yue-Hant/views/recording.jsonsimilarity index 100%rename from web/public/locales/yue_Hant/views/recording.jsonrename to web/public/locales/yue-Hant/views/recording.json