调整人脸识别
This commit is contained in:
parent
54d4bca2ea
commit
b61212980b
|
@ -17,36 +17,37 @@ class HRMService:
|
||||||
f.write(base64_data)
|
f.write(base64_data)
|
||||||
try:
|
try:
|
||||||
unknown_picture = face_recognition.load_image_file(filepath)
|
unknown_picture = face_recognition.load_image_file(filepath)
|
||||||
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
|
unknown_face_encoding = face_recognition.face_encodings(unknown_picture, num_jitters=3)[0]
|
||||||
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')
|
||||||
face_users = cache.get('face_users')
|
|
||||||
if face_datas is None:
|
if face_datas is None:
|
||||||
update_all_user_facedata_cache()
|
update_all_user_facedata_cache()
|
||||||
|
face_datas = cache.get('face_datas')
|
||||||
|
face_users = cache.get('face_users')
|
||||||
try:
|
try:
|
||||||
results = face_recognition.compare_faces(face_datas,
|
results = face_recognition.compare_faces(face_datas,
|
||||||
unknown_face_encoding, tolerance=0.49)
|
unknown_face_encoding, tolerance=0.4)
|
||||||
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):
|
||||||
try:
|
try:
|
||||||
photo_path = settings.BASE_DIR + img_path
|
photo_path = settings.BASE_DIR + img_path
|
||||||
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, num_jitters=10)[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, '人脸数据获取失败请重新上传图片'
|
Loading…
Reference in New Issue