From 5dded4d23532299f4e7e5091ce74838160a3972e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 11 Sep 2023 14:13:17 +0800 Subject: [PATCH] fix: face_find_from_base64 bug --- apps/hrm/services.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/hrm/services.py b/apps/hrm/services.py index bd7ba40d..e583c36a 100755 --- a/apps/hrm/services.py +++ b/apps/hrm/services.py @@ -406,12 +406,13 @@ class HrmService: def face_find_from_base64(cls, base64_data): from deepface import DeepFace img_name = str(uuid.uuid4()) - img_path = settings.BASE_DIR +'/temp/face_' + img_name +'.png' + img_path = settings.BASE_DIR +'/temp/face_' + img_name +'.jpg' with open(img_path, 'wb') as f: f.write(base64_data) db_path = os.path.join(settings.BASE_DIR, 'media/face') - df = DeepFace.find(img_path=img_path, db_path=db_path, model_name='Facenet512') - if df.shape[0] > 0: + dfs = DeepFace.find(img_path=img_path, db_path=db_path, model_name='Facenet512') + df = dfs[0] + if not df.empty: matched = df.iloc[0].identity epId = matched.split('/')[-1].split('.')[0] return Employee.objects.get(id=epId), ''