提交 5648a609 authored 作者: blu's avatar blu

human detection: region

上级 d0ed1c24
......@@ -66,38 +66,45 @@ binPrefix = os.getenv('BIN_PRE', '')
configDir = os.getenv('CFG_DIR', workd)
API_HOST = None
API_CAMERA_CFG_URI = "/video/analysis/camera/{}/model"
RABBITMQ_URI = os.getenv("RABB_ADDR", None)
RABBITMQ_URI = os.getenv("RABB_ADDR", "amqp://guest:guest@localhost:5672/")
RABBITMQ_TOPIC = os.getenv("RABB_TOPIC", "*.camera.model")
RABBITMQ_EXHANGE = os.getenv("RABB_EXC", "video")
CAMERA_CONFIG_MAP = {}
rabChan = None
def rabCallback(ch, method, prop, body):
try:
print("received rabbitmsg. routing key: {} , body: {}".format(method.routing_key, body))
rk = method.routing_key.split('.')
sn = None
if len(rk):
sn = rk[0]
if sn:
CAMERA_CONFIG_MAP[sn] = json.loads(body)
print("CAMERA_CONFIG_MAP: \n{}".format(json.dumps(CAMERA_CONFIG_MAP)))
except Exception as e:
#traceback.print_exc()
#pdb.post_mortem(tb)
print("failed to process callback {}: {} - {}".format(e, method, body))
if RABBITMQ_URI:
def initRabbit():
rabChan = None
if RABBITMQ_URI:
print("connecting rabbitmq {}".format(RABBITMQ_URI))
parameters = pika.URLParameters(RABBITMQ_URI) #("amqp://ilabservice:iLabServiceOps123456@40.73.40.246:5672/")
connection = pika.BlockingConnection(parameters)
rabChan = connection.channel()
rabChan.exchange_declare(exchange=RABBITMQ_EXHANGE, exchange_type="topic")
qr = rabChan.queue_declare('', durable=False)
qr = rabChan.queue_declare('', durable=True)
rabChan.queue_bind(exchange=RABBITMQ_EXHANGE,
queue=qr.method.queue, routing_key=RABBITMQ_TOPIC)
rabChan.basic_consume(
queue=qr.method.queue, on_message_callback=rabCallback, auto_ack=True)
return rabChan
print("CONFIG: \n\tMQTT: {}:{}\n\tBIN_NAME: {}".format(
MQTT_HOST, MQTT_PORT, binName))
def rabCallback(ch, method, prop, body):
try:
rk = method.routing_key.split('.')
sn = None
if len(rk):
sn = rk[0]
if sn:
CAMERA_CONFIG_MAP[sn] = json.loads(body)
except Exception as e:
print("failed to process callback: {} - {}", method, body)
def downloadFile(ipcSn, dirName, fileName, destDir):
file_path = ipcSn + '/'+dirName+'/'+fileName
destDir = destDir + '/' + fileName
......@@ -160,7 +167,8 @@ class VAMMQTTClient:
self.client.on_message = VAMMQTTClient.on_message
self.client.connect_async(host, port, 30)
self.client.loop_start()
self.rabChan = initRabbit()
th = threading.Thread(target=lambda: self.rabChan.start_consuming()).start()
app = Flask(__name__,
static_url_path='',
......@@ -178,6 +186,24 @@ worker.conf.update(
# timezone='Europe/Oslo',
enable_utc=True)
def getRegionConfig(ipcSN):
region = None
if ipcSN in CAMERA_CONFIG_MAP and type(CAMERA_CONFIG_MAP[ipcSN]) is dict:
region = CAMERA_CONFIG_MAP[ipcSN]['region']
elif CAMERA_CONFIG_MAP.get(ipcSN) is None and API_HOST:
res = requests.get(API_HOST + API_CAMERA_CFG_URI)
try:
if res.status_code == 200:
if "region" in res.json():
region = res.json()["region"]
CAMERA_CONFIG_MAP[ipcSN] = res.json()
if CAMERA_CONFIG_MAP.get(ipcSN) is None:
CAMERA_CONFIG_MAP[ipCSN] = 0
except Exception as e:
print("failed to get camera config {}: {}".format(ipcSN, e))
print("getRegionConfig: {}: {}".format(ipcSN, json.dumps(region)))
return region
def take_task(task):
ret = {'code': 0, 'msg': 'ok'}
print("taking task", json.dumps(task))
......@@ -188,6 +214,7 @@ def take_task(task):
ret['data'] = taskValidator.errors
else:
# process
task["region"] = getRegionConfig(task['cameraId'])
video_analysis.apply_async(args=[task])
print(json.dumps(ret))
return ret
......@@ -217,20 +244,6 @@ def video_analysis(data):
workd) + '/' + ipcSN, strRand)
os.system('mkdir -p ' + downloadDir)
downloadFile(ipcSN, dirName, fileName, downloadDir)
region = None
if ipcSN in CAMERA_CONFIG_MAP and type(CAMERA_CONFIG_MAP[ipcSN]) is dict:
region = CAMERA_CONFIG_MAP[ipcSN]['region']
else ipcSN is not in CAMERA_CONFIG_MAP:
res = requests.get(API_HOST + API_CAMERA_CFG_URI)
try:
if res.status_code == 200:
if "region" in res.json():
region = res.json()["region"]
CAMERA_CONFIG_MAP[ipcSN] = res.json()
if ipcSN is not in CAMERA_CONFIG_MAP:
CAMERA_CONFIG_MAP[ipCSN] = 0
except Exception as e:
print("failed to get camera config {}: {}".format(ipcSN, e))
print("downloaded file {} into {}".format(fileName, downloadDir))
# analyze
......@@ -238,8 +251,9 @@ def video_analysis(data):
prefix = binPrefix + ' ' if binPrefix else binPrefix
cmdLine = prefix + workd + '/' + binName + ' ' + downloadDir + \
fileName + ' -c ' + configDir + ' -o ' + downloadDir + '/detect.jpg'
region = data['region']
if region:
cmdLine += "-s {},{},{},{}".format(region['minX'], region['minY'], region['maxX'], region['maxY'])
cmdLine += " -s {},{},{},{}".format(region['minX'], region['minY'], region['maxX'], region['maxY'])
else:
print("no region config")
cmdArgs = shlex.split(cmdLine)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论