diff --git a/apps/hrm/services.py b/apps/hrm/services.py index 0f9edb34..4dde5139 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -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