diff --git a/face_recognition/app/app.py b/face_recognition/app/app.py index 40549e4..c5e9d81 100644 --- a/face_recognition/app/app.py +++ b/face_recognition/app/app.py @@ -35,27 +35,21 @@ def new_user_id(): with open('/tmp/demo_object.pkl', 'wb') as f: pickle.dump(demo_object, f) minioClient.fput_object('users', str(id), '/tmp/demo_object.pkl') - return jsonify({'id':id, 'id2':'test2'}) + return jsonify({'id':id}) @app.route('/init_face') #call like https://face.sguba.de/init_face?id=123&encoded_string=abc def new_face(): id = request.args.get('id', None) img = request.args.get('encoded_string', None) - img += "=" * ((4 - len(img) % 4) % 4) - img = bytes(img, encoding='utf-8') - #print(img, flush=True) - #imgdata = base64.b64decode(img) - #with open('/tmp/'+str(id), 'wb') as file: - # file.write(bytearray(imgdata)) - save_img(img, '/tmp/'+str(id)+'.jpg') - #to debug send img - minioClient.fput_object('users', str(id)+'.jpg', '/tmp/'+str(id)+'.jpg') - face = face_recognition.load_image_file('/tmp/'+str(id)+'.jpg') + temporary_img_path = '/tmp/'+str(id)+'.jpg' + temporary_pkl_path = '/tmp/'+str(id)+'.pkl' + save_img(img, temporary_img_path) + face = face_recognition.load_image_file(temporary_img_path) face_encoding = face_recognition.face_encodings(face)[0] - with open('/tmp/'+str(id)+'.pkl', 'wb') as file: + with open(temporary_pkl_path, 'wb') as file: pickle.dump(face_encoding, file) - minioClient.fput_object('users', str(id), '/tmp/'+str(id)+'.pkl') + minioClient.fput_object('users', str(id), temporary_pkl_path) return jsonify({'id':id}) @app.route('/check_face') @@ -63,13 +57,13 @@ def new_face(): def check_face(): id = request.args.get('id', None) img = request.args.get('encoded_string', None) - imgdata = base64.b64decode(img) - with open('/tmp/'+str(id), 'wb') as file: - file.write(imgdata) - face = face_recognition.load_image_file('/tmp/'+str(id)) + temporary_img_path = '/tmp/'+str(id)+'.jpg' + temporary_pkl_path = '/tmp/'+str(id)+'.pkl' + save_img(img, temporary_img_path) + face = face_recognition.load_image_file(temporary_img_path) face_encoding = face_recognition.face_encodings(face)[0] - minioClient.fget_object('users', str(id), '/tmp/'+str(id)) - with open('/tmp/'+str(id), 'rb') as file: + minioClient.fget_object('users', str(id), temporary_pkl_path) + with open(temporary_pkl_path, 'rb') as file: face2_encoding = pickle.load(file) return jsonify({'result':face_recognition.compare_faces([face_encoding], face2_encoding)}) @@ -87,6 +81,8 @@ def check_id(id): return known def save_img(encoded_data, filename): + encoded_data += "=" * ((4 - len(encoded_data) % 4) % 4) + encoded_data = bytes(encoded_data, encoding='utf-8') nparr = np.fromstring(base64.urlsafe_b64decode(encoded_data), np.uint8) img = cv2.imdecode(nparr, cv2.IMREAD_ANYCOLOR) img = imutils.rotate(img, 90) @@ -101,14 +97,6 @@ def setup(): pass except ResponseError as err: raise - try: - minioClient.make_bucket("uploads") - except BucketAlreadyOwnedByYou as err: - pass - except BucketAlreadyExists as err: - pass - except ResponseError as err: - raise if __name__ == '__main__':