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 个修改的文件
包含
85 行增加
和
31 行删除
+85
-31
web.py
opencv-yolo/web/web.py
+85
-31
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/{}/
...
@@ -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_URI
=
os
.
getenv
(
"RABBITMQ_URI"
,
"amqp://guest:guest@localhost:5672/"
)
RABBITMQ_TOPIC
=
os
.
getenv
(
"RABBITMQ_TOPIC"
,
"*.camera.model"
)
RABBITMQ_TOPIC
=
os
.
getenv
(
"RABBITMQ_TOPIC"
,
"*.camera.model"
)
RABBITMQ_EXHANGE
=
os
.
getenv
(
"RABBITMQ_EXHANGE"
,
"video"
)
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
=
{}
CAMERA_CONFIG_MAP
=
{}
def
rabCallback
(
ch
,
method
,
prop
,
body
):
def
rab
Model
Callback
(
ch
,
method
,
prop
,
body
):
try
:
try
:
print
(
"received rabbitmsg. routing key: {} , body: {}"
.
format
(
method
.
routing_key
,
body
))
print
(
"received rabbitmsg. routing key: {} , body: {}"
.
format
(
method
.
routing_key
,
body
))
rk
=
method
.
routing_key
.
split
(
'.'
)
rk
=
method
.
routing_key
.
split
(
'.'
)
...
@@ -85,25 +89,56 @@ def rabCallback(ch, method, prop, body):
...
@@ -85,25 +89,56 @@ def rabCallback(ch, method, prop, body):
CAMERA_CONFIG_MAP
[
sn
]
=
json
.
loads
(
body
)
CAMERA_CONFIG_MAP
[
sn
]
=
json
.
loads
(
body
)
print
(
"CAMERA_CONFIG_MAP:
\n
{}"
.
format
(
json
.
dumps
(
CAMERA_CONFIG_MAP
)))
print
(
"CAMERA_CONFIG_MAP:
\n
{}"
.
format
(
json
.
dumps
(
CAMERA_CONFIG_MAP
)))
except
Exception
as
e
:
except
Exception
as
e
:
#extype, value, tb = sys.exc_info()
#traceback.print_exc()
#traceback.print_exc()
#pdb.post_mortem(tb)
#pdb.post_mortem(tb)
print
(
"failed to process callback {}: {} - {}"
.
format
(
e
,
method
,
body
))
print
(
"failed to process callback {}: {} - {}"
.
format
(
e
,
method
,
body
))
def
initRabbit
():
def
rabAiTaskCallback
(
ch
,
method
,
prop
,
body
):
rabChan
=
None
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
:
if
RABBITMQ_URI
:
print
(
"connecting rabbitmq {}"
.
format
(
RABBITMQ_URI
))
print
(
"connecting rabbitmq {}"
.
format
(
RABBITMQ_URI
))
parameters
=
pika
.
URLParameters
(
RABBITMQ_URI
)
#("amqp://ilabservice:iLabServiceOps123456@40.73.40.246:5672/")
parameters
=
pika
.
URLParameters
(
RABBITMQ_URI
)
#("amqp://ilabservice:iLabServiceOps123456@40.73.40.246:5672/")
connection
=
pika
.
BlockingConnection
(
parameters
)
connection
=
pika
.
BlockingConnection
(
parameters
)
rabChan
=
connection
.
channel
()
print
(
"rabbitmq connection established"
)
rabChan
.
exchange_declare
(
exchange
=
RABBITMQ_EXHANGE
,
exchange_type
=
"topic"
)
qr
=
rabChan
.
queue_declare
(
''
,
durable
=
True
)
# camera model channel
rabChan
.
queue_bind
(
exchange
=
RABBITMQ_EXHANGE
,
rabChanModel
=
connection
.
channel
()
queue
=
qr
.
method
.
queue
,
routing_key
=
RABBITMQ_TOPIC
)
rabChanModel
.
exchange_declare
(
exchange
=
RABBITMQ_EXHANGE
,
exchange_type
=
"topic"
)
rabChan
.
basic_consume
(
modelQueue
=
rabChanModel
.
queue_declare
(
''
,
durable
=
True
)
queue
=
qr
.
method
.
queue
,
on_message_callback
=
rabCallback
,
auto_ack
=
True
)
rabChanModel
.
queue_bind
(
exchange
=
RABBITMQ_EXHANGE
,
return
rabChan
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
)
# 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
(
print
(
"CONFIG:
\n\t
MQTT: {}:{}
\n\t
BIN_NAME: {}"
.
format
(
MQTT_HOST
,
MQTT_PORT
,
binName
))
MQTT_HOST
,
MQTT_PORT
,
binName
))
...
@@ -128,6 +163,10 @@ def uploadFile(ipcSn, dirName, fileName, srcPath):
...
@@ -128,6 +163,10 @@ def uploadFile(ipcSn, dirName, fileName, srcPath):
class
VAMMQTTClient
:
class
VAMMQTTClient
:
rabChanModel
=
None
rabChanAiTask
=
None
th1
=
None
th2
=
None
# The callback for when the client receives a CONNACK response from the server.
# The callback for when the client receives a CONNACK response from the server.
@staticmethod
@staticmethod
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
...
@@ -173,8 +212,9 @@ class VAMMQTTClient:
...
@@ -173,8 +212,9 @@ class VAMMQTTClient:
self
.
client
.
on_message
=
VAMMQTTClient
.
on_message
self
.
client
.
on_message
=
VAMMQTTClient
.
on_message
self
.
client
.
connect_async
(
host
,
port
,
30
)
self
.
client
.
connect_async
(
host
,
port
,
30
)
self
.
client
.
loop_start
()
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__
,
app
=
Flask
(
__name__
,
static_url_path
=
''
,
static_url_path
=
''
,
...
@@ -195,22 +235,23 @@ worker.conf.update(
...
@@ -195,22 +235,23 @@ worker.conf.update(
def
getRegionConfig
(
ipcSN
):
def
getRegionConfig
(
ipcSN
):
region
=
None
region
=
None
res
=
None
res
=
None
reqUrl
=
API_HOST
+
API_CAMERA_CFG_URI
.
format
(
ipcSN
)
if
API_HOST
:
try
:
reqUrl
=
API_HOST
+
API_CAMERA_CFG_URI
.
format
(
ipcSN
)
if
ipcSN
in
CAMERA_CONFIG_MAP
and
type
(
CAMERA_CONFIG_MAP
[
ipcSN
])
is
dict
:
try
:
region
=
CAMERA_CONFIG_MAP
[
ipcSN
][
'region'
]
if
ipcSN
in
CAMERA_CONFIG_MAP
and
type
(
CAMERA_CONFIG_MAP
[
ipcSN
])
is
dict
:
elif
CAMERA_CONFIG_MAP
.
get
(
ipcSN
)
is
None
and
API_HOST
:
region
=
CAMERA_CONFIG_MAP
[
ipcSN
][
'region'
]
res
=
requests
.
get
(
reqUrl
)
elif
CAMERA_CONFIG_MAP
.
get
(
ipcSN
)
is
None
and
API_HOST
:
if
res
.
status_code
==
200
:
res
=
requests
.
get
(
reqUrl
)
ret
=
res
.
json
()
if
res
.
status_code
==
200
:
if
'data'
in
ret
and
'region'
in
ret
[
'data'
]:
ret
=
res
.
json
()
region
=
ret
[
"data"
][
"region"
]
if
'data'
in
ret
and
'region'
in
ret
[
'data'
]:
CAMERA_CONFIG_MAP
[
ipcSN
]
=
ret
[
"data"
]
region
=
ret
[
"data"
][
"region"
]
if
CAMERA_CONFIG_MAP
.
get
(
ipcSN
)
is
None
:
CAMERA_CONFIG_MAP
[
ipcSN
]
=
ret
[
"data"
]
CAMERA_CONFIG_MAP
[
ipCSN
]
=
0
if
CAMERA_CONFIG_MAP
.
get
(
ipcSN
)
is
None
:
print
(
"getRegionConfig: {}, {}, {}: {}"
.
format
(
ipcSN
,
reqUrl
,
res
.
text
if
res
and
(
text
in
res
)
else
None
,
json
.
dumps
(
region
)))
CAMERA_CONFIG_MAP
[
ipCSN
]
=
0
except
Exception
as
e
:
print
(
"getRegionConfig: {}, {}, {}: {}"
.
format
(
ipcSN
,
reqUrl
,
res
.
text
if
res
and
(
'text'
in
res
)
else
None
,
json
.
dumps
(
region
)))
print
(
"failed to get camera config {}: {}"
.
format
(
ipcSN
,
e
))
except
Exception
as
e
:
print
(
"failed to get camera config {}: {}"
.
format
(
ipcSN
,
e
))
return
region
return
region
def
take_task
(
task
):
def
take_task
(
task
):
...
@@ -316,11 +357,24 @@ def video_analysis(data):
...
@@ -316,11 +357,24 @@ def video_analysis(data):
mc
.
username_pw_set
(
username
=
MQTT_USER
,
password
=
MQTT_PASSWORD
)
mc
.
username_pw_set
(
username
=
MQTT_USER
,
password
=
MQTT_PASSWORD
)
mc
.
connect
(
MQTT_HOST
,
MQTT_PORT
)
mc
.
connect
(
MQTT_HOST
,
MQTT_PORT
)
mc
.
publish
(
'video.ai/v1.0/result'
,
json
.
dumps
(
ret
),
qos
=
1
)
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
:
try
:
os
.
system
(
'rm -fr '
+
downloadDir
)
os
.
system
(
'rm -fr '
+
downloadDir
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
'cascaded exception in va: {}'
.
format
(
e
))
print
(
'cascaded exception in va: {}'
.
format
(
e
))
#raise Exception()
return
ret
return
ret
...
...
opencv-yolo/web/web_rabbit.py
deleted
100644 → 0
浏览文件 @
7b282b1f
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论