feat: 寻找距离最近的face index

This commit is contained in:
caoqianming 2023-09-17 01:08:37 +08:00
parent 8c58d3990e
commit 5317c2c715
1 changed files with 11 additions and 5 deletions

View File

@ -15,6 +15,7 @@ from apps.third.dahua import dhClient
from apps.third.models import TDevice
from apps.third.tapis import dhapis
from apps.utils.tools import rannum, ranstr
import numpy as np
myLogger = logging.getLogger('log')
@ -398,11 +399,16 @@ class HrmService:
face_datas = cache.get('face_datas_dlib')
results = face_recognition.compare_faces(face_datas['datas'],
unknown_face_encoding, tolerance=0.45)
if True in results:
first_match_index = results.index(True)
# 识别成功
ep = Employee.objects.get(id=face_datas['eps'][first_match_index])
return ep, ''
face_distances = face_recognition.face_distance(face_datas['datas'], unknown_face_encoding)
best_match_index = np.argmin(face_distances)
if results[best_match_index]:
epId = face_datas['eps'][best_match_index]
return Employee.objects.get(id=epId), ''
# if True in results:
# first_match_index = results.index(True)
# # 识别成功
# ep = Employee.objects.get(id=face_datas['eps'][first_match_index])
# return ep, ''
return None, '人脸未匹配,请调整位置'
@classmethod