Idle mode
Change-Id: I43f80aab51ae01e544bda6ffb9fb7990d359564d
diff --git a/person_detection/app.py b/person_detection/app.py
index 443fbde..5cf454b 100644
--- a/person_detection/app.py
+++ b/person_detection/app.py
@@ -65,6 +65,7 @@
args.add_argument("--labels", help="Optional. Path to labels mapping file", default=None, type=str)
args.add_argument("-pt", "--prob_threshold", help="Optional. Probability threshold for detections filtering",
default=0.5, type=float)
+ args.add_argument("--idle", action='store_true', help="Idle if no clients connected")
return parser
diff --git a/person_detection/base_camera.py b/person_detection/base_camera.py
index 88a1e0e..90a2474 100644
--- a/person_detection/base_camera.py
+++ b/person_detection/base_camera.py
@@ -56,10 +56,12 @@
frame = {} # current frame is stored here by background thread
last_access = {} # time of last client access to the camera
event = {}
+ idle = False # if True, stops thread if no client connected
- def __init__(self, device=None):
+ def __init__(self, device=None, idle=False):
"""Start the background camera thread if it isn't running yet."""
self.device = device
+ self.idle = idle
BaseCamera.event[self.device] = CameraEvent()
if self.device not in BaseCamera.thread:
BaseCamera.thread[self.device] = None
@@ -96,10 +98,12 @@
BaseCamera.event[device].set() # send signal to clients
time.sleep(0)
- # if there hasn't been any clients asking for frames in
- # the last 10 seconds then stop the thread
- if time.time() - BaseCamera.last_access[device] > 10:
- frames_iterator.close()
- print('Stopping camera thread due to inactivity.')
- break
+ if self.idle:
+ # if there hasn't been any clients asking for frames in
+ # the last 10 seconds then stop the thread
+ if time.time() - BaseCamera.last_access[device] > 10:
+ frames_iterator.close()
+ print('Stopping camera thread due to inactivity.')
+ break
+
BaseCamera.thread[device] = None
diff --git a/person_detection/person_detection.py b/person_detection/person_detection.py
index 3d1fe80..29aef27 100644
--- a/person_detection/person_detection.py
+++ b/person_detection/person_detection.py
@@ -15,6 +15,7 @@
from openvino.inference_engine import IECore
from base_camera import BaseCamera
+DEFAULT_PROB_THRESH = 0.5
def build_argparser():
parser = ArgumentParser(add_help=False)
@@ -35,13 +36,14 @@
"Default value is CPU", default="CPU", type=str)
args.add_argument("--labels", help="Optional. Path to labels mapping file", default=None, type=str)
args.add_argument("-pt", "--prob_threshold", help="Optional. Probability threshold for detections filtering",
- default=0.5, type=float)
+ default=DEFAULT_PROB_THRESH, type=float)
args.add_argument("-ns", help='No show output', action='store_true')
return parser
class Camera(BaseCamera):
+ prob_threshold = DEFAULT_PROB_THRESH
def __init__(self, device, args):
log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout)
@@ -81,8 +83,9 @@
self.labels_map = None
self.args = args
+ self.prob_threshold = args.prob_threshold
- super(Camera, self).__init__(device)
+ super(Camera, self).__init__(device, args.idle)
def __del__(self):
self.cap.release()
@@ -145,7 +148,7 @@
for obj in res[0][0]:
# Draw only objects when probability more than specified threshold
- if obj[2] > self.args.prob_threshold:
+ if obj[2] > self.prob_threshold:
xmin = int(obj[3] * initial_w)
ymin = int(obj[4] * initial_h)
xmax = int(obj[5] * initial_w)