From 24a0e85718797c6c192451b78cd7346bf37ebebf Mon Sep 17 00:00:00 2001 From: haotian <2421912570@qq.com> Date: Tue, 30 Sep 2025 10:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BA=AB=E4=BB=BD=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yaml | 4 ++-- main.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/config.yaml b/config.yaml index 477d90f..8ab9456 100644 --- a/config.yaml +++ b/config.yaml @@ -35,8 +35,8 @@ face_recognition: # 角色映射配置 role_mapping: - employee_threshold: 0.85 # 员工识别阈值 - visitor_threshold: 0.70 # 访客识别阈值 + stranger_threshold: 0.99 # 员工识别阈值 + # visitor_threshold: 0.70 # 访客识别阈值 # 低于visitor_threshold视为陌生人 # 日志配置 diff --git a/main.py b/main.py index f4f88f1..daeb085 100644 --- a/main.py +++ b/main.py @@ -179,16 +179,17 @@ class FaceRecognitionSystem: self.logger.error(f"人脸识别错误: {e}") return None - def determine_role(self, similarity: float) -> str: + def determine_role(self, persion_id: str,similarity: float) -> str: """根据相似度确定角色""" role_config = self.config['role_mapping'] - if similarity >= role_config['employee_threshold']: - return "员工" - elif similarity >= role_config['visitor_threshold']: - return "访客" + if similarity < role_config['stranger_threshold']: + return "未知", "陌生人" else: - return "陌生人" + t = persion_id.split("_") + name = t[0] + role = "员工" if len(t) == 1 else "访客" + return name, role def should_recognize(self, person_id: str) -> bool: """检查是否应该识别(防止重复识别)""" @@ -344,10 +345,10 @@ class FaceRecognitionSystem: # 检查是否应该识别(防止重复) if self.should_recognize(person_id): - role = self.determine_role(similarity) + role = self.determine_role(person_id,similarity) self.logger.info( - f"识别到: {person_id}, 相似度: {similarity:.2f}, 角色: {role}" + f"识别到: {person_id}, 相似度: {similarity:.6f}, 角色: {role}" ) # 发送识别结果