天天看点

使用Intel的EVAM微服务跑通demo-app应用,处理摄像头视频数据

作者:freewebsys

目录

  • 前言
  • 1,关于EVAM
  • 2,配置EVAM的docker-compose服务
  • 4,创建摄像头应用,启动web服务,端口 59750
  • 5,启动成功进入web界面
  • 6,总结

1,关于EVAM

是Intel 开发的组件库 Edge Video Analytics Microservice,边缘端的视频分析微服务。

官方网站:

https://www.intel.com/content/www/us/en/developer/articles/technical/video-analytics-service.html

github地址:

https://github.com/intel/edge-video-analytics-microservice

Docker Hub 地址:

https://hub.docker.com/r/intel/edge_video_analytics_microservice

版本区别:

0.7.2 Aligned with Intel® Deep Learning Streamer Pipeline Server 2022.1.1 release.

0.7.0 Initial release using Intel® Distribution of OpenVINO™ Toolkit 2021.4.2

当然使用 个 2022 版本的。

架构图,底层是OpenVINO的引擎,然后是Intel的深度学习框架,上面是Pipline和模型,然后是Streamer Pipeline 服务。在上面就是应用层。

使用Intel的EVAM微服务跑通demo-app应用,处理摄像头视频数据

2,配置EVAM的docker-compose服务

之前已经研究过一遍使用源码的方式自己编译docker镜像然后跑起来。

也可以成功:

就是构建速度慢,下载好多东西。这次直接使用镜像做服务:

docker-compose.yml

networks:
  edgex-network:
    driver: bridge
services:

  broker:
    image: eclipse-mosquitto
    hostname: mqtt
    container_name: mqtt-broker
    volumes:
      - ./mosquitto_conf:/mosquitto/config
    ports:
      - "1883:1883"
      - "59001:9001"
    networks:
      - edgex-network
  video-analytics-microservice:
    image: intel/edge_video_analytics_microservice:0.7.2
    hostname: edgex-video-analytics-microservice
    container_name: edgex-video-analytics-microservice
    privileged: true
    tty: true
    entrypoint: ["./run.sh"]
    ports:
      - '8080:8080'
      - '8554:8554'
    networks:
      - edgex-network
    environment:
      - ENABLE_RTSP=true
      - RTSP_PORT=8554
      - ENABLE_WEBRTC=true
      - WEBRTC_SIGNALING_SERVER=ws://localhost:59001
      - RUN_MODE=EVA
      # Default Detection and Classification Device
      - DETECTION_DEVICE=CPU
      - CLASSIFICATION_DEVICE=CPU
      - WRITABLE_INSECURESECRETS_CAMERACREDENTIALS_SECRETS_USERNAME=admin
      - WRITABLE_INSECURESECRETS_CAMERACREDENTIALS_SECRETS_PASSWORD=yhy363tp
    device_cgroup_rules:
    # Default run - device-cgroup-rule='c 189:* rmw'
    # NCS2 run - device-cgroup-rule='c 209:* rmw'
    # Selective rules can be applied for deployment
    - 'c 189:* rmw'
    - 'c 209:* rmw'
    devices:
    # Following devices under /dev filesystem will be needed based on usecase
    # dri - GPU
    # ion - VPU
    # USB camera devices
    # Selective mount can be done for deployment as mounting whole /dev is not recommended
    - "/dev:/dev"

version: '3.7'

           

在当前目录创建 mosquitto_conf/mosquitto.conf

需要再配置下 broker 的端口:开启 websocket服务

#
# Copyright (C) 2022 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

allow_anonymous true
listener 1883

log_type error
log_type warning
log_type notice
log_type information
log_type subscribe
log_type unsubscribe
log_type websockets

listener 9001
protocol websockets

           

然后就可以启动服务了

docker-compose up -d

           

4,创建摄像头应用,启动web服务,端口 59750

首先下载 edgex examples 项目

$ git clone https://github.com/edgexfoundry/edgex-examples.git
# 切换到 camera management 项目
$ cd edgex-examples/application-services/custom/camera-management/

           

配置摄像头凭证文件。输入账号密码。

$ vi res/configuration.toml 

