Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
3ef56023
提交
3ef56023
authored
3月 10, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
object detection: revise
上级
7b282b1f
全部展开
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
69 行增加
和
15 行删除
+69
-15
web.py
opencv-yolo/web/web.py
+69
-15
web_rabbit.py
opencv-yolo/web/web_rabbit.py
+0
-0
没有找到文件。
opencv-yolo/web/web.py
浏览文件 @
3ef56023
...
...
@@ -72,9 +72,13 @@ API_CAMERA_CFG_URI = os.getenv("API_CAMERA_CFG_URI", "/video/analysis/camera/{}/
RABBITMQ_URI
=
os
.
getenv
(
"RABBITMQ_URI"
,
"amqp://guest:guest@localhost:5672/"
)
RABBITMQ_TOPIC
=
os
.
getenv
(
"RABBITMQ_TOPIC"
,
"*.camera.model"
)
RABBITMQ_EXHANGE
=
os
.
getenv
(
"RABBITMQ_EXHANGE"
,
"video"
)
AI_QUEUE_TASK
=
os
.
getenv
(
'AI_TASK'
,
'videoai.v1.task'
)
AI_QUEUE_RESULT
=
os
.
getenv
(
'AI_RESULT'
,
'videoai.v1.result'
)
AI_EXCHANGE
=
os
.
getenv
(
'AI_XHG'
,
'videoai'
)
CAMERA_CONFIG_MAP
=
{}
def
rabCallback
(
ch
,
method
,
prop
,
body
):
def
rab
Model
Callback
(
ch
,
method
,
prop
,
body
):
try
:
print
(
"received rabbitmsg. routing key: {} , body: {}"
.
format
(
method
.
routing_key
,
body
))
rk
=
method
.
routing_key
.
split
(
'.'
)
...
...
@@ -85,25 +89,56 @@ def rabCallback(ch, method, prop, body):
CAMERA_CONFIG_MAP
[
sn
]
=
json
.
loads
(
body
)
print
(
"CAMERA_CONFIG_MAP:
\n
{}"
.
format
(
json
.
dumps
(
CAMERA_CONFIG_MAP
)))
except
Exception
as
e
:
#extype, value, tb = sys.exc_info()
#traceback.print_exc()
#pdb.post_mortem(tb)
print
(
"failed to process callback {}: {} - {}"
.
format
(
e
,
method
,
body
))
def
initRabbit
():
rabChan
=
None
def
rabAiTaskCallback
(
ch
,
method
,
prop
,
body
):
try
:
print
(
"received rabbitmsg. routing key: {} , body: {}"
.
format
(
method
.
routing_key
,
body
))
take_task
(
json
.
loads
(
body
))
except
Exception
as
e
:
extype
,
value
,
tb
=
sys
.
exc_info
()
traceback
.
print_exc
()
pdb
.
post_mortem
(
tb
)
print
(
"failed to process callback {}: {} - {}"
.
format
(
e
,
method
,
body
))
def
rabbit_camera_model
():
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
)
print
(
"rabbitmq connection established"
)
# camera model channel
rabChanModel
=
connection
.
channel
()
rabChanModel
.
exchange_declare
(
exchange
=
RABBITMQ_EXHANGE
,
exchange_type
=
"topic"
)
modelQueue
=
rabChanModel
.
queue_declare
(
''
,
durable
=
True
)
rabChanModel
.
queue_bind
(
exchange
=
RABBITMQ_EXHANGE
,
queue
=
modelQueue
.
method
.
queue
,
routing_key
=
RABBITMQ_TOPIC
)
rabChanModel
.
basic_consume
(
queue
=
modelQueue
.
method
.
queue
,
on_message_callback
=
rabModelCallback
,
auto_ack
=
True
)
print
(
"bound camera model"
)
rabChanModel
.
start_consuming
()
def
rabbit_ai_task
():
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
=
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
# ai analysis task channel
rabChanAiTask
=
connection
.
channel
()
if
AI_EXCHANGE
:
rabChanAiTask
.
exchange_declare
(
exchange
=
AI_EXCHANGE
,
exchange_type
=
"direct"
)
rabChanAiTask
.
queue_declare
(
queue
=
AI_QUEUE_TASK
,
durable
=
True
)
rabChanAiTask
.
queue_bind
(
exchange
=
AI_EXCHANGE
,
queue
=
AI_QUEUE_TASK
,
routing_key
=
AI_QUEUE_TASK
)
rabChanAiTask
.
basic_consume
(
queue
=
AI_QUEUE_TASK
,
on_message_callback
=
rabAiTaskCallback
,
auto_ack
=
True
)
print
(
"bound ai task"
)
rabChanAiTask
.
start_consuming
()
print
(
"CONFIG:
\n\t
MQTT: {}:{}
\n\t
BIN_NAME: {}"
.
format
(
MQTT_HOST
,
MQTT_PORT
,
binName
))
...
...
@@ -128,6 +163,10 @@ def uploadFile(ipcSn, dirName, fileName, srcPath):
class
VAMMQTTClient
:
rabChanModel
=
None
rabChanAiTask
=
None
th1
=
None
th2
=
None
# The callback for when the client receives a CONNACK response from the server.
@staticmethod
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
...
...
@@ -173,8 +212,9 @@ 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
()
self
.
th1
=
threading
.
Thread
(
target
=
rabbit_camera_model
)
.
start
()
self
.
th2
=
threading
.
Thread
(
target
=
rabbit_ai_task
)
.
start
()
app
=
Flask
(
__name__
,
static_url_path
=
''
,
...
...
@@ -195,6 +235,7 @@ worker.conf.update(
def
getRegionConfig
(
ipcSN
):
region
=
None
res
=
None
if
API_HOST
:
reqUrl
=
API_HOST
+
API_CAMERA_CFG_URI
.
format
(
ipcSN
)
try
:
if
ipcSN
in
CAMERA_CONFIG_MAP
and
type
(
CAMERA_CONFIG_MAP
[
ipcSN
])
is
dict
:
...
...
@@ -208,7 +249,7 @@ def getRegionConfig(ipcSN):
CAMERA_CONFIG_MAP
[
ipcSN
]
=
ret
[
"data"
]
if
CAMERA_CONFIG_MAP
.
get
(
ipcSN
)
is
None
:
CAMERA_CONFIG_MAP
[
ipCSN
]
=
0
print
(
"getRegionConfig: {}, {}, {}: {}"
.
format
(
ipcSN
,
reqUrl
,
res
.
text
if
res
and
(
text
in
res
)
else
None
,
json
.
dumps
(
region
)))
print
(
"getRegionConfig: {}, {}, {}: {}"
.
format
(
ipcSN
,
reqUrl
,
res
.
text
if
res
and
(
'text'
in
res
)
else
None
,
json
.
dumps
(
region
)))
except
Exception
as
e
:
print
(
"failed to get camera config {}: {}"
.
format
(
ipcSN
,
e
))
return
region
...
...
@@ -316,11 +357,24 @@ def video_analysis(data):
mc
.
username_pw_set
(
username
=
MQTT_USER
,
password
=
MQTT_PASSWORD
)
mc
.
connect
(
MQTT_HOST
,
MQTT_PORT
)
mc
.
publish
(
'video.ai/v1.0/result'
,
json
.
dumps
(
ret
),
qos
=
1
)
print
(
"mqtt message published"
)
# rabbitmq
if
RABBITMQ_URI
:
parameters
=
pika
.
URLParameters
(
RABBITMQ_URI
)
connection
=
pika
.
BlockingConnection
(
parameters
)
rabChanResult
=
connection
.
channel
()
rabChanResult
.
exchange_declare
(
exchange
=
AI_EXCHANGE
,
exchange_type
=
"direct"
)
rabChanResult
.
queue_declare
(
queue
=
AI_QUEUE_RESULT
,
durable
=
True
)
rabChanResult
.
queue_bind
(
exchange
=
AI_EXCHANGE
,
queue
=
AI_QUEUE_RESULT
,
routing_key
=
AI_QUEUE_RESULT
)
rabChanResult
.
basic_publish
(
exchange
=
AI_EXCHANGE
,
routing_key
=
AI_QUEUE_RESULT
,
body
=
json
.
dumps
(
ret
),
properties
=
pika
.
BasicProperties
(
delivery_mode
=
2
))
print
(
"rabbitmq message published"
)
rabChanResult
.
close
()
try
:
os
.
system
(
'rm -fr '
+
downloadDir
)
except
Exception
as
e
:
print
(
'cascaded exception in va: {}'
.
format
(
e
))
#raise Exception()
return
ret
...
...
opencv-yolo/web/web_rabbit.py
deleted
100644 → 0
浏览文件 @
7b282b1f
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论