From e62a835ace835274cf49c9219eef6b4913e211b1 Mon Sep 17 00:00:00 2001 From: yimm0815 Date: Tue, 17 Dec 2019 18:32:29 -0800 Subject: [PATCH] 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