# 设置账号密码
    # TODO: Enter your camera's credentials here.
    # NOTE: currently this solution is limited to supporting only 1 username/password combination
    #       for ALL cameras. In the future when then device-onvif-camera service is able to provide
    #       us with pre-authenticated uris, this can be removed.
    [Writable.InsecureSecrets.CameraCredentials]
    path = "CameraCredentials"
      [Writable.InsecureSecrets.CameraCredentials.Secrets]
      username = "admin"
      password = "password"
           

需要golang 环境:

https://golang.google.cn/doc/install

首先删除之前的老版本的文件,然后在解压缩到/usr/local目录下面:需要root权限

$ sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.19.2.linux-amd64.tar.gz

$ vi $HOME/.bashrc
增加环境变量
# add golang
export PATH=$PATH:/data/local/go/bin
# 增加代理,下载提速
export GO111MODULE=on
export GOPROXY=https://goproxy.cn

测试
$ go version
go version go1.19.2 linux/amd64
           

安装工具和依赖:

# 需要安装工具 pkg-config
$ sudo apt install pkg-config
# 安装 zeromq 依赖开发工具包:
$ sudo apt-get install libzmq3-dev

           

执行构建,没有任何问题代表构建成功!

$ make build-app 
go mod tidy
CGO_ENABLED=1 go build -ldflags "-X github.com/edgexfoundry/app-functions-sdk-go/v2/internal.SDKVersion=v2.2.0 -X github.com/edgexfoundry/app-functions-sdk-go/v2/internal.ApplicationVersion=0.0.0" -o app-camera-management
           
$ make run-app 
EDGEX_SECURITY_SECRET_STORE=false ./app-camera-management
.....
level=INFO ts=2022-10-19T08:31:46.13384954Z app=app-camera-management source=service.go:202 msg="StoreAndForward disabled. Not running retry loop."
level=INFO ts=2022-10-19T08:31:46.133856645Z app=app-camera-management source=service.go:205 msg="Camera Management Application Service has started"
level=INFO ts=2022-10-19T08:31:46.133863725Z app=app-camera-management source=server.go:162 msg="Starting HTTP Web Server on address 0.0.0.0:59750"

           

5,启动成功进入web界面

http://localhost:59750

特别需要注意的是这个分辨率。

2304x1296 H264 @ 25 fps

640x480 H264 @ 25 fps

选择下面的640 分辨率,否则太高了,会报错,Picture size 0x0 is invalid

不能查看摄像的实时处理结果了

Input #0, rtsp, from 'rtsp://localhost:8554/Camera001':
  Metadata:
    title           : Session streamed with GStreamer
    comment         : rtsp-server
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0: Video: mjpeg (Baseline), none(bt470bg/unknown/unknown), 90k tbr, 90k tbn, 90k tbc
[mjpeg @ 0x7f5e4000b480] [IMGUTILS @ 0x7f5e3bffdcd0] Picture size 0x0 is invalid
    Last message repeated 18 times
[mjpeg @ 0x7f5e4000b480] [IMGUTILS @ 0x7f5e3bffdcd0] Picture size 0x0 is invalid
           

实时查看流结果地址。就是带框框的视频流。

# 需要安装 ffmpeg # 
sudo apt install ffmpeg
ffplay -rtsp_transport tcp rtsp://localhost:8554/Camera001

           
使用Intel的EVAM微服务跑通demo-app应用,处理摄像头视频数据
使用Intel的EVAM微服务跑通demo-app应用,处理摄像头视频数据

在工位,没有车辆行人的视频,用截图代替了。

使用Intel的EVAM微服务跑通demo-app应用,处理摄像头视频数据
使用Intel的EVAM微服务跑通demo-app应用,处理摄像头视频数据

6,总结

使用Intel的 EVAM 微服务,创建OpenVINO的目标检测跟踪服务,并成功接受到相关坐标数据。

这个官方例子还是非常的丰富的。稍作修改下就可以应用到项目当中了,已经把相关的目标检测模型都放到 OpenVINO 中,

封装成一个docker 服务器启动了。整个流程也通过配置下就可以了。

非常的方便、简单、高效的边缘演示服务!

继续阅读