diff --git a/contrib/MonocularDepthEstimation/README.md b/contrib/MonocularDepthEstimation/README.md index 7f804b284e62def1f761585ccc28e84f2d0aed7e..73d326e9e5d5414de4f24a1d975d788c875203d1 100644 --- a/contrib/MonocularDepthEstimation/README.md +++ b/contrib/MonocularDepthEstimation/README.md @@ -1,188 +1,38 @@ -# 基于MxStream的AdaBins单目深度估计 +# 基于MxVision的AdaBins单目深度估计 ## 1 介绍 -基于AdaBins室内模型的单目深度估计,输出输入图像的深度图 \ -样例输入:室内图片(如果要得到输出大小和输入完全一致的深度图,请输入宽 320 * n,高 240 * n 的图片)\ -样例输出:输入图片的深度图(灰度图形式) +### 1.1 简介 +本案例是基于AdaBins室内模型的单目深度估计,输出为对应输入图像的深度图(灰度图形式)。 -### 1.1 支持的产品 -昇腾310(推理) +### 1.2 支持的产品 +Atlas 300I pro、Atlas 300V pro -### 1.2 支持的版本 -本样例配套的CANN版本为 [5.0.4](https://www.hiascend.com/software/cann/commercial) ,MindX SDK版本为 [2.0.4](https://www.hiascend.com/software/Mindx-sdk) 。 +### 1.3 支持的版本 +本样例配套的MxVision版本、CANN版本、Driver/Firmware版本如下所示: +| MxVision版本 | CANN版本 | Driver/Firmware版本 | +| --------- | ------------------ | -------------- | +| 6.0.RC3 | 8.0.RC3 | 24.1.RC3 | -MindX SDK安装前准备可参考《用户指南》,[安装教程](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/quickStart/1-1安装SDK开发套件.md) - -### 1.3 目录结构 +## 2 设置环境变量 ``` -. -|-------- depth_estimation -| |---- monocular_depth_estimation.py // 基于MxStream和Adabins模型的深度估计实现 -|-------- image -| |---- test.jpg // 测试的室内图片(需自行准备) -|-------- model -| |---- aipp_adabins_640_480.aippconfig // Adabins 模型转换配置文件 -| |---- model_conversion.sh // 模型转换脚本 -|-------- pipeline -| |---- depth_estimation.pipeline // 深度估计的pipeline文件 -|-------- result // 深度图结果或模型精度结果存放处 -|-------- test_set -| |---- image // 测试集图片(需自行准备) -| |---- depth_info // 测试集图片深度信息(需自行准备) -|-------- util -| |---- data_process.py // 处理测试集数据 -| |---- util.py // 公共方法 -|-------- evaluate.py // 模型精度验证 -|-------- main.py // 单目深度估计样例 -|-------- README.md // ReadMe -|-------- run.sh // 样例运行脚本 - +. /usr/local/Ascend/ascend-toolkit/set_env.sh #CANN默认安装路径,根据实际安装路径修改 +. ${SDK_INSTALL_PATH}/mxVision/set_env.sh #根据实际SDK安装路径修改 ``` -## 2 环境依赖 - -### 2.1 软件版本 -| 软件 | 版本 | 说明 | 获取方式 | -| ------------------- | ------------ | ----------------------------- | ------------------------------------------------------------ | -| mxVision | 2.0.4 | mxVision软件包 | [链接](https://www.hiascend.com/software/Mindx-sdk) | -| Ascend-CANN-toolkit | 5.0.4 | Ascend-cann-toolkit开发套件包 | [链接](https://www.hiascend.com/software/cann/commercial) | -| 操作系统 | Ubuntu 18.04 | 操作系统 | Ubuntu官网获取 | - - -### 2.2 准备工作 - -> 模型转换 -**步骤1** 在 [GitHub AdaBins](https://github.com/shariqfarooq123/AdaBins) 上下载预训练模型 [AdaBins_nyu.pt](https://drive.google.com/drive/folders/1nYyaQXOBjNdUJDsmJpcRpu6oE55aQoLA) , -或者直接下载已经转换好的 [AdaBins_nyu.onnx](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/MonocularDepthEstimation/AdaBins_nyu.onnx) ,跳过 **步骤2** 直接进入om模型的转换 - -**步骤2** 将获取到的 `AdaBins_nyu.pt` 转换为 `AdaBins_nyu.onnx`, [参考链接](https://blog.csdn.net/ApathyT/article/details/120834163) - -**步骤3** 将转换或下载得到的 `AdaBins_nyu.onnx` 放在 `model` 目录下 - -**步骤4** 运行模型转换脚本 `model_conversion.sh` 或在 `model` 目录下执行以下命令 +## 3 准备模型 +**步骤1**:下载模型:[下载链接](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/MonocularDepthEstimation/AdaBins_nyu.onnx),将获取到的.onnx文件存放至本案例代码的MonocularDepthEstimation/model 目录下。 +**步骤2**:进入MonocularDepthEstimation/model目录执行以下命令。 ``` -# 设置环境变量(请确认install_path路径是否正确) -# Set environment PATH (Please confirm that the install_path is correct). - -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.9.2/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg -export LD_LIBRARY_PATH=${install_path}/atc/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp - -# 执行,转换AdaBins模型 -# Execute, transform AdaBins model. - -atc --model=./AdaBins_nyu.onnx --framework=5 --output=./AdaBins_nyu.om --soc_version=Ascend310 --insert_op_conf=./aipp_adabins_640_480.aippconfig --log=error +atc --model=./AdaBins_nyu.onnx --framework=5 --output=./AdaBins_nyu --soc_version=Ascend310P3 --insert_op_conf=./aipp_adabins_640_480.aippconfig --log=error ``` -执行完模型转换脚本后,会生成相应的.om模型文件。 - -模型转换使用了ATC工具,如需更多信息请参考: - - https://gitee.com/ascend/docs-openmind/blob/master/guide/mindx/sdk/tutorials/%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99.md - -> 相关参数修改 - -**通用配置** -1) [depth_estimation.pipeline](./pipeline/depth_estimation.pipeline) 中配置 `AdaBin_nyu.om` 模型路径 -``` -"mxpi_tensorinfer0": { - "props": { - "dataSource": "mxpi_imageresize0", - "modelPath": "${ AdaBin_nyu.om 模型路径}" - }, - "factory": "mxpi_tensorinfer", - "next": "appsink0" - } -``` -2) [monocular_depth_estimation.py](./depth_estimation/monocular_depth_estimation.py) 中配置模型的实际输出宽高 -```python -# depth estimation model output size -model_output_height = 240 -model_output_width = 320 -``` +## 4 编译与运行 +**步骤1**:准备输入图片:将输入图片命名为test.jpg放入项目根目录下 -**推理配置** -1) 准备一张室内图片,置于 [image](./image) 文件夹中 -2) [main.py](./main.py) 中配置 `input_image_path` 和 `output_result_path` +**步骤2**:运行: ``` - input_image_path = 'image/${测试图片文件名}' # 仅支持jpg格式 - output_result_path = "result/${输出结果文件名}" -``` - -**精度测试配置** -1) 下载测试集数据( [下载地址](http://horatio.cs.nyu.edu/mit/silberman/nyu_depth_v2/nyu_depth_v2_labeled.mat) ), - 置于 [test_set](./test_set) 文件夹下,检查文件名是否为 `nyu_depth_v2_labeled.mat` -2) 运行 [data_process.py](./util/data_process.py),处理完毕后的图片位于 [test_set/image](./test_set/image) 文件夹下, - 深度信息位于 [test_set/depth_info](./test_set/depth_info) 文件夹下 -3) [evaluate.py](./evaluate.py) 中配置测试集图片大小 +python3 main.py ``` - # test set image size - test_image_height = ${测试集图片的高} - test_image_width = ${测试集图片的宽} -``` -4) [evaluate.py](./evaluate.py) 其他可选配置项 -``` - # thresholds for accuracy - threshold_1 = 1.25 - threshold_2 = 1.25 ** 2 - threshold_3 = 1.25 ** 3 -``` - -### 2.3 配置环境变量 - -```bash -# 执行如下命令,打开.bashrc文件 -cd $HOME -vi .bashrc -# 在.bashrc文件中添加以下环境变量 -MX_SDK_HOME=${SDK安装路径} - -LD_LIBRARY_PATH=${MX_SDK_HOME}/lib:${MX_SDK_HOME}/opensource/lib:${MX_SDK_HOME}/opensource/lib64:/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:/usr/local/Ascend/driver/lib64/ - -GST_PLUGIN_SCANNER=${MX_SDK_HOME}/opensource/libexec/gstreamer-1.0/gst-plugin-scanner - -GST_PLUGIN_PATH=${MX_SDK_HOME}/opensource/lib/gstreamer-1.0:${MX_SDK_HOME}/lib/plugins - -PYTHONPATH=${MX_SDK_HOME}/python - -# 保存退出.bashrc文件 -# 执行如下命令使环境变量生效 -source ~/.bashrc - -# 查看环境变量 -env -``` - -## 3 运行 -手动运行请参照 ①, 脚本运行请参照 ② -> ① 手动运行前请确保每一步环境变量均配置完成,随后进入工程目录,键入执行指令 -```bash -# 进入工程目录 -cd MonocularDepthEstimation - -# 图片深度估计 -python3 main.py ${测试图片路径} ${输出结果路径} -ex: python3 main.py image/test.jpg result/result.jpg - -# AdaBins_nyu 模型精度验证 -python3 evaluate.py -``` - -> ② 脚本运行请先赋予可执行权限 -```bash -# 赋予可执行权限 -chmod +x run.sh - -# 说明:-m 运行模式 {infer | evaluate} -i infer模式下输入图片的路径 -o infer模式下输出结果的路径 -# 推理模式 -bash run.sh -m infer -i image/test.jpg -o result/result.jpg -# 精度验证模式 -bash run.sh -m evaluate -``` - -## 4 查看结果 -执行`run.sh`完毕后,sample会将**图片深度信息**或**模型精度结果**保存在工程目录下`result`中。 \ No newline at end of file +**步骤3**:查看结果:会在当前目录生成result.jpg \ No newline at end of file diff --git a/contrib/MonocularDepthEstimation/main.py b/contrib/MonocularDepthEstimation/main.py index 934230a2d72b1063cc6507ee054403a5f393b15f..b4a5790f69794625df5d7858e83a5917af3e4db9 100644 --- a/contrib/MonocularDepthEstimation/main.py +++ b/contrib/MonocularDepthEstimation/main.py @@ -27,32 +27,8 @@ from util.util import colorize if __name__ == '__main__': - input_image_path = 'image/${测试图片文件名}' - output_result_path = "result/${输出结果文件名}" - - # parse command arguments - if len(sys.argv) == 2: - if sys.argv[1] == '': - print('input image path is valid, use default config.') - else: - input_image_path = sys.argv[1] - print('no output result path, use default config.') - elif len(sys.argv) == 3: - if sys.argv[1] == '': - print('input image path is valid, use default config.') - else: - input_image_path = sys.argv[1] - if sys.argv[2] == '': - print('output result path is valid, use default config.') - else: - output_result_path = sys.argv[2] - else: - print("Please enter at least image path, " - "such as 'python3 main.py image/test.jpg' or 'bash run.sh -m infer -i image/test.jpg'.") - print('no input image path and output result path, use default config.') - - print('input image path: {}.'.format(input_image_path)) - print('output result path: {}.'.format(output_result_path)) + input_image_path = './test.jpg' + output_result_path = "./result.jpg" # check input image input_valid = False diff --git a/contrib/MonocularDepthEstimation/model/model_conversion.sh b/contrib/MonocularDepthEstimation/model/model_conversion.sh deleted file mode 100644 index 76c612802dc92c725ee8545af004eeb127b392c3..0000000000000000000000000000000000000000 --- a/contrib/MonocularDepthEstimation/model/model_conversion.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# Copyright(C) 2021. Huawei Technologies Co.,Ltd. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -e - -# 该脚本用来将onnx模型文件转换成.om模型文件 -# This is used to convert onnx model file to .om model file. - - -# 设置环境变量(请确认install_path路径是否正确) -# Set environment PATH (Please confirm that the install_path is correct). - -export install_path=/usr/local/Ascend/ascend-toolkit/latest -export PATH=/usr/local/python3.9.2/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH -export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg -export LD_LIBRARY_PATH=${install_path}/atc/lib64:$LD_LIBRARY_PATH -export ASCEND_OPP_PATH=${install_path}/opp - - -# 执行,转换Adabins_nyu模型 -# Execute, transform Adabins_nyu model. - -atc --model=./AdaBins_nyu.onnx --framework=5 --output=./AdaBins_nyu.om --soc_version=Ascend310 --insert_op_conf=./aipp_adabins_640_480.aippconfig --log=error - -# 退出 -# exit -exit 0 \ No newline at end of file diff --git a/contrib/MonocularDepthEstimation/pipeline/depth_estimation.pipeline b/contrib/MonocularDepthEstimation/pipeline/depth_estimation.pipeline index 7da5941a82fdaed993e70265c5fa8c73839b4ae9..0eafba4fec1802ac06dad46b78772d9b74478512 100644 --- a/contrib/MonocularDepthEstimation/pipeline/depth_estimation.pipeline +++ b/contrib/MonocularDepthEstimation/pipeline/depth_estimation.pipeline @@ -29,7 +29,7 @@ "mxpi_tensorinfer0": { "props": { "dataSource": "mxpi_imageresize0", - "modelPath": "${ AdaBin_nyu.om 模型路径}" + "modelPath": "./model/AdaBins_nyu.om" }, "factory": "mxpi_tensorinfer", "next": "appsink0" diff --git a/contrib/PassengerflowEstimation/README.md b/contrib/PassengerflowEstimation/README.md index fa84cd2d57ac0cf1434a79326096c197ceaba119..a96f8218007f63bf99008a52025661dd502d9199 100644 --- a/contrib/PassengerflowEstimation/README.md +++ b/contrib/PassengerflowEstimation/README.md @@ -1,252 +1,88 @@ # passengerflowestimation客流量检测 -## 1介绍 +## 1 介绍 -passengerflowestimation基于MindXSDK开发,在昇腾芯片上进行客流量统计,将最后统计得到的客流量结果在终端内显示。输入一段视频,最后可以得出在某一时间内的客流量。 +### 1.1 简介 +passengerflowestimation基于MindXSDK开发,在昇腾芯片上进行客流量统计,输入一段视频,最后可以得出在某一时间内的客流量。本项目适用于俯视角度较大,并且人流量不是非常密集的视频中人流量统计。 -### 1.1支持的产品 +### 1.2 支持的产品 +Atlas 300I pro、Atlas 300V pro -本产品以昇腾310(推理)卡为硬件平台。 +### 1.3 支持的版本 +本样例配套的MxVision版本、CANN版本、Driver/Firmware版本如下所示: +| MxVision版本 | CANN版本 | Driver/Firmware版本 | +| --------- | ------------------ | -------------- | +| 6.0.RC3 | 8.0.RC3 | 24.1.RC3 | -### 1.2支持的版本 +### 1.4 三方依赖 -该项目支持的SDK版本为2.0.4,CANN版本为5.0.4。 - -### 1.3软件方案介绍 - -基于MindX SDK的passengerflowestimation客流量检测业务流程为:待检测视频存放在live555服务器上经过mxpi_rtspsrc拉流插件输入,然后使用视频解码插件mxpi_videodecoder进行视频解码。用tee串流插件对解码的视频流进行分发。随后用mxpi_imageresize插件将图像方所至满足检测模型要求的输入图像大小要求,放缩后的图像输入模型推理插件mxpi_tensorinfer进行处理。将经过模型推理插件处理后的数据流输入到mxpi_objectpostprocessor之中,对目标检测模型推理的输出张量进行后处理。处理完毕后,再输入mxpi_selectobject插件中对类名为人的目标框进行筛选,紧接着输入到mxpi_motsimplesortV2插件中实现多目标路径记录功能。本项目开发的mxpi_passengerflowestimation插件将统计识别到的人的数目并输出到终端(此处统计的人数是是通过规定直线人流量)。最后通过mxpi_videoencoder将输入的视频标记出被识别出的人后输出。 - -表1.1系统方案各子系统功能描述: - -| 序号 | 子系统 | 功能描述 | -| ---- | -------------- | ------------------------------------------------------------ | -| 1 | 视频输入流 | 接收外部调用接口的输入视频路径,对视频进行拉流,并将拉去的裸流存储到缓冲区(buffer)中,并发送到下游插件。 | -| 2 | 视频解码 | 用于视频解码,当前只支持H264格式。 | -| 3 | 数据分发 | 对单个输入数据进行2次分发。 | -| 4 | 数据缓存 | 输出时为后续处理过程创建一个线程,用于将输入数据与输出数据解耦,并创建缓存队列,存储尚未输入到下流插件的数据。 | -| 5 | 图像处理 | 对解码后的YUV格式的图像进行放缩。 | -| 6 | 模型推理插件 | 目标分类或检测。 | -| 7 | 模型后处理插件 | 对模型输出的张量进行后处理。 | -| 8 | 目标筛选插件 | 对需要进行统计的目标进行筛选。 | -| 9 | 统计客流量插件 | 对视频中筛选出来的目标进行数量统计。 | -| 10 | 目标框转绘插件 | 将流中传进的数据转换可用于OSD插件绘图所使用的MxpiOsdinstancesList数据类型。 | -| 11 | OSD可视化插件 | 实现对视频流的每一帧图像进行绘制。 | -| 12 | 视频编码插件 | 用于将OSD可视化插件输出的图片进行视频编码,输出视频。 | - -### 1.4代码目录结构与说明 - -本项目名为passengerflowestimation客流量检测,项目目录如下所示: - -``` -├── models -│ ├── aipp_Passengerflowdetection.config # 模型转换aipp配置文件 -│ ├── passengerflowestimation.onnx # onnx模型 -│ └── yolov4.om # om模型 -├── pipeline -│ └── passengerflowestimation.pipeline # pipeline文件 -├── plugins -│ ├── mxpi_passengerflowestimate # passengerflowestimation后处理插件 -│ │ ├── CMakeLists.txt -│ │ ├── PassengerFlowEstimation.cpp -│ │ ├── PassengerFlowEstimation.h -│ │ └── build.sh -│ └── mxpi_selectobject # 筛选目标插件 -│ ├── CMakeLists.txt -│ ├── mxpi_selectobject.cpp -│ ├── mxpi_selectobject.h -│ └── build.sh -├── CMakeLists.txt -├── build.sh -├── main.cpp -``` - -### 1.5技术实现流程图 - -本项目实现对输入视频的人流量进行统计,流程图如下: - -![img](https://gitee.com/distancemay/mindxsdk-referenceapps/raw/master/contrib/PassengerflowEstimation/images/image1.png) - - - -## 2环境依赖 - -推荐系统为ubuntu 18.04,环境以来软件和版本如下: - -| 软件名称 | 版本 | 说明 | 获取方式 | -| ------------------- | ----- | ----------------------------- | --------------------------------------------------------- | -| MindX SDK | 2.0.4 | mxVision软件包 | [链接](https://www.hiascend.com/software/Mindx-sdk) | -| ubuntu | 18.04 | 操作系统 | 请上ubuntu官网获取 | -| Ascend-CANN-toolkit | 5.0.4 | Ascend-cann-toolkit开发套件包 | [链接](https://www.hiascend.com/software/cann/commercial) | - -在项目编译运行时候,需要设置环境变量: - -``` -. /usr/local/Ascend/ascend-toolkit/set_env.sh -. ${SDK安装路径}/mxVision/set_env.sh -``` - -注:其中SDK安装路径${MX_SDK_HOME}替换为用户的SDK安装路径。并且本项目用到了mxpi_opencvosd插件,使用mxpi_opencvosd插件前,需要使用osd相关的模型文件,请执行MindX SDK开发套件包安装目录下operators/opencvosd/generate_osd_om.sh脚本生成所需模型文件(在generate_osd_om.sh所在文件夹下执行`bash generate_osd_om.sh `,若这条命令执行失败,则将passengerflowestimation目录下的.om文件移动到generate_osd_om.sh所在的文件夹目录下MindXSDK安装路径/mxVision/operators/opencvosd下)。{install_path}替换为开发套件包所在路径。**(注:开头两行为每次一重新开启终端执行程序就需要输入,此外的其他为转换模型需要,若已经转换模型成功,则不需要输入这些)** - - - -## 3 软件依赖 - -推理中涉及到第三方软件依赖如下表所示。 - -| 软件名称 | 版本 | 说明 | 使用教程 | +| 依赖软件 | 版本 | 说明 | 使用教程 | | -------- | ---------- | ------------------------------ | ------------------------------------------------------------ | -| live555 | 1.09 | 实现视频转rstp进行推流 | [链接](https://gitee.com/ascend/docs-openmind/blob/master/guide/mindx/sdk/one_stop_navigation.md) | -| ffmpeg | 2021-07-21 | 实现mp4格式视频转为264格式视频 | [链接](https://gitee.com/ascend/docs-openmind/blob/master/guide/mindx/sdk/one_stop_navigation.md) | - - - -## 4 模型转换 - -本项目中使用的模型是yolov4模型,onnx模型可以直接[下载](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/PassengerflowEstimation/ATC%20Yolov4%28FP16%29%20from%20Pytorch.zip)。下载后使用模型转换工具ATC将onnx模型转换为om模型,模型转换工具相关介绍参考链接:https://gitee.com/ascend/docs-openmind/blob/master/guide/mindx/sdk/tutorials/%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99.md - -模型转换步骤如下: - -1. 从链接处下载onnx模型至`passengerflowestimation/models`文件夹下,将模型修改名称为`passengerflowestimation.onnx`。 -2. 进入`passengerflowestimation/models`文件夹下面执行命令**(注:提前设置好环境变量)**: +| live555 | 1.10 | 实现视频转rstp进行推流 | [链接](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/Live555%E7%A6%BB%E7%BA%BF%E8%A7%86%E9%A2%91%E8%BD%ACRTSP%E8%AF%B4%E6%98%8E%E6%96%87%E6%A1%A3.md) | +## 2 设置环境变量 ``` -atc --model=${模型路径}/passengerflowestimation.onnx --framework=5 --output=${输出.om模型路径}/yolov4 --input_format=NCHW --output_type=FP32 --soc_version=Ascend310 --input_shape="input:1,3,608,608" --log=info --insert_op_conf=${aipp文件路径}/aipp_Passengerflowdetection.config +. /usr/local/Ascend/ascend-toolkit/set_env.sh #CANN默认安装路径,根据实际安装路径修改 +. ${SDK_INSTALL_PATH}/mxVision/set_env.sh #根据实际SDK安装路径修改 ``` -执行该命令后会在指定输出.om模型路径生成项目指定模型文件`passengerflowestimation.om`。若模型转换成功则输出: +## 3 准备模型 +**步骤1**:下载原始yolov4模型:[下载地址](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/PassengerflowEstimation/ATC%20Yolov4%28FP16%29%20from%20Pytorch.zip),并将解压后获取到的.onnx文件存放至本案例代码的PassengerflowEstimation/models 目录下。 +**步骤2**: 进入PassengerflowEstimation/models目录执行以下命令。 ``` -ATC start working now, please wait for a moment. -ATC run success, welcome to the next use. +atc --model=./yolov4_dynamic_bs.onnx --framework=5 --output=yolov4 --input_format=NCHW --output_type=FP32 --soc_version=Ascend310P3 --input_shape="input:1,3,608,608" --log=info --insert_op_conf=./aipp_Passengerflowdetection.config ``` -模型转换的aipp文件配置如下: - +**步骤3**: 转换opencvosd模型,执行以下命令: ``` -aipp_op{ - aipp_mode:static - input_format : YUV420SP_U8 - - src_image_size_w : 608 - src_image_size_h : 608 - - crop: false - load_start_pos_h : 0 - load_start_pos_w : 0 - crop_size_w : 608 - crop_size_h: 608 - - csc_switch : true - rbuv_swap_switch : true - - - min_chn_0 : 0 - min_chn_1 : 0 - min_chn_2 : 0 - var_reci_chn_0: 0.003921568627451 - var_reci_chn_1: 0.003921568627451 - var_reci_chn_2: 0.003921568627451 - - - matrix_r0c0: 256 - matrix_r0c1: 0 - matrix_r0c2: 359 - matrix_r1c0: 256 - matrix_r1c1: -88 - matrix_r1c2: -183 - matrix_r2c0: 256 - matrix_r2c1: 454 - matrix_r2c2: 0 - input_bias_0: 0 - input_bias_1: 128 - input_bias_2: 128} +cd ${SDK_INSTALL_PATH}/mxVision/operators/opencvosd #根据实际SDK安装路径修改 +bash generate_osd_om.sh ``` -## 5准备 - -按照第3小结**软件依赖**安装live555和ffmpeg,按照 [Live555离线视频转RTSP说明文档](https://gitee.com/ascend/docs-openmind/blob/master/guide/mindx/sdk/one_stop_navigation.md)将mp4视频转换为h264格式。并将生成的264格式的视频上传到`live/mediaServer`目录下,然后修改`passengerflowestimation/pipeline`目录下的`passengerflowestimation.pipeline`文件中mxpi_rtspsrc0的内容。 - +## 4 编译与运行 +**步骤1**:配置pipeline: +根据实际的网络视频流,修改passengerflowestimation.pipeline文件第9行: ``` +#将rtspUrl的值修改为实际的rtsp网络视频流地址 "mxpi_rtspsrc0": { - "factory": "mxpi_rtspsrc", - "props": { - "rtspUrl":"rtsp://xxx.xxx.xxx.xxx:xxxx/xxx.264", // 修改为自己所使用的的服务器和文件名 - "channelId": "0" - }, - "next": "mxpi_videodecoder0" - }, -``` - -在mxpi_objectpostprocessor0插件中,修改postProcessLibPath中的路径为自己libyolov3postprocess.so文件路径。 -## 6编译与运行 - -### 步骤1 - -按照第二小节环境依赖中的步骤设置环境变量。 - -### 步骤2 - -按照第四小节模型转换中的步骤获取om模型文件,放置在`passengerflowestimation/models`目录下。 - -### 步骤3 修改 - -对于mxpi_passengerflowestimate插件的使用说明: - -在pipeline中,mxpi_passengerflowestimate插件如下: - + "factory": "mxpi_rtspsrc", + "props": { + "rtspUrl": "rtsp://xxx.xxx.xx.xxx:xxxx/xxxx.264", + "channelId": "0" + }, + "next": "queue0" +}, ``` -"mxpi_passengerflowestimation0": { - "props": { - "dataSource": "mxpi_selectobject0", - "motSource": "motV2", - "x0":"736", - "y0":"191", - "x1":"1870", - "y1":"191" - }, - "factory": "mxpi_passengerflowestimation", - "next": "mxpi_object2osdinstances0" - }, -``` - -这里点$(x_0,y_0)$与$(x_1,y_1)$确定了一条线段,这个插件统计经过该线段的客流量。修改mxpi_objectpostprocessor0插件中的postProcessLibPath为自己当前的libyolov3postprocess.so路径。 - -### 步骤4 编译 - -进入passengerflowestimation目录,在passengerflowestimation目录下执行命令: - +根据实际的环境变量,修改passengerflowestimation.pipeline文件第87行: ``` -bash build.sh +#将postProcessLibPath的值修改为libyolov3postprocess.so的绝对路径路径(在SDK安装路径下) +"mxpi_objectpostprocessor0": { + "props": { + "dataSource": "mxpi_tensorinfer0", + "postProcessConfigPath": "./models/yolov4.cfg", + "labelPath": "./models/yolov3.names", + "postProcessLibPath": "${MindX_SDK安装路径}/mxVision/lib/modelpostprocessors/libyolov3postprocess.so" + }, + "factory": "mxpi_objectpostprocessor", + "next": "mxpi_selectobject0" +}, ``` -命令执行成功之后会在passengerflowestimation/plugins/mxpi_passengerflowestimation和passengerflowestimation/plugins/mxpi_selectobject目录下分别生成build文件夹。将build文件夹下生成的.so下载后上传到${SDK安装路径}/mxVision/lib/plugins目录下。在生成build文件夹后,进入到build目录下执行如下指令: - +**步骤2**:编译后处理插件so:在项目根目录下执行 ``` -chmod 640 libmxpi_passengerflowestimation.so -chmod 640 libmxpi_selectobject.so +bash build.sh #编译 +chmod 440 ./plugins/mxpi_passengerflowestimation/build/libmxpi_passengerflowestimation.so #修改so权限 +chmod 440 ./plugins/mxpi_selectobject/build/libmxpi_selectobject.so #修改so权限 +cp ./plugins/mxpi_passengerflowestimation/build/libmxpi_passengerflowestimation.so ${SDK_INSTALL_PATH}/mxVision/lib/plugins #拷贝so到相应路径,${SDK_INSTALL_PATH}根据实际SDK安装路径修改 +cp ./plugins/mxpi_selectobject/build/libmxpi_selectobject.so ${SDK_INSTALL_PATH}/mxVision/lib/plugins #拷贝so到相应路径,${SDK_INSTALL_PATH}根据实际SDK安装路径修改 ``` +**步骤3**:拉起Live555服务:[Live555拉流教程](../../docs/参考资料/Live555离线视频转RTSP说明文档.md) - -### 步骤5 运行: - -在passengerflowestimation目录下运行: - +**步骤4**:在根目录下运行: ``` python3 main.py ``` -最后生成的结果将会在passengerflowestimation文件夹目录下result.h264文件里面。 - - - -## 7性能测试 - -测试帧率: 本样例的测试脚本main.py测试拉流25帧视频时输出的帧率,通过计算帧数和整个计算过程所需时间的比值,统计整个过程中平均帧率。 -测试视频的帧率为25,分辨率1920*1080,因为拉流开始会导致丢帧,而测试脚本是通过计算帧数和整个处理过程所需的时间的比值获得的平均帧率,所以测试视频的帧数过少会引起性能测试值偏低,FRAMENUM需要设为较大值(不小于源测试视频的帧数)。 -经过计算平均fps值,得到平均fps为24.9(如下图所示),考虑到一开始拉流丢帧造成的损失,满足性能测试要求。 -![img](https://gitee.com/distancemay/mindxsdk-referenceapps/raw/master/contrib/PassengerflowEstimation/images/image5.png) - -## 8适用场景 -本项目适用于俯视角度较大,并且人流量不是非常密集的视频中人流量统计。若人流非常密集,由于yolov4模型识别人体不准确,故无法准确统计客流量。并且在视频中的画线要尽量水平。待检测的视频最好如下所示: -![img](https://gitee.com/distancemay/mindxsdk-referenceapps/raw/master/contrib/PassengerflowEstimation/images/image4.png) \ No newline at end of file +**步骤5**:查看结果:生成的结果保存在result.h264文件里面。 \ No newline at end of file diff --git a/contrib/PassengerflowEstimation/images/image1.png b/contrib/PassengerflowEstimation/images/image1.png deleted file mode 100644 index 5513cfd54307a556339891ff1b39d702b2db4511..0000000000000000000000000000000000000000 Binary files a/contrib/PassengerflowEstimation/images/image1.png and /dev/null differ diff --git a/contrib/PassengerflowEstimation/images/image2.png b/contrib/PassengerflowEstimation/images/image2.png deleted file mode 100644 index 934f91befb8dee122a00627324cb94fce04d2f82..0000000000000000000000000000000000000000 Binary files a/contrib/PassengerflowEstimation/images/image2.png and /dev/null differ diff --git a/contrib/PassengerflowEstimation/images/image3.png b/contrib/PassengerflowEstimation/images/image3.png deleted file mode 100644 index 0d573883f0beff7688c686cb790e7f2ad3adac8f..0000000000000000000000000000000000000000 Binary files a/contrib/PassengerflowEstimation/images/image3.png and /dev/null differ diff --git a/contrib/PassengerflowEstimation/images/image4.png b/contrib/PassengerflowEstimation/images/image4.png deleted file mode 100644 index 0a74cddb050c1356fd280ae9b97cf74fc0224183..0000000000000000000000000000000000000000 Binary files a/contrib/PassengerflowEstimation/images/image4.png and /dev/null differ diff --git a/contrib/PassengerflowEstimation/images/image5.png b/contrib/PassengerflowEstimation/images/image5.png deleted file mode 100644 index b0ae459c09cabacc6324209af2ceb26b037bcc84..0000000000000000000000000000000000000000 Binary files a/contrib/PassengerflowEstimation/images/image5.png and /dev/null differ diff --git a/contrib/PassengerflowEstimation/images/image6.png b/contrib/PassengerflowEstimation/images/image6.png deleted file mode 100644 index f3b522ddde6b079e14eddd30489c5798c510ac3e..0000000000000000000000000000000000000000 Binary files a/contrib/PassengerflowEstimation/images/image6.png and /dev/null differ diff --git a/contrib/PassengerflowEstimation/pipeline/passengerflowestimation.pipeline b/contrib/PassengerflowEstimation/pipeline/passengerflowestimation.pipeline index 646238ecdad6303d3bfdb4199f2d1c716100c382..d96f382dcc7918b5f857dfec33176b73f2a0cf97 100644 --- a/contrib/PassengerflowEstimation/pipeline/passengerflowestimation.pipeline +++ b/contrib/PassengerflowEstimation/pipeline/passengerflowestimation.pipeline @@ -135,8 +135,6 @@ "next": "mxpi_opencvosd0:1" }, "mxpi_opencvosd0": { - "dataSourceImage": "queue2", - "dataSourceOsd": "queue11", "factory": "mxpi_opencvosd", "next": "queue9" }, diff --git a/contrib/PassengerflowEstimation/plugins/mxpi_passengerflowestimation/CMakeLists.txt b/contrib/PassengerflowEstimation/plugins/mxpi_passengerflowestimation/CMakeLists.txt index 4922d0ff0d3b5c4e3c60a0f07aa78f1691590499..af33e0e47eaf18b8111aa8af641258d932f39ff1 100644 --- a/contrib/PassengerflowEstimation/plugins/mxpi_passengerflowestimation/CMakeLists.txt +++ b/contrib/PassengerflowEstimation/plugins/mxpi_passengerflowestimation/CMakeLists.txt @@ -14,7 +14,7 @@ link_directories(${MX_SDK_HOME}/lib) link_directories(${MX_SDK_HOME}/opensource/lib) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) -add_compile_options(-std=c++11 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations) +add_compile_options(-std=c++14 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations) add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}") add_definitions(-DENABLE_DVPP_INTERFACE) add_definitions(-Dgoogle=mindxsdk_private) diff --git a/contrib/PassengerflowEstimation/plugins/mxpi_selectobject/CMakeLists.txt b/contrib/PassengerflowEstimation/plugins/mxpi_selectobject/CMakeLists.txt index 4adc685ffa24a8215cf4d9073e64eb4618fccee3..a0a33b4ac770d61db802177be8a5cf252fad52a0 100644 --- a/contrib/PassengerflowEstimation/plugins/mxpi_selectobject/CMakeLists.txt +++ b/contrib/PassengerflowEstimation/plugins/mxpi_selectobject/CMakeLists.txt @@ -14,7 +14,7 @@ link_directories(${MX_SDK_HOME}/lib) link_directories(${MX_SDK_HOME}/opensource/lib) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) -add_compile_options(-std=c++11 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations) +add_compile_options(-std=c++14 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations) add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}") add_definitions(-DENABLE_DVPP_INTERFACE) add_definitions(-Dgoogle=mindxsdk_private)