Pass args as env
Change-Id: Iec4477b64f77f1c96bf11c2dece6c128dbf1ab04
diff --git a/person_detection/app.py b/person_detection/app.py
index 59cc966..437374e 100644
--- a/person_detection/app.py
+++ b/person_detection/app.py
@@ -3,6 +3,7 @@
SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
"""
+import os
import logging as log
import sys
import flask
@@ -20,7 +21,7 @@
def index():
"""Video streaming home page."""
global args
- devices = {str(x):"Camera "+str(x) for x in range(args.num)}
+ devices = {str(x): "Camera "+str(x) for x in range(args.num)}
log.info("{} - connected".format(flask.request.remote_addr))
return flask.render_template('index.html', devices=devices)
@@ -47,64 +48,44 @@
return int(name)
+
+
def build_argparser():
parser = ArgumentParser(add_help=False)
args = parser.add_argument_group('Options')
- args.add_argument('-h', '--help',
- action = 'help',
- default = SUPPRESS,
- help = 'Show this help message and exit.')
+ args.add_argument('-h', '--help', action='help', default=SUPPRESS,
+ help='Show this help message and exit.')
args.add_argument("-m", "--model",
- help = "Required. Path to an .xml file with a trained model.",
- required = True,
- type = str)
- args.add_argument("-i", "--input",
- help = "Path to video file or image. 'cam' for capturing video stream from camera",
- default = "gstreamer",
- type = str)
- args.add_argument("-pt", "--prob_threshold",
- help = "Optional. Probability threshold for detections filtering",
- default = 0.75,
- type = float)
- args.add_argument("--noroc",
- action = 'store_true',
- help = "No ROC")
- args.add_argument("--key",
- help = "ROC api key",
- type = str)
- args.add_argument("--url",
- help = "ROC url",
- type = str)
- args.add_argument("--keycloak",
- help = "Keycloak url",
- type = str)
- args.add_argument("--enterprise",
- help = "Enterprise ID",
- type = str)
- args.add_argument("--site",
- help = "Site ID",
- type = str)
- args.add_argument("--user",
- help = "ROC username",
- type = str)
- args.add_argument("--password",
- help = "ROC password",
- type = str)
- args.add_argument("--num",
- help="Number of camera devices",
- default=1,
- type=int)
- args.add_argument("--mbrlow",
- help="Low range of MBR",
- default=7000000,
- type=int)
- args.add_argument("--mbrhigh",
- help="High range of MBR",
- default=10000000,
- type=int)
- args.add_argument("--devicegroup",
- help="Camera device group",
+ help="Path to model", required=True,
type=str)
+ args.add_argument("-i", "--input",
+ help="Video input", default="gstreamer", type=str)
+ args.add_argument("-pt", "--prob_threshold",
+ help="Probability threshold for detection",
+ default=0.75, type=float)
+ args.add_argument("--noroc", action='store_true', help="No ROC")
+ args.add_argument("--key", help="ROC api key", type=str)
+ args.add_argument("--url", default=config.ROCURL,
+ help="ROC url", type=str)
+ args.add_argument("--keycloak", default=config.KEYCLOAKURL,
+ help="Keycloak url", type=str)
+ args.add_argument("--enterprise", default=config.ENTERPRISE,
+ help="Enterprise ID", type=str)
+ args.add_argument("--site", default=config.SITE,
+ help="Site ID", type=str)
+ args.add_argument("--devicegroup", default=config.DEVICEGROUP,
+ help="Camera device group", type=str)
+ args.add_argument("--user", default=config.ROCUSER,
+ help="ROC username", type=str)
+ args.add_argument("--password", default=config.ROCPASSWORD,
+ help="ROC password", type=str)
+ args.add_argument("--num", default=config.NUMDEVICES,
+ help="Number of camera devices",
+ type=int)
+ args.add_argument("--mbrlow", help="Low range of MBR", default=7000000,
+ type=int)
+ args.add_argument("--mbrhigh", help="High range of MBR", default=10000000,
+ type=int)
return parser
@@ -123,13 +104,15 @@
key = args.key
if key is None:
if args.user is not None and args.password is not None:
- roc = Roc(args.url, args.keycloak, args.user, args.password, args.enterprise, args.site)
+ roc = Roc(args.url, args.keycloak, args.user, args.password,
+ args.enterprise, args.site)
key = roc.get_key()
else:
log.error("Either key or user/password required")
sys.exit()
- log.info("Device group:{} mbr:{}(low)".format(args.devicegroup, args.mbrlow))
+ log.info("Device group:{} mbr:{}(low)".format(args.devicegroup,
+ args.mbrlow))
roc.set_mbr(args.devicegroup, args.mbrlow)
app.run(host='0.0.0.0', debug=True)
diff --git a/person_detection/config.py b/person_detection/config.py
index f1cb46e..adf48ee 100644
--- a/person_detection/config.py
+++ b/person_detection/config.py
@@ -3,4 +3,16 @@
SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
"""
+import os
+
cameras = {"0": "Camera 0", "1": "Camera 1", "2": "Camera 2"}
+
+ROCURL = os.environ.get("ROCURL")
+KEYCLOAKURL = os.environ.get("KEYCLOAKURL")
+ENTERPRISE = os.environ.get("ENTERPRISE")
+SITE = os.environ.get("SITE")
+DEVICEGROUP = os.environ.get("DEVICEGROUP")
+ROCUSER = os.environ.get("ROCUSER")
+ROCPASSWORD = os.environ.get("ROCPASSWORD")
+NUMDEVICES = os.environ.get("NUMDEVICES", 1)
+