天天看點

使用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 伺服器啟動了。整個流程也通過配置下就可以了。

非常的友善、簡單、高效的邊緣示範服務!

繼續閱讀