Update 'face_recognition/app/app.py'
This commit is contained in:
parent
c94f666bec
commit
e7198a5e2b
@ -7,6 +7,8 @@ import pickle
|
|||||||
import face_recognition
|
import face_recognition
|
||||||
from werkzeug.datastructures import ImmutableMultiDict
|
from werkzeug.datastructures import ImmutableMultiDict
|
||||||
import base64
|
import base64
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
minioClient = Minio('minio:9000', access_key=os.environ['s3-name'], secret_key=os.environ['s3-password'], secure=False)
|
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():
|
def new_face():
|
||||||
id = request.args.get('id', None)
|
id = request.args.get('id', None)
|
||||||
img = request.args.get('encoded_string', None)
|
img = request.args.get('encoded_string', None)
|
||||||
print(img, flush=True)
|
#print(img, flush=True)
|
||||||
imgdata = base64.b64decode(img)
|
#imgdata = base64.b64decode(img)
|
||||||
with open('/tmp/'+str(id), 'wb') as file:
|
#with open('/tmp/'+str(id), 'wb') as file:
|
||||||
file.write(bytearray(imgdata))
|
# file.write(bytearray(imgdata))
|
||||||
minioClient.fput_object('users', str(id)+'.jpg', '/tmp/'+str(id))
|
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 = face_recognition.load_image_file('/tmp/'+str(id))
|
||||||
face_encoding = face_recognition.face_encodings(face)[0]
|
face_encoding = face_recognition.face_encodings(face)[0]
|
||||||
with open('/tmp/'+str(id)+'.pkl', 'wb') as file:
|
with open('/tmp/'+str(id)+'.pkl', 'wb') as file:
|
||||||
@ -79,6 +83,11 @@ def check_id(id):
|
|||||||
pass
|
pass
|
||||||
return known
|
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():
|
def setup():
|
||||||
try:
|
try:
|
||||||
minioClient.make_bucket("users")
|
minioClient.make_bucket("users")
|
||||||
|
Loading…
Reference in New Issue
Block a user