尝试将DeepStream SDK的物体检测结果通过Kafka与Node-RED进行集成

首先

在这篇文章中,我们将根据下面的图示在Jetson TX2上配置Kafka和Node-RED,并解释将DeepStream的输出与Kafka和Node-RED进行协同的步骤。

构成图

image.png

完成图像

out.gif

环境信息

Jetson TX2 is translated as 杰逊TX2 in Chinese.
Jetpack 4.3 is translated as Jetpack 4.3版本 in Chinese.
カメラ:LOGICOOL HD PRO WEBCAM C920 can be translated as 摄像头:LOGICOOL HD PRO WEBCAM C920 in Chinese.
Kafka 2.4.0 remains as Kafka 2.4.0 in Chinese.
Node-RED 1.0.3 stays as Node-RED 1.0.3 in Chinese.
Node.js 12.14.1 is translated as Node.js 12.14.1版本 in Chinese.

概述步骤

    1. Kafka配置

 

    1. Node-RED配置

 

    DeepStream示例应用程序启动

1. 设置卡夫卡

1-1. Java的引入

为了运行Kafka,需要安装Java,所以将其引入。

$ sudo apt install openjdk-11-jre
$ java --version

1-2. Kafka的安装和启动

参考以下的 Kafka 快速入门步骤,安装并启动单节点 Kafka。
https://kafka.apache.org/quickstart

从以下网站下载Kafka的代码:
https://www.apache.org/dyn/closer.cgi?path=/kafka/2.4.0/kafka_2.12-2.4.0.tgz

我会解冻。

$ tar -xzf kafka_2.12-2.4.0.tgz

启动zookeeper。保持已经启动的zookeeper终端运行。

$ cd kafka_2.12-2.4.0
$ bin/zookeeper-server-start.sh config/zookeeper.properties

请启动Kafka服务器,并保持启动该服务器的终端保持打开状态。

$ cd kafka_2.12-2.4.0
$ bin/kafka-server-start.sh config/server.properties

我要创建一个话题。在这篇文章中,我要创建一个名为“测试”的话题。

$ cd kafka_2.12-2.4.0
$ bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
$ bin/kafka-topics.sh --list --bootstrap-server localhost:9092

2. Node-RED安装

2-1. 安装Node.js

Node.js的安装可以参考以下文章。
在TX2上也可以按照相同的步骤进行安装。

使用以下命令安装Node.js。

$ sudo apt install -y nodejs npm
$ sudo npm install n -g
$ sudo n stable
$ sudo apt purge -y nodejs npm
$ exec $SHELL -l
$ node -v
$ npm -v

2-2. 安装和启动Node-RED

在安装Node-RED时,执行以下Node-RED文档中提供的命令即可。

Node-RED文档
https://nodered.org/docs/getting-started/local#使用npm进行安装

执行以下命令,安装Node-RED。

sudo npm install -g --unsafe-perm node-red

请使用以下命令启动Node-RED。

$ node-red
image.png
image.png

选择“安装”选项卡,搜索“kafka”,并安装“node-red-contrib-kafka-manager”。

image.png

可以确认左边的调色板上已经添加了「Kafka Consumer」和「Kafka Producer」。

image.png

2-3. 创建Node-RED的流程

image.png
image.png
image.png
image.png
image.png
image.png

3. 启动DeepStream示例应用程序

将DeepStream的示例代码和配置文件复制。

将示例代码和配置文件复制到工作目录中。

$ mkdir ~/work
$ cp -r /opt/nvidia/deepstream/deepstream-4.0/samples ~/work
$ cp -r /opt/nvidia/deepstream/deepstream-4.0/sources/ ~/work

3-2. 检查网络摄像头

使用l4l2-ctl命令确认Web摄像头已连接。
从下面的示例可以看出它已连接到/dev/video0。

$ v4l2-ctl --list-devices
vi-output, ov5693 2-0036 (platform:15700000.vi:2):
    /dev/video1

HD Pro Webcam C920 (usb-3530000.xhci-2):
    /dev/video0

3-3. 文件組成

根据样本配置文件test5_config_file_src_infer.txt的参考,创建一个名为test5_config_usb_src_infer.txt的配置文件。

$ cd ~/work/sources/apps/sample_apps/deepstream-test5/configs/
$ ls
$ vi test5_config_file_src_infer.txt

构成文件的内容如下所示。
请注意有两点。
– “camera-v4l2-dev-node” 中设置的号码应为在上一步中确认的 /dev/videoX 的号码。
– 将 camera-fps-n 设置为 30 会导致处理延迟,因此请将摄像头输入设置为 15FPS。

