Update 'face_recognition/app/app.py'
This commit is contained in:
parent
d9ec192487
commit
5645d64107
@ -45,14 +45,12 @@ def new_face():
|
||||
temporary_img_path = '/tmp/'+str(id)+'.jpg'
|
||||
temporary_pkl_path = '/tmp/'+str(id)+'.pkl'
|
||||
save_img(img, temporary_img_path)
|
||||
#new method img_path to encoding, inkl error handling
|
||||
face = face_recognition.load_image_file(temporary_img_path)
|
||||
face_encoding = face_recognition.face_encodings(face)[0]
|
||||
with open(temporary_pkl_path, 'wb') as file:
|
||||
pickle.dump(face_encoding, file)
|
||||
minioClient.fput_object('users', str(id), temporary_pkl_path)
|
||||
#return boolean if setup was succesful
|
||||
return jsonify({'id':id})
|
||||
face_encoding_response = encode_face(temporary_img_path)
|
||||
if face_encoding_response['success']==True:
|
||||
with open(temporary_pkl_path, 'wb') as file:
|
||||
pickle.dump(face_encoding, file)
|
||||
minioClient.fput_object('users', str(id), temporary_pkl_path)
|
||||
return jsonify({'success':face_encoding_response['success']})
|
||||
|
||||
@app.route('/check_face')
|
||||
#call like https://face.sguba.de/check_face?id=123&encoded_string=abc
|
||||
@ -90,6 +88,18 @@ def save_img(encoded_data, filename):
|
||||
img = imutils.rotate(img, 90)
|
||||
return cv2.imwrite(filename, img)
|
||||
|
||||
def encode_face(path):
|
||||
success = None
|
||||
face = face_recognition.load_image_file(path)
|
||||
face_encoding = face_recognition.face_encodings(face)
|
||||
if len(face_encoding)==0:
|
||||
success = False
|
||||
response = {'success':success, 'encoding':None}
|
||||
else:
|
||||
success = True
|
||||
response = {'success':success, 'encoding':face_encoding[0]}
|
||||
return response
|
||||
|
||||
def setup():
|
||||
try:
|
||||
minioClient.make_bucket("users")
|
||||
|
Loading…
Reference in New Issue
Block a user