feat: 寻找距离最近的face index
This commit is contained in:
parent
8c58d3990e
commit
5317c2c715
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue