From b61212980b930922fcbb375d06884a4ad0b8a68b Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 24 Feb 2022 20:40:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=BA=E8=84=B8=E8=AF=86?= =?UTF-8?q?=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/hrm/services.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hb_server/apps/hrm/services.py b/hb_server/apps/hrm/services.py index f2101f6..1abfb19 100644 --- a/hb_server/apps/hrm/services.py +++ b/hb_server/apps/hrm/services.py @@ -17,36 +17,37 @@ class HRMService: f.write(base64_data) try: unknown_picture = face_recognition.load_image_file(filepath) - unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0] + unknown_face_encoding = face_recognition.face_encodings(unknown_picture, num_jitters=3)[0] os.remove(filepath) except: os.remove(filepath) - return None, '人脸识别失败' + return None, '识别失败,请调整位置' # 匹配人脸库 face_datas = cache.get('face_datas') - face_users = cache.get('face_users') if face_datas is None: update_all_user_facedata_cache() + face_datas = cache.get('face_datas') + face_users = cache.get('face_users') try: results = face_recognition.compare_faces(face_datas, - unknown_face_encoding, tolerance=0.49) + unknown_face_encoding, tolerance=0.4) except: - return None, '人脸匹配失败' + return None, '人脸未匹配' for index, value in enumerate(results): if value: # 识别成功 user = User.objects.get(id=face_users[index]) return user, '' - return None, '人脸匹配失败' + return None, '人脸未匹配' @classmethod def get_facedata_from_img(cls, img_path): try: photo_path = settings.BASE_DIR + img_path picture_of_me = face_recognition.load_image_file(photo_path) - my_face_encoding = face_recognition.face_encodings(picture_of_me)[0] + my_face_encoding = face_recognition.face_encodings(picture_of_me, num_jitters=10)[0] face_data_list = my_face_encoding.tolist() return face_data_list, '' except: - return None, '人脸识别失败' \ No newline at end of file + return None, '人脸数据获取失败请重新上传图片' \ No newline at end of file