From b9d4b1f6943b78c9d2975252d52564a8cfe5764b Mon Sep 17 00:00:00 2001 From: yimm0815 Date: Tue, 17 Dec 2019 10:59:13 -0800 Subject: [PATCH 1/5] code cleanup and parameter reorganization --- analytics/common/runva.py | 2 +- analytics/crowd-counting/count-crowd.py | 7 ++++--- analytics/object-detection/detect-object.py | 6 +++--- analytics/people-counting/count-people.py | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/analytics/common/runva.py b/analytics/common/runva.py index 9ecf83b80..1344531cf 100755 --- a/analytics/common/runva.py +++ b/analytics/common/runva.py @@ -27,7 +27,7 @@ def __init__(self, pipeline, version="2"): def stop(self): self._stop=True - def loop(self, sensor, location, uri, algorithm, topic, algorithmName, resolution): + def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolution={}): if algorithmName=="crowd-counting": pid,msg=PipelineManager.create_instance(self._pipeline,self._version,{ "source": { diff --git a/analytics/crowd-counting/count-crowd.py b/analytics/crowd-counting/count-crowd.py index 2559da16d..43db0b1bd 100755 --- a/analytics/crowd-counting/count-crowd.py +++ b/analytics/crowd-counting/count-crowd.py @@ -24,9 +24,10 @@ runva=None stop=False -def connect(sensor, location, algorithm, uri, algorithmName, resolution): +def connect(sensor, location, uri, algorithm, algorithmName, resolution, zonemap): global mqtt2db, rec2db, runva + print("==============count-crowd:connect:zonemap=",zonemap,"========================",flush=True) try: mqtt2db=MQTT2DB(algorithm) # this waits for mqtt rec2db=Rec2DB(sensor) @@ -39,7 +40,7 @@ def connect(sensor, location, algorithm, uri, algorithmName, resolution): # any VA exit indicates a camera disconnect with ThreadPoolExecutor(1) as e1: - e1.submit(runva.loop, sensor, location, uri, algorithm, topic, algorithmName, resolution) + e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, resolution) if not stop: mqtt2db.stop() @@ -88,7 +89,7 @@ def quit_service(signum, sigframe): # stream from the sensor print("Connected to "+sensor["_id"]+"...",flush=True) - connect(sensor["_id"],sensor["_source"]["location"],algorithm,sensor["_source"]["url"],sensor["_source"]["algorithm"],sensor["_source"]["resolution"]) + connect(sensor["_id"],sensor["_source"]["location"],sensor["_source"]["url"],algorithm,sensor["_source"]["algorithm"],sensor["_source"]["resolution"],sensor["_source"]["zonemap"]) # if exit, there is somehting wrong r=dbs.update(sensor["_id"],{"status":"disconnected"}) diff --git a/analytics/object-detection/detect-object.py b/analytics/object-detection/detect-object.py index cc7ddc2a4..c85e02c3d 100755 --- a/analytics/object-detection/detect-object.py +++ b/analytics/object-detection/detect-object.py @@ -23,7 +23,7 @@ myAlgorithm="" version=0 -def connect(sensor, location, algorithm, uri, algorithmName, resolution): +def connect(sensor, location, uri, algorithm, algorithmName): global mqtt2db, rec2db, runva try: @@ -38,7 +38,7 @@ def connect(sensor, location, algorithm, uri, algorithmName, resolution): # any VA exit indicates a camera disconnect with ThreadPoolExecutor(1) as e1: - e1.submit(runva.loop, sensor, location, uri, algorithm, topic, algorithmName, resolution) + e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, {}) if not stop: mqtt2db.stop() @@ -94,7 +94,7 @@ def quit_service(signum, sigframe): # stream from the sensor print("Connected to "+sensor["_id"]+"...",flush=True) - connect(sensor["_id"],sensor["_source"]["location"],algorithm,sensor["_source"]["url"],sensor["_source"]["algorithm"],sensor["_source"]["resolution"]) + connect(sensor["_id"],sensor["_source"]["location"],sensor["_source"]["url"],algorithm,sensor["_source"]["algorithm"]) # if exit, there is somehting wrong r=dbs.update(sensor["_id"],{"status":"disconnected"}) diff --git a/analytics/people-counting/count-people.py b/analytics/people-counting/count-people.py index 6948034b0..c52627aaa 100755 --- a/analytics/people-counting/count-people.py +++ b/analytics/people-counting/count-people.py @@ -20,7 +20,7 @@ runva=None stop=False -def connect(sensor, location, algorithm, uri, algorithmName, resolution): +def connect(sensor, location, uri, algorithm, algorithmName): global mqtt2db, rec2db, runva try: @@ -35,7 +35,7 @@ def connect(sensor, location, algorithm, uri, algorithmName, resolution): # any VA exit indicates a camera disconnect with ThreadPoolExecutor(1) as e1: - e1.submit(runva.loop, sensor, location, uri, algorithm, topic, algorithmName, resolution) + e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, {}) if not stop: mqtt2db.stop() @@ -84,7 +84,7 @@ def quit_service(signum, sigframe): # stream from the sensor print("Connected to "+sensor["_id"]+"...",flush=True) - connect(sensor["_id"],sensor["_source"]["location"],algorithm,sensor["_source"]["url"],sensor["_source"]["algorithm"],sensor["_source"]["resolution"]) + connect(sensor["_id"],sensor["_source"]["location"],sensor["_source"]["url"],algorithm,sensor["_source"]["algorithm"]) # if exit, there is somehting wrong r=dbs.update(sensor["_id"],{"status":"disconnected"}) From 312f3e67fd139aa12f03c8ce3e5b49bd31fe6873 Mon Sep 17 00:00:00 2001 From: yimm0815 Date: Tue, 17 Dec 2019 14:48:52 -0800 Subject: [PATCH 2/5] custom transform input para passing try --- analytics/common/runva.py | 10 ++-- .../Xeon/gst/pipeline/2/pipeline.json | 46 +++++++++---------- .../custom_transforms/crowd_counting.py | 4 +- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/analytics/common/runva.py b/analytics/common/runva.py index 1344531cf..bb74444c9 100755 --- a/analytics/common/runva.py +++ b/analytics/common/runva.py @@ -56,12 +56,14 @@ def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolutio "topic": topic, }, "parameters": { - "numZone": 8, - "width": resolution["width"], - "height": resolution["height"], + "crowd_count": { + "numZone": 8, + "width": resolution["width"], + "height": resolution["height"] + }, "every-nth-frame": every_nth_frame, "recording_prefix": "/tmp/" + sensor, - }, + } }) else: pid,msg=PipelineManager.create_instance(self._pipeline,self._version,{ diff --git a/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json b/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json index 08c4fa7cb..8f88b5308 100644 --- a/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json +++ b/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json @@ -1,8 +1,8 @@ { - "name": "crowd_counting", - "version": 2, - "type": "GStreamer", - "template":"rtspsrc udp-buffer-size=212992 name=\"source\" ! queue ! rtph264depay ! h264parse ! video/x-h264 ! tee name=t ! queue ! decodebin ! videoconvert name=\"videoconvert\" ! video/x-raw,format=BGRx ! queue leaky=upstream ! gvainference infer-config=CPU_BIND_THREAD=NO model=\"{models[CSRNet_IR_model_2019R3][1][network]}\" model-proc=\"{models[CSRNet_IR_model_2019R3][1][proc]}\" name=\"detection\" ! queue ! gvametaconvert converter=json method=detection include-no-detections=true name=\"metaconvert\" ! gvapython name=\"crowdcounting\" module=\"crowd_counting\" class=\"CrowdCounting\" package=\"custom_transforms\" ! queue ! gvametapublish name=\"destination\" ! appsink name=appsink t. ! queue ! splitmuxsink max-size-time=60500000000 name=\"splitmuxsink\"", + "name": "crowd_counting", + "version": 2, + "type": "GStreamer", + "template":"rtspsrc udp-buffer-size=212992 name=\"source\" ! queue ! rtph264depay ! h264parse ! video/x-h264 ! tee name=t ! queue ! decodebin ! videoconvert name=\"videoconvert\" ! video/x-raw,format=BGRx ! queue leaky=upstream ! gvainference infer-config=CPU_BIND_THREAD=NO model=\"{models[CSRNet_IR_model_2019R3][1][network]}\" model-proc=\"{models[CSRNet_IR_model_2019R3][1][proc]}\" name=\"detection\" ! queue ! gvametaconvert converter=json method=detection include-no-detections=true name=\"metaconvert\" ! gvapython name=\"crowdcounting\" module=\"crowd_counting\" class=\"CrowdCounting\" package=\"custom_transforms\" ! queue ! gvametapublish name=\"destination\" ! appsink name=appsink t. ! queue ! splitmuxsink max-size-time=60500000000 name=\"splitmuxsink\"", "description": "Crowd Counting Pipeline", "source": { "type": "object", @@ -24,26 +24,26 @@ } } }, - "parameters": { + "parameters": { "type" : "object", "properties" : { - "numZone": { - "element":"detection", - "type": "integer", - "minimum": 0, - "maximum": 100 - }, - "width": { - "element":"detection", - "type": "integer", - "minimum": 0, - "maximum": 4096 - }, - "height": { - "element":"detection", - "type": "integer", - "minimum": 0, - "maximum": 3072 + "crowd_count": { + "element": { + "name": "crowdcounting", + "property": "args" + }, + "type": "object", + "properties": { + "numZone": { + "type": "integer" + }, + "width": { + "type": "integer" + }, + "height": { + "type": "integer" + } + } }, "every-nth-frame": { "element":"detection", @@ -74,5 +74,5 @@ "default":"recording" } } - } + } } diff --git a/analytics/crowd-counting/custom_transforms/crowd_counting.py b/analytics/crowd-counting/custom_transforms/crowd_counting.py index 05bf644ea..8fd28b96f 100644 --- a/analytics/crowd-counting/custom_transforms/crowd_counting.py +++ b/analytics/crowd-counting/custom_transforms/crowd_counting.py @@ -5,11 +5,13 @@ from PIL import Image, ImageDraw class CrowdCounting: - def __init__(self,numZone=8,width=1024,height=768): + def __init__(self,numZone=0,width=0,height=0): + print("===========CrowdCounting:__init__:numZone,width,height=", numZone, width, height, "================") self.numZone = numZone self.mask=[0]*self.numZone self.crowd_count=[0]*self.numZone self.polygon=[0]*self.numZone + self.crowd_count = -1 #self._sensor = sensor self.polygon[0] = [865,210,933,210,933,227,968,227,968,560,934,560,934,568,865,568,865,210] From 88ec21ebef4d4a16b42936d4f1fb1b92bac5dfc3 Mon Sep 17 00:00:00 2001 From: yimm0815 Date: Tue, 17 Dec 2019 16:10:26 -0800 Subject: [PATCH 3/5] set specific zone number instead of total number of zones --- analytics/common/runva.py | 2 +- .../Xeon/gst/pipeline/2/pipeline.json | 2 +- .../custom_transforms/crowd_counting.py | 58 ++++++++----------- analytics/object-detection/detect-object.py | 2 +- analytics/people-counting/count-people.py | 2 +- 5 files changed, 27 insertions(+), 39 deletions(-) diff --git a/analytics/common/runva.py b/analytics/common/runva.py index bb74444c9..a1ba9f3c1 100755 --- a/analytics/common/runva.py +++ b/analytics/common/runva.py @@ -57,7 +57,7 @@ def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolutio }, "parameters": { "crowd_count": { - "numZone": 8, + "zone": 8, "width": resolution["width"], "height": resolution["height"] }, diff --git a/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json b/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json index 8f88b5308..547d432c8 100644 --- a/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json +++ b/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json @@ -34,7 +34,7 @@ }, "type": "object", "properties": { - "numZone": { + "zone": { "type": "integer" }, "width": { diff --git a/analytics/crowd-counting/custom_transforms/crowd_counting.py b/analytics/crowd-counting/custom_transforms/crowd_counting.py index 8fd28b96f..f64527ddd 100644 --- a/analytics/crowd-counting/custom_transforms/crowd_counting.py +++ b/analytics/crowd-counting/custom_transforms/crowd_counting.py @@ -5,63 +5,51 @@ from PIL import Image, ImageDraw class CrowdCounting: - def __init__(self,numZone=0,width=0,height=0): - print("===========CrowdCounting:__init__:numZone,width,height=", numZone, width, height, "================") - self.numZone = numZone - self.mask=[0]*self.numZone - self.crowd_count=[0]*self.numZone - self.polygon=[0]*self.numZone - self.crowd_count = -1 - + def __init__(self,zone=0,width=1024,height=768): + print("===========CrowdCounting:__init__:zone,width,height=", zone, width, height, "================") + #self._sensor = sensor - self.polygon[0] = [865,210,933,210,933,227,968,227,968,560,934,560,934,568,865,568,865,210] - self.polygon[1] = [830,49,861,49,893,56,922,71,946,93,960,122,967,151,967,228,934,228,934,211,899,211,867,209,864,183,854,165,836,149,814,144,759,144,759,114,795,114,795,84,830,83,830,49] - self.polygon[2] = [259,49,259,82,277,82,277,114,323,114,323,146,760,146,760,114,796,114,796,82,832,82,831,49,259,49] - self.polygon[3] = [259,49,259,82,277,82,277,114,322,114,322,144,269,144,246,146,226,156,212,173,204,190,204,212,174,212,172,214,143,214,143,161,157,127,182,103,214,87,231,83,230,49,259,49] - self.polygon[4] = [140,571,174,571,206,563,206,211,140,211,140,571] - self.polygon[5] = [206,563,174,569,142,569,142,599,158,630,182,654,212,668,242,673,298,672,298,644,326,644,326,612,271,612,248,609,227,600,215,583,206,563] - self.polygon[6] = [762,611,762,642,788,642,788,672,811,672,811,704,261,704,261,672,298,672,298,642,325,642,325,611,762,611] - self.polygon[7] = [966,561,966,586,964,615,954,646,933,676,900,695,866,702,810,702,788,674,788,644,762,644,762,611,817,611,840,604,857,587,868,566,896,574,901,567,933,567,933,561,966,561] + self.polygons=[0]*8 + self.polygons[0] = [865,210,933,210,933,227,968,227,968,560,934,560,934,568,865,568,865,210] + self.polygons[1] = [830,49,861,49,893,56,922,71,946,93,960,122,967,151,967,228,934,228,934,211,899,211,867,209,864,183,854,165,836,149,814,144,759,144,759,114,795,114,795,84,830,83,830,49] + self.polygons[2] = [259,49,259,82,277,82,277,114,323,114,323,146,760,146,760,114,796,114,796,82,832,82,831,49,259,49] + self.polygons[3] = [259,49,259,82,277,82,277,114,322,114,322,144,269,144,246,146,226,156,212,173,204,190,204,212,174,212,172,214,143,214,143,161,157,127,182,103,214,87,231,83,230,49,259,49] + self.polygons[4] = [140,571,174,571,206,563,206,211,140,211,140,571] + self.polygons[5] = [206,563,174,569,142,569,142,599,158,630,182,654,212,668,242,673,298,672,298,644,326,644,326,612,271,612,248,609,227,600,215,583,206,563] + self.polygons[6] = [762,611,762,642,788,642,788,672,811,672,811,704,261,704,261,672,298,672,298,642,325,642,325,611,762,611] + self.polygons[7] = [966,561,966,586,964,615,954,646,933,676,900,695,866,702,810,702,788,674,788,644,762,644,762,611,817,611,840,604,857,587,868,566,896,574,901,567,933,567,933,561,966,561] + self.zone = zone + self.mask=[0] + self.crowd_count=0 + self.polygon=self.polygons[self.zone] + #no matter what resolution the input video is (currently 720x1280), #it will resize to 1024x768 before sending to model #AI data input is 1/8 of image resolution, 768x1024 image, data is 1x96x128x1 self.width = width>>3 self.height = height>>3 - for zone in range(self.numZone): - for t in range(len(self.polygon[zone])): - self.polygon[zone][t] = self.polygon[zone][t]>>3 + for t in range(len(self.polygon)): + self.polygon[t] = self.polygon[t]>>3 #convert polygon to mask algorithm #https://stackoverflow.com/questions/3654289/scipy-create-2d-polygon-mask self.img = Image.new('L', (self.width, self.height), 0) - for zone in range(self.numZone): - self.img = Image.new('L', (self.width, self.height), 0) - ImageDraw.Draw(self.img).polygon(self.polygon[zone], outline=1, fill=1) - self.mask[zone] = numpy.array(self.img).flatten() + ImageDraw.Draw(self.img).polygon(self.polygon, outline=1, fill=1) + self.mask = numpy.array(self.img).flatten() def process_frame(self, frame): for tensor in frame.tensors(): data = tensor.data() imgData = [] imgData.append(tensor.data()) - for zone in range(self.numZone): - self.crowd_count[zone] = numpy.sum(self.mask[zone] * imgData) + self.crowd_count = numpy.sum(self.mask * imgData) if (self.crowd_count): messages = list(frame.messages()) if len(messages) > 0: json_msg = json.loads(messages[0].get_message()) - json_msg["count"] = { - "zone0":int(self.crowd_count[0]), - "zone1":int(self.crowd_count[1]), - "zone2":int(self.crowd_count[2]), - "zone3":int(self.crowd_count[3]), - "zone4":int(self.crowd_count[4]), - "zone5":int(self.crowd_count[5]), - "zone6":int(self.crowd_count[6]), - "zone7":int(self.crowd_count[7]) - } + json_msg["count"] = {"zone"+str(self.zone):int(self.crowd_count)} messages[0].set_message(json.dumps(json_msg)) return True diff --git a/analytics/object-detection/detect-object.py b/analytics/object-detection/detect-object.py index c85e02c3d..5cdecafcf 100755 --- a/analytics/object-detection/detect-object.py +++ b/analytics/object-detection/detect-object.py @@ -38,7 +38,7 @@ def connect(sensor, location, uri, algorithm, algorithmName): # any VA exit indicates a camera disconnect with ThreadPoolExecutor(1) as e1: - e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, {}) + e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName) if not stop: mqtt2db.stop() diff --git a/analytics/people-counting/count-people.py b/analytics/people-counting/count-people.py index c52627aaa..d60974de2 100755 --- a/analytics/people-counting/count-people.py +++ b/analytics/people-counting/count-people.py @@ -35,7 +35,7 @@ def connect(sensor, location, uri, algorithm, algorithmName): # any VA exit indicates a camera disconnect with ThreadPoolExecutor(1) as e1: - e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, {}) + e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName) if not stop: mqtt2db.stop() From 629ea822361ba5127506ce390034f525de72168a Mon Sep 17 00:00:00 2001 From: yimm0815 Date: Tue, 17 Dec 2019 18:00:30 -0800 Subject: [PATCH 4/5] pass zone number in --- analytics/common/runva.py | 4 ++-- analytics/crowd-counting/count-crowd.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/analytics/common/runva.py b/analytics/common/runva.py index a1ba9f3c1..69148749c 100755 --- a/analytics/common/runva.py +++ b/analytics/common/runva.py @@ -27,7 +27,7 @@ def __init__(self, pipeline, version="2"): def stop(self): self._stop=True - def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolution={}): + def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolution={}, zone=0): if algorithmName=="crowd-counting": pid,msg=PipelineManager.create_instance(self._pipeline,self._version,{ "source": { @@ -57,7 +57,7 @@ def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolutio }, "parameters": { "crowd_count": { - "zone": 8, + "zone": zone, "width": resolution["width"], "height": resolution["height"] }, diff --git a/analytics/crowd-counting/count-crowd.py b/analytics/crowd-counting/count-crowd.py index 43db0b1bd..f9c254a86 100755 --- a/analytics/crowd-counting/count-crowd.py +++ b/analytics/crowd-counting/count-crowd.py @@ -28,6 +28,7 @@ def connect(sensor, location, uri, algorithm, algorithmName, resolution, zonemap global mqtt2db, rec2db, runva print("==============count-crowd:connect:zonemap=",zonemap,"========================",flush=True) + try: mqtt2db=MQTT2DB(algorithm) # this waits for mqtt rec2db=Rec2DB(sensor) @@ -40,7 +41,7 @@ def connect(sensor, location, uri, algorithm, algorithmName, resolution, zonemap # any VA exit indicates a camera disconnect with ThreadPoolExecutor(1) as e1: - e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, resolution) + e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, resolution, zonemap[0]["zone"]) if not stop: mqtt2db.stop() From e62a835ace835274cf49c9219eef6b4913e211b1 Mon Sep 17 00:00:00 2001 From: yimm0815 Date: Tue, 17 Dec 2019 18:32:29 -0800 Subject: [PATCH 5/5] pass polygon to custom transform --- analytics/common/runva.py | 5 ++-- .../Xeon/gst/pipeline/2/pipeline.json | 6 +++++ analytics/crowd-counting/count-crowd.py | 6 ++++- .../custom_transforms/crowd_counting.py | 24 +++++++++---------- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/analytics/common/runva.py b/analytics/common/runva.py index 69148749c..78494b5c2 100755 --- a/analytics/common/runva.py +++ b/analytics/common/runva.py @@ -27,7 +27,7 @@ def __init__(self, pipeline, version="2"): def stop(self): self._stop=True - def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolution={}, zone=0): + def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolution={}, zone=0, polygon=[]): if algorithmName=="crowd-counting": pid,msg=PipelineManager.create_instance(self._pipeline,self._version,{ "source": { @@ -59,7 +59,8 @@ def loop(self, sensor, location, uri, topic, algorithm, algorithmName, resolutio "crowd_count": { "zone": zone, "width": resolution["width"], - "height": resolution["height"] + "height": resolution["height"], + "polygon": polygon }, "every-nth-frame": every_nth_frame, "recording_prefix": "/tmp/" + sensor, diff --git a/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json b/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json index 547d432c8..fe7981a41 100644 --- a/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json +++ b/analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json @@ -42,6 +42,12 @@ }, "height": { "type": "integer" + }, + "polygon": { + "type": "array", + "items": { + "type": "number" + } } } }, diff --git a/analytics/crowd-counting/count-crowd.py b/analytics/crowd-counting/count-crowd.py index f9c254a86..5747ca58c 100755 --- a/analytics/crowd-counting/count-crowd.py +++ b/analytics/crowd-counting/count-crowd.py @@ -28,6 +28,10 @@ def connect(sensor, location, uri, algorithm, algorithmName, resolution, zonemap global mqtt2db, rec2db, runva print("==============count-crowd:connect:zonemap=",zonemap,"========================",flush=True) + flatZonemap = [] + for sublist in zonemap[0]["polygon"]: + for item in sublist: + flatZonemap.append(item) try: mqtt2db=MQTT2DB(algorithm) # this waits for mqtt @@ -41,7 +45,7 @@ def connect(sensor, location, uri, algorithm, algorithmName, resolution, zonemap # any VA exit indicates a camera disconnect with ThreadPoolExecutor(1) as e1: - e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, resolution, zonemap[0]["zone"]) + e1.submit(runva.loop, sensor, location, uri, topic, algorithm, algorithmName, resolution, zonemap[0]["zone"],flatZonemap) if not stop: mqtt2db.stop() diff --git a/analytics/crowd-counting/custom_transforms/crowd_counting.py b/analytics/crowd-counting/custom_transforms/crowd_counting.py index f64527ddd..c63a25dc6 100644 --- a/analytics/crowd-counting/custom_transforms/crowd_counting.py +++ b/analytics/crowd-counting/custom_transforms/crowd_counting.py @@ -5,24 +5,24 @@ from PIL import Image, ImageDraw class CrowdCounting: - def __init__(self,zone=0,width=1024,height=768): - print("===========CrowdCounting:__init__:zone,width,height=", zone, width, height, "================") + def __init__(self,zone=0,width=1024,height=768, polygon=[865,210,933,210,933,227,968,227,968,560,934,560,934,568,865,568,865,210]): + print("===========CrowdCounting:__init__:zone,width,height,polygon=", zone, width, height, polygon, "================") #self._sensor = sensor - self.polygons=[0]*8 - self.polygons[0] = [865,210,933,210,933,227,968,227,968,560,934,560,934,568,865,568,865,210] - self.polygons[1] = [830,49,861,49,893,56,922,71,946,93,960,122,967,151,967,228,934,228,934,211,899,211,867,209,864,183,854,165,836,149,814,144,759,144,759,114,795,114,795,84,830,83,830,49] - self.polygons[2] = [259,49,259,82,277,82,277,114,323,114,323,146,760,146,760,114,796,114,796,82,832,82,831,49,259,49] - self.polygons[3] = [259,49,259,82,277,82,277,114,322,114,322,144,269,144,246,146,226,156,212,173,204,190,204,212,174,212,172,214,143,214,143,161,157,127,182,103,214,87,231,83,230,49,259,49] - self.polygons[4] = [140,571,174,571,206,563,206,211,140,211,140,571] - self.polygons[5] = [206,563,174,569,142,569,142,599,158,630,182,654,212,668,242,673,298,672,298,644,326,644,326,612,271,612,248,609,227,600,215,583,206,563] - self.polygons[6] = [762,611,762,642,788,642,788,672,811,672,811,704,261,704,261,672,298,672,298,642,325,642,325,611,762,611] - self.polygons[7] = [966,561,966,586,964,615,954,646,933,676,900,695,866,702,810,702,788,674,788,644,762,644,762,611,817,611,840,604,857,587,868,566,896,574,901,567,933,567,933,561,966,561] + # self.polygons=[0]*8 + # self.polygons[0] = [865,210,933,210,933,227,968,227,968,560,934,560,934,568,865,568,865,210] + # self.polygons[1] = [830,49,861,49,893,56,922,71,946,93,960,122,967,151,967,228,934,228,934,211,899,211,867,209,864,183,854,165,836,149,814,144,759,144,759,114,795,114,795,84,830,83,830,49] + # self.polygons[2] = [259,49,259,82,277,82,277,114,323,114,323,146,760,146,760,114,796,114,796,82,832,82,831,49,259,49] + # self.polygons[3] = [259,49,259,82,277,82,277,114,322,114,322,144,269,144,246,146,226,156,212,173,204,190,204,212,174,212,172,214,143,214,143,161,157,127,182,103,214,87,231,83,230,49,259,49] + # self.polygons[4] = [140,571,174,571,206,563,206,211,140,211,140,571] + # self.polygons[5] = [206,563,174,569,142,569,142,599,158,630,182,654,212,668,242,673,298,672,298,644,326,644,326,612,271,612,248,609,227,600,215,583,206,563] + # self.polygons[6] = [762,611,762,642,788,642,788,672,811,672,811,704,261,704,261,672,298,672,298,642,325,642,325,611,762,611] + # self.polygons[7] = [966,561,966,586,964,615,954,646,933,676,900,695,866,702,810,702,788,674,788,644,762,644,762,611,817,611,840,604,857,587,868,566,896,574,901,567,933,567,933,561,966,561] self.zone = zone self.mask=[0] self.crowd_count=0 - self.polygon=self.polygons[self.zone] + self.polygon=polygon #no matter what resolution the input video is (currently 720x1280), #it will resize to 1024x768 before sending to model