diff --git a/face_recognition/app/app.py b/face_recognition/app/app.py index 60691cf..636c9cf 100644 --- a/face_recognition/app/app.py +++ b/face_recognition/app/app.py @@ -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 @@ -89,6 +87,18 @@ def save_img(encoded_data, filename): img = cv2.imdecode(nparr, cv2.IMREAD_ANYCOLOR) 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: