fix: face_find_from_base64 bug

This commit is contained in:
caoqianming 2023-09-11 14:13:17 +08:00
parent 19239c6b42
commit 5dded4d235
1 changed files with 4 additions and 3 deletions

View File

@ -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), ''