diff --git a/application/__init__.py b/application/__init__.py index 4a2b19b..3e471ed 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -12,7 +12,9 @@ app = Flask(__name__) api = Api(app, version='1', contact={"name":""}, license={"name":"Online Dienst Dokumentation"}, api_spec_url='/api/swagger') + api.add_resource(endpoints.PersonList,'/api/v1/person/', '/api/v1/person/') +api.add_resource(endpoints.Camera,'/api/v1/camera/', "/api/v1/camera/") @app.route("/") def index(): diff --git a/application/db.py b/application/db.py index 7b12462..1fbc096 100644 --- a/application/db.py +++ b/application/db.py @@ -12,10 +12,14 @@ connection = engine.connect() Base = declarative_base() Session = sessionmaker(bind=engine) +lastImage = "" + class Gender(enum.Enum): - other = "other" - male = "male" - female = "female" + other = "Other" + male = "Male" + female = "Female" + def __str__(self): + return str(self.value) class Person(Base): __tablename__ = "person" @@ -44,7 +48,7 @@ class Person(Base): "fname": self.fname, "lname": self.lname, "yob": self.yob, - "gender": self.gender, + "gender": str(self.gender), "face": face, "fingerprints": prints } diff --git a/application/endpoints.py b/application/endpoints.py index 00e683f..a8228ff 100644 --- a/application/endpoints.py +++ b/application/endpoints.py @@ -3,8 +3,10 @@ import flask import requests import application.config as config import json +import cv2 from application.db import Session, Person, Fingerprint +lastImage = "" class PersonList(Resource): def post(self, id = None): @@ -41,7 +43,18 @@ class PersonList(Resource): def get(self, id = None): """ """ try: + parser = reqparse.RequestParser() + parser.add_argument('useFace', type=bool, required=False) + args = parser.parse_args() + session = Session() + + if "useFace" in args and args["useFace"]: + + # replace by Biometric function + data = list(session.query(Person).all())[1].serialize() + return flask.make_response(flask.jsonify({'data': data}), 200) + if id is None: data = list(session.query(Person).all()) else: @@ -80,3 +93,51 @@ class PersonList(Resource): print("error: -", e) return flask.make_response(flask.jsonify({'error': str(e)}), 404) +class Camera(Resource): + + + + # provides th function used for the live streams + class VideoCamera(object): + """Video stream object""" + url = "http://131.95.3.162/mjpg/video.mjpg" + def __init__(self): + self.video = cv2.VideoCapture(self.url) + + def __del__(self): + self.video.release() + + def get_frame(self, ending): + success, image = self.video.read() + ret, jpeg = cv2.imencode(ending, image) + return jpeg.tobytes() + + + def gen(self, camera): + """Video streaming generator function.""" + while True: + frame = camera.get_frame('.jpg') + yield (b'--frame\r\n' + b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') + + def get(self, type = "stream"): + global lastImage + try: + if type == "stream": + return flask.Response(self.gen(self.VideoCamera()), mimetype='multipart/x-mixed-replace; boundary=frame') + + elif type == "still": + return flask.Response(lastImage, mimetype='image/jpeg') + + return flask.make_response(flask.jsonify({'error': "No idea how you got here"}), 404) + except Exception as e: + print("error: -", e) + return flask.make_response(flask.jsonify({'error': str(e)}), 404) + + def post(self): + global lastImage + try: + lastImage = self.VideoCamera().get_frame('.png') + except Exception as e: + print("error: -", e) + return flask.make_response(flask.jsonify({'error': str(e)}), 404) \ No newline at end of file diff --git a/application/static/coms.js b/application/static/coms.js new file mode 100644 index 0000000..71e1d85 --- /dev/null +++ b/application/static/coms.js @@ -0,0 +1,49 @@ +function getJSON(url, callback) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.responseType = 'json'; + xhr.onload = function () { + var status = xhr.status; + if (status < 400) { + callback(null, xhr.response); + } else { + console.log("failed getting"); + console.log(status); + } + }; + xhr.send(); +}; + +function putJSON(url, data, callback) { + var xhr = new XMLHttpRequest(); + xhr.open('PUT', url, true); + xhr.responseType = 'json'; + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.onload = function () { + var status = xhr.status; + if (status < 400) { + callback(null, xhr.response); + } else { + console.log("failed posting"); + console.log(status); + } + }; + xhr.send(data); +}; + +function postJSON(url, data, callback) { + var xhr = new XMLHttpRequest(); + xhr.open('POST', url, true); + xhr.responseType = 'json'; + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.onload = function () { + var status = xhr.status; + if (status < 400) { + callback(null, xhr.response); + } else { + console.log("failed posting"); + console.log(status); + } + }; + xhr.send(data); +}; \ No newline at end of file diff --git a/application/static/main.css b/application/static/main.css index b070ae4..ff65f29 100644 --- a/application/static/main.css +++ b/application/static/main.css @@ -15,13 +15,18 @@ left: -50%; } - +.navButton{ + padding-left: 1rem; + padding-right: 1rem; + margin-right: 0.5rem; +} #main{ width: 65rem; height: 38rem; position: relative; top: 10rem; left: -50%; + display: block; } @@ -46,4 +51,34 @@ .card-text{ padding: 0; height: 0; +} + +#middle-left{ + float: left; +} +#middle-right{ + float:right; +} +.middle{ + margin: 0rem 2rem 0 2rem; + height: 100%; + width: 40%; + display: block; +} + +#image-left{ + width:100%; + padding: 1rem; +} +#image-right{ + width:100%; + padding: 1rem; +} + +.heroInfo{ + padding: 1rem; +} + +.middle-controls{ + margin-right: 1rem; } \ No newline at end of file diff --git a/application/static/main.js b/application/static/main.js index ae79edb..1835318 100644 --- a/application/static/main.js +++ b/application/static/main.js @@ -1,70 +1,142 @@ rootKontext = "" +selected = null +var ml = document.getElementById('middle-left'); +var mr = document.getElementById('middle-right'); +personData = {} -function getJSON(url, callback) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', url, true); - xhr.responseType = 'json'; - xhr.onload = function () { - var status = xhr.status; - if (status < 400) { - callback(null, xhr.response); - } else { - console.log("failed getting"); - console.log(status); + +function focusNav(id) { + focusedID = id; + $(id).addClass('btn-primary').siblings().removeClass('btn-primary') + //$(id).removeClass('active').siblings().removeClass('active') +} + +function focusPerson(id) { + selected = id; + $("#person" + id).removeClass('border-light').siblings().addClass('border-light') + $("#person" + id).addClass('border-success').siblings().removeClass('border-success') + renderPersonRight() +} + + + +function loadPersonList(data) { + console.log(data) + data = data["data"] + let el = document.getElementById('list'); + data.forEach(function (item) { + string = ` +
+
+

