上传证件照bug
This commit is contained in:
parent
d54ea2c2dc
commit
8cb4f244d1
|
@ -21,7 +21,7 @@ class HRMService:
|
|||
os.remove(filepath)
|
||||
except:
|
||||
os.remove(filepath)
|
||||
return None, '头像解码失败'
|
||||
return None, '人脸识别失败'
|
||||
|
||||
# 匹配人脸库
|
||||
face_datas = cache.get('face_datas')
|
||||
|
@ -32,13 +32,13 @@ class HRMService:
|
|||
results = face_recognition.compare_faces(face_datas,
|
||||
unknown_face_encoding, tolerance=0.5)
|
||||
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):
|
||||
|
@ -47,6 +47,6 @@ class HRMService:
|
|||
picture_of_me = face_recognition.load_image_file(photo_path)
|
||||
my_face_encoding = face_recognition.face_encodings(picture_of_me)[0]
|
||||
face_data_list = my_face_encoding.tolist()
|
||||
return face_data_list
|
||||
return face_data_list, ''
|
||||
except:
|
||||
return None
|
||||
return None, '人脸识别失败'
|
|
@ -42,13 +42,13 @@ class EmployeeViewSet(CreateUpdateModelAMixin, OptimizationMixin, UpdateModelMix
|
|||
serializer.is_valid(raise_exception=True)
|
||||
photo = data.get('photo', None)
|
||||
if instance.photo != photo:
|
||||
f_l = HRMService.get_facedata_from_img(img_path=photo)
|
||||
f_l, msg = HRMService.get_facedata_from_img(img_path=photo)
|
||||
if f_l:
|
||||
serializer.save(update_by=request.user, face_data = f_l)
|
||||
# 更新人脸缓存
|
||||
update_all_user_facedata_cache.delay()
|
||||
return Response()
|
||||
return Response('头像识别失败', status=status.HTTP_400_BAD_REQUEST)
|
||||
return Response(msg, status=status.HTTP_400_BAD_REQUEST)
|
||||
serializer.save(update_by=request.user)
|
||||
return Response()
|
||||
|
||||
|
|
Loading…
Reference in New Issue