From 5317c2c7154addd24782f7ddac369421056df5e7 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sun, 17 Sep 2023 01:08:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AF=BB=E6=89=BE=E8=B7=9D=E7=A6=BB?= =?UTF-8?q?=E6=9C=80=E8=BF=91=E7=9A=84face=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/hrm/services.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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