${item["fname"]} ${item["lname"]}

+
${item["timestamp"]}
+ +

+ +

+ Gender: ${item["gender"]}
+ YoB: ${item["yob"]}
+ Available FP: ${item["fingerprints"].length}
+
+ +

+
+
+ ` + el.innerHTML += string; + }) +} + +function snapShot(){ + postJSON(rootKontext + "/api/v1/camera/", {}, + function (error, data) { + document.getElementById('image-left').src = rootKontext + "/api/v1/camera/still"; } - }; - xhr.send(); -}; + ); +} -function putJSON(url, data, callback) { - var xhr = new XMLHttpRequest(); - xhr.open('PUT', url, true); - xhr.responseType = 'json'; - xhr.setRequestHeader('Content-Type', 'application/json'); - xhr.onload = function () { - var status = xhr.status; - if (status < 400) { - callback(null, xhr.response); - } else { - console.log("failed posting"); - console.log(status); +function renderPersonRight(data){ + string = ` + + +

+ Gender: ${data["gender"]}
+ YoB: ${data["yob"]}
+ Available FP: ${data["fingerprints"].length}
+ + ` + mr.innerHTML = string; +} + +function identify(){ + snapShot() + getJSON(rootKontext + "/api/v1/person/?useFace=True", + function (error, data) { + data = data["data"] + renderPersonRight(data) } - }; - xhr.send(data); -}; + ); +} +function validate(){ + snapShot() + getJSON(rootKontext + "/api/v1/person/?useFace=True&?validateId="+selected, + function (error, data) { + data = data["data"] + renderPersonRight(data) + } + ); +} + +function renderValidate(){ + string = ` + + + + + ` + ml.innerHTML = string; +} + +function renderChange(){ + console.log("change") +} +function renderEnrole(){ + console.log("enrole") +} +function renderIdentify(){ + string = ` + + + + + ` + ml.innerHTML = string; +} + + +function loadStream() { + string = ` + + ` + ml.innerHTML += string; + + string = ` + + ` + mr.innerHTML += string; +} function loadData() { getJSON(rootKontext + "/api/v1/person/", function (error, data) { - console.log(data) - data = data["data"] - let el = document.getElementById('list'); - data.forEach(function (item) { - string = ` -
-
-

${item["fname"]} ${item["lname"]}

-
${item["timestamp"]}
- -

- -

- ${item["gender"]}
- ${item["yob"]}
- ${item["fingerprints"].length}
-
- -

-
-
- ` - el.innerHTML += string; - }) - - - + ml = document.getElementById('middle-left'); + mr = document.getElementById('middle-right'); + personData = data + loadPersonList(data) + renderIdentify() } ); -} \ No newline at end of file +} + diff --git a/application/static/render.js b/application/static/render.js new file mode 100644 index 0000000..b842845 --- /dev/null +++ b/application/static/render.js @@ -0,0 +1,25 @@ +function renderValidate(){ + string = ` + + + + + ` + ml.innerHTML = string; +} + +function renderChange(){ + console.log("change") +} +function renderEnrole(){ + console.log("enrole") +} +function renderIdentify(){ + string = ` + + + + + ` + ml.innerHTML = string; +} \ No newline at end of file diff --git a/application/templates/index.html b/application/templates/index.html index 41bddff..43c5bfc 100644 --- a/application/templates/index.html +++ b/application/templates/index.html @@ -21,6 +21,7 @@ + @@ -28,26 +29,25 @@
+
- hi + +
+
+ + +
+
diff --git a/run.py b/run.py index 7224a78..61ef917 100644 --- a/run.py +++ b/run.py @@ -1,5 +1,5 @@ from application import app -app.run(host="localhost",port='10024', debug=True) +app.run(host="localhost", port='5001', debug=True) diff --git a/test.sqlite b/test.sqlite index 43da940..35f6d66 100644 Binary files a/test.sqlite and b/test.sqlite differ