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