[application]
enable-perf-measurement=1
perf-measurement-interval-sec=5
#gie-kitti-output-dir=streamscl

[tiled-display]
enable=1
rows=1
columns=1
width=640
height=360
gpu-id=0
#(0): nvbuf-mem-default - Default memory allocated, specific to particular platform
#(1): nvbuf-mem-cuda-pinned - Allocate Pinned/Host cuda memory, applicable for Tesla
#(2): nvbuf-mem-cuda-device - Allocate Device cuda memory, applicable for Tesla
#(3): nvbuf-mem-cuda-unified - Allocate Unified cuda memory, applicable for Tesla
#(4): nvbuf-mem-surface-array - Allocate Surface Array memory, applicable for Jetson
nvbuf-memory-type=0

[source0]
enable=1
#Type - 1=CameraV4L2 2=URI 3=MultiURI
type=1
camera-width=640
camera-height=360
camera-fps-n=15
camera-fps-d=1
camera-v4l2-dev-node=0

[sink0]
enable=1
#Type - 1=FakeSink 2=EglSink 3=File
type=2
sync=1
source-id=0
gpu-id=0
nvbuf-memory-type=0

[sink1]
enable=1
#Type - 1=FakeSink 2=EglSink 3=File 4=UDPSink 5=nvoverlaysink 6=MsgConvBroker
type=6
msg-conv-config=dstest5_msgconv_sample_config.txt
#(0): PAYLOAD_DEEPSTREAM - Deepstream schema payload
#(1): PAYLOAD_DEEPSTREAM_MINIMAL - Deepstream schema payload minimal
#(256): PAYLOAD_RESERVED - Reserved type
#(257): PAYLOAD_CUSTOM   - Custom schema payload
msg-conv-payload-type=0
msg-broker-proto-lib=/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_kafka_proto.so
#Provide your msg-broker-conn-str here
msg-broker-conn-str=127.0.0.1;9092;test
topic=test
#Optional:
#msg-broker-config=../../deepstream-test4/cfg_kafka.txt

[sink2]
enable=0
type=3
#1=mp4 2=mkv
container=1
#1=h264 2=h265 3=mpeg4
## only SW mpeg4 is supported right now.
codec=3
sync=1
bitrate=2000000
output-file=out.mp4
source-id=0

[osd]
enable=1
gpu-id=0
border-width=1
text-size=15
text-color=1;1;1;1;
text-bg-color=0.3;0.3;0.3;1
font=Arial
show-clock=0
clock-x-offset=800
clock-y-offset=820
clock-text-size=12
clock-color=1;0;0;0
nvbuf-memory-type=0

[streammux]
gpu-id=0
##Boolean property to inform muxer that sources are live
live-source=0
batch-size=4
##time out in usec, to wait after the first buffer is available
##to push the batch even if the complete batch is not formed
batched-push-timeout=40000
## Set muxer output width and height
width=1920
height=1080
##Enable to maintain aspect ratio wrt source, and allow black borders, works
##along with width, height properties
enable-padding=0
nvbuf-memory-type=0

[primary-gie]
enable=1
gpu-id=0
batch-size=4
## 0=FP32, 1=INT8, 2=FP16 mode
bbox-border-color0=1;0;0;1
bbox-border-color1=0;1;1;1
bbox-border-color2=0;1;1;1
bbox-border-color3=0;1;0;1
nvbuf-memory-type=0
interval=0
gie-unique-id=1
model-engine-file=../../../../../samples/models/Primary_Detector/resnet10.caffemodel_b4_int8.engine
labelfile-path=../../../../../samples/models/Primary_Detector/labels.txt
config-file=../../../../../samples/configs/deepstream-app/config_infer_primary.txt
#infer-raw-output-dir=../../../../../samples/primary_detector_raw_output/

[tracker]
enable=1
tracker-width=600
tracker-height=300
ll-lib-file=/opt/nvidia/deepstream/deepstream-4.0/lib/libnvds_mot_klt.so
#ll-config-file required for DCF/IOU only
#ll-config-file=tracker_config.yml
#ll-config-file=iou_config.txt
gpu-id=0
#enable-batch-process applicable to DCF only
enable-batch-process=0

[tests]
file-loop=0

3-4. 启动DeepStream示例应用程序

请使用以下命令启动示例应用程序。

cd ~/work/sources/apps/sample_apps/deepstream-test5/configs/
$ deepstream-test5-app -c test5_config_usb_src_infer.txt 

3-5.确认结果

out.gif

总结

我已确认只需进行简单设置即可实现DeepStream SDK和Node-RED的协同操作。

广告
将在 10 秒后关闭
bannerAds