diff --git a/client/drivers/login_system.py b/client/drivers/login_system.py index fee192f..b076ce7 100644 --- a/client/drivers/login_system.py +++ b/client/drivers/login_system.py @@ -17,12 +17,13 @@ from models.pose_detection.frame_capturer import RaspCapturer NUM_FACES = 5 -QUIT = -4 +QUIT = -6 RESET = -5 BAD_STATUS_MESSAGES = { Status.NO_FACES.value: "No face detected please", Status.TOO_MANY_FACES.value: "Too many faces detected", Status.NO_MATCH.value: "Could not match face", + Status.ALREADY_REGISTERED.value: "Face already registered", } QUIT_INSTRUCTIONS = "Right button to quit" diff --git a/client/models/face_recognition/recognition.py b/client/models/face_recognition/recognition.py index 043f8a3..b322fbb 100644 --- a/client/models/face_recognition/recognition.py +++ b/client/models/face_recognition/recognition.py @@ -9,6 +9,7 @@ class Status(Enum): + ALREADY_REGISTERED = -4 NO_FACES = -3 TOO_MANY_FACES = -2 NO_MATCH = -1 @@ -72,6 +73,14 @@ def register_faces(user_id: int, faces: list[np.ndarray]) -> int: if not all(matches): return Status.TOO_MANY_FACES.value + # Ensure user is not already registered + for _, other_user_embeddings in iter_face_embeddings(): + for embedding in face_embeddings: + matches = face_recognition.compare_faces(other_user_embeddings, embedding) + + if any(matches): + return Status.ALREADY_REGISTERED.value + register_face_embeddings(user_id, face_embeddings) return Status.OK.value