From 70616b7f94f33f9b37838fee3a5c65746cb19c35 Mon Sep 17 00:00:00 2001 From: Askill Date: Wed, 29 Apr 2020 22:00:17 +0200 Subject: [PATCH] actual image is now processed --- application/endpoints.py | 16 ++++++++-------- application/face_rec.py | 15 +++++++++------ run.py | 3 ++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/application/endpoints.py b/application/endpoints.py index de99ee6..feeb786 100644 --- a/application/endpoints.py +++ b/application/endpoints.py @@ -37,7 +37,7 @@ class PersonList(Resource): arr = [] for x in data: arr.append(x.serialize()) - + session.close() return flask.make_response(flask.jsonify({'data': arr}), 201) except Exception as e: @@ -46,15 +46,17 @@ class PersonList(Resource): def get(self, id = None): """ """ + session = Session() try: parser = reqparse.RequestParser() parser.add_argument('useFace', type=bool, required=False) args = parser.parse_args() - session = Session() + # this indicates that the captured face should be use for identification / validation if "useFace" in args and args["useFace"]: + Camera().post() if id is not None: # validate data = list(session.query(Person).filter_by(person_id=id))[0].serialize() @@ -82,9 +84,11 @@ class PersonList(Resource): arr = [] for x in data: arr.append(x.serialize()) + session.close() return flask.make_response(flask.jsonify({'data': arr}), 200) except Exception as e: + session.close() print("error: -", e) return flask.make_response(flask.jsonify({'error': str(e)}), 400) @@ -106,7 +110,7 @@ class PersonList(Resource): session = Session() data = session.query(Person).filter_by(person_id=id).delete() session.commit() - + session.close() return flask.make_response(flask.jsonify({'data': data}), 204) except Exception as e: @@ -114,10 +118,7 @@ class PersonList(Resource): return flask.make_response(flask.jsonify({'error': str(e)}), 404) class Camera(Resource): - - - - # provides th function used for the live streams + # provides the function used for the live streams class VideoCamera(object): """Video stream object""" url = "http://192.168.178.56:8080/video" @@ -132,7 +133,6 @@ class Camera(Resource): ret, jpeg = cv2.imencode(ending, image) return jpeg - def gen(self, camera): """Video streaming generator function.""" while True: diff --git a/application/face_rec.py b/application/face_rec.py index b5b5fd3..2b6a8b7 100644 --- a/application/face_rec.py +++ b/application/face_rec.py @@ -54,15 +54,18 @@ def initFaceRec(): known_faces.append(encoding) known_names.append(name) -def identifyFace(imgage): - print('Processing unknown faces...') - image = face_recognition.load_image_file('C:/Users/ofjok/Desktop/1.png') + session.close() +def identifyFace(image): + print('Processing unknown faces...') + #image = face_recognition.load_image_file('C:/Users/ofjok/Desktop/1.png') + nparr = np.fromstring(base64.b64decode(image), np.uint8) + image = cv2.imdecode(nparr, cv2.IMREAD_COLOR) + #image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) locations = face_recognition.face_locations(image, model=MODEL) encodings = face_recognition.face_encodings(image, locations) - image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) res = {} @@ -80,5 +83,5 @@ def identifyFace(imgage): return res -initFaceRec() -identifyFace("") \ No newline at end of file + +#identifyFace("") \ No newline at end of file diff --git a/run.py b/run.py index dbdfb23..82a3b93 100644 --- a/run.py +++ b/run.py @@ -1,5 +1,6 @@ from application import app - +from application.face_rec import initFaceRec +initFaceRec() app.run(host="localhost", port='5001', debug=True)