修改身份识别方法

This commit is contained in:
haotian 2025-09-30 10:45:43 +08:00
parent 309da9c910
commit 24a0e85718
2 changed files with 11 additions and 10 deletions

View File

@ -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视为陌生人
# 日志配置

17
main.py
View File

@ -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}"
)
# 发送识别结果