diff --git a/frigate/api/classification.py b/frigate/api/classification.py index 6405516e0..9808e0dc0 100644 --- a/frigate/api/classification.py +++ b/frigate/api/classification.py @@ -40,10 +40,10 @@ def get_faces(): @router.post("/faces/{name}") async def register_face(request: Request, name: str, file: UploadFile): context: EmbeddingsContext = request.app.embeddings - context.register_face(name, await file.read()) + result = context.register_face(name, await file.read()) return JSONResponse( - status_code=200, - content={"success": True, "message": "Successfully registered face."}, + status_code=200 if result.get("success", True) else 400, + content=result, ) diff --git a/frigate/embeddings/__init__.py b/frigate/embeddings/__init__.py index 43da686ce..05c49013e 100644 --- a/frigate/embeddings/__init__.py +++ b/frigate/embeddings/__init__.py @@ -192,8 +192,8 @@ class EmbeddingsContext: return results - def register_face(self, face_name: str, image_data: bytes) -> None: - self.requestor.send_data( + def register_face(self, face_name: str, image_data: bytes) -> dict[str, any]: + return self.requestor.send_data( EmbeddingsRequestEnum.register_face.value, { "face_name": face_name, diff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.py index 6aa503624..e7c2605e4 100644 --- a/frigate/embeddings/maintainer.py +++ b/frigate/embeddings/maintainer.py @@ -144,7 +144,10 @@ class EmbeddingMaintainer(threading.Thread): ) elif topic == EmbeddingsRequestEnum.register_face.value: if not self.face_recognition_enabled: - return False + return { + "message": "Face recognition is not enabled.", + "success": False, + } rand_id = "".join( random.choices(string.ascii_lowercase + string.digits, k=6) @@ -164,7 +167,10 @@ class EmbeddingMaintainer(threading.Thread): face_box = self._detect_face(img) if not face_box: - return False + return { + "message": "No face was detected.", + "success": False, + } face = img[face_box[1] : face_box[3], face_box[0] : face_box[2]] ret, thumbnail = cv2.imencode( @@ -181,7 +187,10 @@ class EmbeddingMaintainer(threading.Thread): output.write(thumbnail.tobytes()) self.face_classifier.clear_classifier() - return True + return { + "message": "Successfully registered face.", + "success": True, + } except Exception as e: logger.error(f"Unable to handle embeddings request {e}")