face tiaozheng
This commit is contained in:
parent
62ca3cefbd
commit
1be0ec0fd8
|
@ -17,7 +17,7 @@ class HRMService:
|
|||
f.write(base64_data)
|
||||
try:
|
||||
unknown_picture = face_recognition.load_image_file(filepath)
|
||||
unknown_face_encoding = face_recognition.face_encodings(unknown_picture, num_jitters=3)[0]
|
||||
unknown_face_encoding = face_recognition.face_encodings(unknown_picture, num_jitters=2)[0]
|
||||
os.remove(filepath)
|
||||
except:
|
||||
os.remove(filepath)
|
||||
|
@ -29,24 +29,21 @@ class HRMService:
|
|||
update_all_user_facedata_cache()
|
||||
face_datas = cache.get('face_datas')
|
||||
face_users = cache.get('face_users')
|
||||
try:
|
||||
results = face_recognition.compare_faces(face_datas,
|
||||
unknown_face_encoding, tolerance=0.45)
|
||||
except:
|
||||
return None, '人脸未匹配1'
|
||||
results = face_recognition.compare_faces(face_datas,
|
||||
unknown_face_encoding, tolerance=0.45)
|
||||
for index, value in enumerate(results):
|
||||
if value:
|
||||
# 识别成功
|
||||
user = User.objects.get(id=face_users[index])
|
||||
return user, ''
|
||||
return None, '人脸未匹配2'
|
||||
return None, '人脸未匹配'
|
||||
|
||||
@classmethod
|
||||
def get_facedata_from_img(cls, img_path):
|
||||
try:
|
||||
photo_path = settings.BASE_DIR + img_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=2)[0]
|
||||
face_data_list = my_face_encoding.tolist()
|
||||
return face_data_list, ''
|
||||
except:
|
||||
|
|
Loading…
Reference in New Issue