From e7198a5e2be61d9e204de0ccc015e7d6ca46d55d Mon Sep 17 00:00:00 2001 From: fabrice Date: Mon, 24 Jun 2019 12:28:17 +0000 Subject: [PATCH] Update 'face_recognition/app/app.py' --- face_recognition/app/app.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/face_recognition/app/app.py b/face_recognition/app/app.py index 285fc19..518e553 100644 --- a/face_recognition/app/app.py +++ b/face_recognition/app/app.py @@ -7,6 +7,8 @@ import pickle import face_recognition from werkzeug.datastructures import ImmutableMultiDict import base64 +import cv2 +import numpy as np app = Flask(__name__) minioClient = Minio('minio:9000', access_key=os.environ['s3-name'], secret_key=os.environ['s3-password'], secure=False) @@ -39,11 +41,13 @@ def new_user_id(): def new_face(): id = request.args.get('id', None) img = request.args.get('encoded_string', None) - print(img, flush=True) - imgdata = base64.b64decode(img) - with open('/tmp/'+str(id), 'wb') as file: - file.write(bytearray(imgdata)) - minioClient.fput_object('users', str(id)+'.jpg', '/tmp/'+str(id)) + #print(img, flush=True) + #imgdata = base64.b64decode(img) + #with open('/tmp/'+str(id), 'wb') as file: + # file.write(bytearray(imgdata)) + save_img(encoded_string, '/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)) face_encoding = face_recognition.face_encodings(face)[0] with open('/tmp/'+str(id)+'.pkl', 'wb') as file: @@ -78,6 +82,11 @@ def check_id(id): else: pass return known + +def save_img(encoded_data, filename): + nparr = np.fromstring(base64.b64decode(encoded_data), np.uint8) + img = cv2.imdecode(nparr, cv2.IMREAD_ANYCOLOR) + return cv2.imwrite(filename, img) def setup(): try: