fix: 解决face缓存时的bug
This commit is contained in:
parent
72372c3215
commit
0c2589c151
|
@ -15,7 +15,6 @@ from apps.third.dahua import dhClient
|
||||||
from apps.third.models import TDevice
|
from apps.third.models import TDevice
|
||||||
from apps.third.tapis import dhapis
|
from apps.third.tapis import dhapis
|
||||||
from apps.utils.tools import rannum, ranstr
|
from apps.utils.tools import rannum, ranstr
|
||||||
from apps.utils.face import face_find
|
|
||||||
|
|
||||||
myLogger = logging.getLogger('log')
|
myLogger = logging.getLogger('log')
|
||||||
|
|
||||||
|
@ -392,22 +391,23 @@ class HrmService:
|
||||||
return None, '识别失败,请调整位置'
|
return None, '识别失败,请调整位置'
|
||||||
|
|
||||||
# 匹配人脸库
|
# 匹配人脸库
|
||||||
face_datas = cache.get('face_datas', None)
|
face_datas = cache.get('face_datas_dlib', None) # 使用的是face_datas_dlib作为key的
|
||||||
if face_datas is None:
|
if face_datas is None:
|
||||||
from apps.hrm.tasks import update_all_facedata_cache
|
from apps.hrm.tasks import update_all_facedata_cache
|
||||||
update_all_facedata_cache()
|
update_all_facedata_cache()
|
||||||
face_datas = cache.get('face_datas')
|
face_datas = cache.get('face_datas_dlib')
|
||||||
results = face_recognition.compare_faces(face_datas['datas'],
|
results = face_recognition.compare_faces(face_datas['datas'],
|
||||||
unknown_face_encoding, tolerance=0.45)
|
unknown_face_encoding, tolerance=0.45)
|
||||||
for index, value in enumerate(results):
|
if True in results:
|
||||||
if value:
|
first_match_index = results.index(True)
|
||||||
# 识别成功
|
# 识别成功
|
||||||
ep = Employee.objects.get(id=face_datas['eps'][index])
|
ep = Employee.objects.get(id=face_datas['eps'][first_match_index])
|
||||||
return ep, ''
|
return ep, ''
|
||||||
return None, '人脸未匹配,请调整位置'
|
return None, '人脸未匹配,请调整位置'
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def face_find_from_base64(cls, base64_data):
|
def face_find_from_base64(cls, base64_data):
|
||||||
|
from apps.utils.face import face_find
|
||||||
# from deepface import DeepFace
|
# from deepface import DeepFace
|
||||||
img_name = str(uuid.uuid4())
|
img_name = str(uuid.uuid4())
|
||||||
img_path = settings.BASE_DIR +'/temp/face_' + img_name +'.jpg'
|
img_path = settings.BASE_DIR +'/temp/face_' + img_name +'.jpg'
|
||||||
|
|
|
@ -97,14 +97,14 @@ def update_all_facedata_cache():
|
||||||
"""
|
"""
|
||||||
更新人脸数据缓存
|
更新人脸数据缓存
|
||||||
"""
|
"""
|
||||||
facedata_queyset = Employee.objects.filter(face_data__dlib__isnull=False).values('id', 'face_data')
|
facedata_queyset = Employee.objects.filter(face_data__dlib__isnull=False).values('id', 'face_data__dlib')
|
||||||
face_eps = []
|
face_eps = []
|
||||||
face_datas = []
|
face_datas = []
|
||||||
for i in facedata_queyset:
|
for i in facedata_queyset:
|
||||||
face_eps.append(i['id'])
|
face_eps.append(i['id'])
|
||||||
face_datas.append(i['face_data'])
|
face_datas.append(i['face_data__dlib'])
|
||||||
face_data_dict = {"eps": face_eps, "datas": face_datas}
|
face_data_dict = {"eps": face_eps, "datas": face_datas}
|
||||||
cache.set('face_datas', face_data_dict)
|
cache.set('face_datas_dlib', face_data_dict)
|
||||||
|
|
||||||
|
|
||||||
@shared_task(base=CustomTask)
|
@shared_task(base=CustomTask)
|
||||||
|
|
Loading…
Reference in New Issue