Skip to content

Commit

Permalink
pass polygon to custom transform
Browse files Browse the repository at this point in the history
  • Loading branch information
yimm0815 committed Dec 18, 2019
1 parent 629ea82 commit e62a835
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
5 changes: 3 additions & 2 deletions analytics/common/runva.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions analytics/crowd-counting/Xeon/gst/pipeline/2/pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
},
"height": {
"type": "integer"
},
"polygon": {
"type": "array",
"items": {
"type": "number"
}
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion analytics/crowd-counting/count-crowd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
24 changes: 12 additions & 12 deletions analytics/crowd-counting/custom_transforms/crowd_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e62a835

Please sign in to comment.