Adjust to score system

This commit is contained in:
Nicolas Mowen 2024-11-21 17:08:09 -07:00
parent 3d1c35370d
commit 2b7c40494e
2 changed files with 9 additions and 7 deletions

View File

@ -456,15 +456,15 @@ class EmbeddingMaintainer(threading.Thread):
if not res: if not res:
return return
sub_label, distance = res sub_label, score = res
logger.debug( logger.debug(
f"Detected best face for person as: {sub_label} with distance {distance}" f"Detected best face for person as: {sub_label} with score {score}"
) )
if id in self.detected_faces and distance >= self.detected_faces[id]: if id in self.detected_faces and score <= self.detected_faces[id]:
logger.debug( logger.debug(
f"Recognized face distance {distance} is greater than previous face distance ({self.detected_faces.get(id)})." f"Recognized face distance {score} is less than previous face distance ({self.detected_faces.get(id)})."
) )
return return
@ -473,11 +473,12 @@ class EmbeddingMaintainer(threading.Thread):
json={ json={
"camera": obj_data.get("camera"), "camera": obj_data.get("camera"),
"subLabel": sub_label, "subLabel": sub_label,
"subLabelScore": score
}, },
) )
if resp.status_code == 200: if resp.status_code == 200:
self.detected_faces[id] = distance self.detected_faces[id] = score
def _detect_license_plate(self, input: np.ndarray) -> tuple[int, int, int, int]: def _detect_license_plate(self, input: np.ndarray) -> tuple[int, int, int, int]:
"""Return the dimensions of the input image as [x, y, width, height].""" """Return the dimensions of the input image as [x, y, width, height]."""

View File

@ -165,7 +165,7 @@ class FaceClassificationModel:
def __init__(self, config: FaceRecognitionConfig, db: SqliteQueueDatabase): def __init__(self, config: FaceRecognitionConfig, db: SqliteQueueDatabase):
self.config = config self.config = config
self.db = db self.db = db
self.recognizer = cv2.face.LBPHFaceRecognizer_create(radius=4, threshold=config.threshold) self.recognizer = cv2.face.LBPHFaceRecognizer_create(radius=4, threshold=(1 - config.threshold) * 1000)
self.label_map: dict[int, str] = {} self.label_map: dict[int, str] = {}
def __build_classifier(self) -> None: def __build_classifier(self) -> None:
@ -198,5 +198,6 @@ class FaceClassificationModel:
if index == -1: if index == -1:
return None return None
return self.label_map[index], distance score = 1.0 - (distance / 1000)
return self.label_map[index], round(score, 2)