Change rendering and fix minor bug
Change-Id: Ibc5f1b6785b71d18940f9e8868f8b4dbb2ba4e5f
diff --git a/person_detection/app.py b/person_detection/app.py
index 240c450..b1e9b2d 100644
--- a/person_detection/app.py
+++ b/person_detection/app.py
@@ -5,21 +5,25 @@
"""
from importlib import import_module
import os
-from flask import Flask, render_template, Response
+import logging as log
+import sys
+import flask
from argparse import ArgumentParser, SUPPRESS
import config
from person_detection import Camera
+import roc
-app = Flask(__name__)
+app = flask.Flask(__name__)
@app.route('/')
def index():
global cameras
"""Video streaming home page."""
- return render_template('index.html', devices=config.cameras)
+ log.info("{} - connected".format(flask.request.remote_addr))
+ return flask.render_template('index.html', devices=config.cameras)
def gen(camera):
"""Video streaming generator function."""
@@ -32,8 +36,9 @@
def video_feed(device):
"""Video streaming route. Put this in the src attribute of an img tag."""
global args
- camera = Camera(device, args)
- return Response(gen(camera),
+ log.debug("{} - video feed {}".format(flask.request.remote_addr, device))
+ camera = Camera(device, flask.request.remote_addr, args)
+ return flask.Response(gen(camera),
mimetype='multipart/x-mixed-replace; boundary=frame')
def name_to_port(name):
@@ -59,11 +64,10 @@
default = 0.75,
type = float)
args.add_argument("--noroc",
- action = 'store_false',
+ action = 'store_true',
help = "No ROC")
args.add_argument("--key",
help = "ROC api key",
- required = True,
type = str)
args.add_argument("--mbrlow",
help = "Low range of MBR",
@@ -82,5 +86,9 @@
if __name__ == '__main__':
+ log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.DEBUG, stream=sys.stdout)
+ log.debug("Starting person detection app")
args = build_argparser().parse_args()
+ if not args.noroc:
+ roc.set_mbr(args.key, args.devicegroup, args.mbrlow)
app.run(host='0.0.0.0', debug=True)
diff --git a/person_detection/base_camera.py b/person_detection/base_camera.py
index e97dca2..b8fa47c 100644
--- a/person_detection/base_camera.py
+++ b/person_detection/base_camera.py
@@ -39,6 +39,7 @@
BaseCamera.process[self.device].start()
# wait until frames are available
_ = self.get_frame()
+ log.info("Start camera {} feed to {}".format(self.device, self.client))
def get_frame(self):
"""Return the current camera frame."""
@@ -65,7 +66,7 @@
BaseCamera.activity_counter.value += 1
BaseCamera.lock.release()
self.set_resolution_high()
- if self.noroc is True:
+ if not self.noroc:
roc.set_mbr(self.key, self.devicegroup, self.mbrhigh)
self.detected = True
self.start_timer()
@@ -78,7 +79,7 @@
if BaseCamera.activity_counter.value <= 0:
BaseCamera.activity_counter.value = 0
self.set_resolution_low()
- if self.noroc is True:
+ if not self.noroc:
roc.set_mbr(self.key, self.devicegroup, self.mbrlow)
BaseCamera.lock.release()
diff --git a/person_detection/person_detection.py b/person_detection/person_detection.py
index f7984af..86ebaa5 100644
--- a/person_detection/person_detection.py
+++ b/person_detection/person_detection.py
@@ -8,7 +8,6 @@
from collections import namedtuple
import logging as log
import os
-import sys
from argparse import ArgumentParser, SUPPRESS
from imutils import build_montages
@@ -21,15 +20,13 @@
class Camera(BaseCamera):
Shape = namedtuple('Shape', ['n','c','h','w'])
- def __init__(self, device, args):
- log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
-
+ def __init__(self, device, client, args):
self.model_xml = args.model
self.input = args.input
self.prob_threshold = args.prob_threshold
self.is_async_mode = True
self.device = device
-
+ self.client = client
super(Camera, self).__init__(device, args.key, args.mbrlow, args.mbrhigh, args.devicegroup, args.noroc)
def __del__(self):
diff --git a/person_detection/templates/index.html b/person_detection/templates/index.html
index 0cb83e7..4acf6d7 100644
--- a/person_detection/templates/index.html
+++ b/person_detection/templates/index.html
@@ -12,7 +12,7 @@
</div>
<div class="row">
{% for x, y in devices.items() %}
- <div class="col-6">
+ <div class="col-12">
<div class="card">
<img src="{{ url_for('video_feed', device=x) }}" class="card-img-top" alt="...">
<div class="card-body">