fix: 还是使用face_recongnition
This commit is contained in:
parent
4d80d58554
commit
96d83e0b49
|
@ -266,9 +266,10 @@ class FaceLoginView(CreateAPIView):
|
|||
from apps.hrm.services import HrmService
|
||||
base64_data = base64.urlsafe_b64decode(tran64(request.data.get('base64').replace(' ', '+')))
|
||||
ep, msg = HrmService.face_find_from_base64(base64_data)
|
||||
if ep and ep.user:
|
||||
user = ep.user
|
||||
refresh = RefreshToken.for_user(ep.user)
|
||||
if ep:
|
||||
if ep.user and ep.user.is_active and ep.user.is_deleted is False:
|
||||
user = ep.user
|
||||
refresh = RefreshToken.for_user(ep.user)
|
||||
# # 可设为在岗
|
||||
# now = timezone.now()
|
||||
# now_local = timezone.localtime()
|
||||
|
@ -286,10 +287,12 @@ class FaceLoginView(CreateAPIView):
|
|||
# if created:
|
||||
# Employee.objects.filter(user=user).update(is_atwork=True, last_check_time=now)
|
||||
|
||||
return Response({
|
||||
'refresh': str(refresh),
|
||||
'access': str(refresh.access_token),
|
||||
'username':user.username,
|
||||
'name':user.name
|
||||
})
|
||||
return Response({
|
||||
'refresh': str(refresh),
|
||||
'access': str(refresh.access_token),
|
||||
'username':user.username,
|
||||
'name':user.name
|
||||
})
|
||||
else:
|
||||
raise ParseError('账户不存在或不可用')
|
||||
raise ParseError(msg)
|
||||
|
|
|
@ -71,14 +71,15 @@ class EmployeeCreateUpdateSerializer(CustomModelSerializer):
|
|||
old_name = instance.name
|
||||
instance = super().update(instance, validated_data)
|
||||
if old_photo != instance.photo: # 如果照片有变动,需要更新人脸库
|
||||
face_data, msg = HrmService.get_facedata_from_img(settings.BASE_DIR + instance.photo)
|
||||
# 使用的是face_recongition
|
||||
face_data, msg = HrmService.get_facedata_from_img_x(settings.BASE_DIR + instance.photo)
|
||||
if face_data:
|
||||
instance.face_data = face_data
|
||||
instance.save()
|
||||
else:
|
||||
raise ParseError(msg)
|
||||
from apps.hrm.tasks import update_global_face
|
||||
update_global_face.delay()
|
||||
from apps.hrm.tasks import update_all_facedata_cache
|
||||
update_all_facedata_cache.delay()
|
||||
if instance.user and instance != old_name:
|
||||
instance.user.name = instance.name
|
||||
instance.user.save()
|
||||
|
|
|
@ -403,8 +403,8 @@ class HrmService:
|
|||
for index, value in enumerate(results):
|
||||
if value:
|
||||
# 识别成功
|
||||
user = User.objects.get(id=face_datas['users'][index])
|
||||
return user, ''
|
||||
ep = Employee.objects.get(id=face_datas['eps'][index])
|
||||
return ep, ''
|
||||
return None, '人脸未匹配,请调整位置'
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -97,14 +97,13 @@ def update_all_facedata_cache():
|
|||
"""
|
||||
更新人脸数据缓存
|
||||
"""
|
||||
facedata_queyset = Employee.objects.filter(face_data__isnull=False,
|
||||
user__is_active=True).values('user', 'face_data')
|
||||
face_users = []
|
||||
facedata_queyset = Employee.objects.filter(face_data__isnull=False).values('eps', 'face_data')
|
||||
face_eps = []
|
||||
face_datas = []
|
||||
for i in facedata_queyset:
|
||||
face_users.append(i['user'])
|
||||
face_eps.append(i['id'])
|
||||
face_datas.append(i['face_data'])
|
||||
face_data_dict = {"users": face_users, "datas": face_datas}
|
||||
face_data_dict = {"eps": face_eps, "datas": face_datas}
|
||||
cache.set('face_datas', face_data_dict)
|
||||
|
||||
|
||||
|
|
|
@ -30,4 +30,4 @@ xlwt==1.3.0
|
|||
openpyxl==3.1.0
|
||||
cron-descriptor==1.2.35
|
||||
pymysql==1.0.3
|
||||
deepface==0.0.79
|
||||
# deepface==0.0.79
|
||||
|
|
Loading…
Reference in New Issue