afirst commit

This commit is contained in:
doudou0
2022-10-11 09:24:57 +08:00
parent 40f2126766
commit f1742a1976
26 changed files with 2443 additions and 1 deletions

Submodule deepsort deleted from b3fcf7e2fd

49
deepsort/CMakeLists.txt Normal file
View File

@@ -0,0 +1,49 @@
# Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
# CMake lowest version requirement
cmake_minimum_required(VERSION 3.5.0)
# project information
project(FairMOT)
set(MX_SDK_HOME "/home/wangshengke1/MindX_SDK/mxVision")
if (NOT DEFINED ENV{MX_SDK_HOME})
string(REGEX REPLACE "(.*)/(.*)/(.*)/(.*)" "\\1" MX_SDK_HOME ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "set default MX_SDK_HOME: ${MX_SDK_HOME}")
else ()
message(STATUS "env MX_SDK_HOME: ${MX_SDK_HOME}")
endif()
# Compile options
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_definitions(-Dgoogle=mindxsdk_private)
add_compile_options(-std=c++11 -fPIC -fstack-protector-all -Wall)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack -pie")
# Header path
include_directories(
${MX_SDK_HOME}/include/
${MX_SDK_HOME}/opensource/include/
)
# add host lib path
link_directories(
${MX_SDK_HOME}/lib/
${MX_SDK_HOME}/opensource/lib/
${MX_SDK_HOME}/opensource/lib64/
)
add_executable(main main.cpp)
target_link_libraries(main glog mxbase plugintoolkit mxpidatatype streammanager cpprest mindxsdk_protobuf)
install(TARGETS main DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

241
deepsort/README.md Normal file
View File

@@ -0,0 +1,241 @@
# DeepSORT目标跟踪
## 1 介绍
DeepSOR目标跟踪后处理插件基于MindXSDK开发在晟腾芯片上进行目标检测和跟踪可以对行人进行画框和编号将检测结果可视化并保存。项目主要流程为通过live555服务器进行拉流输入视频然后进行视频解码将264格式的视频解码为YUV格式的图片图片缩放后经过模型推理进行行人识别识别结果经过FairMOT后处理后得到识别框对识别框进行跟踪并编号用编号覆盖原有的类别信息再将识别框和类别信息分别转绘到图片上最后将图片编码成视频进行输出。
### 1.1 支持的产品
昇腾310(推理)
### 1.2 支持的版本
本样例配套的CANN版本为[5.0.4](https://www.hiascend.com/software/cann/commercial)。支持的SDK版本为[2.0.4](https://www.hiascend.com/software/Mindx-sdk)。
MindX SDK安装前准备可参考《用户指南》[安装教程](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/quickStart/1-1安装SDK开发套件.md)
### 1.3 软件方案介绍
基于MindX SDK的 DeepSORT目标识别业务流程为待检测视频存放在live555服务器上经mxpi_rtspsrc拉流插件输入然后使用视频解码插件mxpi_videodecoder将视频解码成图片再通过图像缩放插件mxpi_imageresize将图像缩放至满足检测模型要求的输入图像大小要求缩放后的图像输入模型推理插件mxpi_tensorinfer得到检测结果本项目开发的DeepSORT后处理插件处理推理结果得到识别框。再接入跟踪插件中识别框进行目标跟踪得到目标的跟踪编号然后在使用本项目开发的mxpi_trackidreplaceclassname插件将跟踪编号覆盖类名信息使用mxpi_object2osdinstances和mxpi_opencvosd分别将识别框和类名存储跟踪编号绘制到原图片再通过mxpi_videoencoder将图片合成视频。
表1.1 系统方案各子系统功能描述:
| 序号 | 子系统 | 功能描述 |
| ---- | -------------------- | :----------------------------------------------------------- |
| 1 | 视频输入 | 接收外部调用接口的输入视频路径对视频进行拉流并将拉取的裸流存储到缓冲区buffer并发送到下游插件。 |
| 2 | 视频解码 | 用于视频解码当前只支持H264/H265格式。 |
| 3 | 数据分发 | 对单个输入数据分发多次。 |
| 4 | 数据缓存 | 输出时为后续处理过程另创建一个线程,用于将输入数据与输出数据解耦,并创建缓存队列,存储尚未输出到下流插件的数据。 |
| 5 | 图像处理 | 对解码后的YUV格式的图像进行指定宽高的缩放暂时只支持YUV格式 的图像。 |
| 6 | 模型推理插件 | 目标分类或检测目前只支持单tensor输入图像数据的推理模型。 |
| 7 | 模型后处理插件 | 实现对DeepSORT模型输出的tensor解析获取目标检测框以及对应的ReID向量传输到跟踪模块。 |
| 8 | 跟踪插件 | 实现多目标(包括机非人、人脸)路径记录功能。 |
| 9 | 跟踪编号取代类名插件 | 用跟踪插件产生的编号信息取代后处理插件产生的类名信息,再将数据传入数据流中。 |
| 10 | 目标框转绘插件 | 将流中传进的MxpiObjectList数据类型转换可用于OSD插件绘图所使用的的 MxpiOsdInstancesList数据类型。 |
| 11 | OSD可视化插件 | 主要实现对每帧图像标注跟踪结果。 |
| 12 | 视频编码插件 | 用于将OSD可视化插件输出的图片进行视频编码输出视频。 |
### 1.4 代码目录结构与说明
本工程名称为 DeepSORT工程目录如下图所示
```
├── models
│ ├── aipp_FairMOT.config # 模型转换aipp配置文件
│ ├── mot_v2.onnx # onnx模型
│ └── mot_v2.om # om模型
├── pipeline
│ └── deepsort.pipeline # pipeline文件
├── plugins
│ ├── FairmotPostProcess #DeepSORT后处理插件
│ │ ├── CMakeLists.txt
│ │ ├── FairmotPostProcess.cpp
│ │ ├── FairmotPostProcess.h
│ │ └── build.sh
│ ├── Deeosort # DeepSORT的Tracking
│ │ ├── CMakeLists.txt
│ │ ├── DeepSort.cpp
│ │ ├── DeepSort.h
│ │ ├── kalmanfilter.cpp
│ │ ├── kalmanfilter.h
│ │ ├── linear_assignment.cpp
│ │ ├── linear_assignment.h
│ │ ├── nn_matching.cpp
│ │ ├── nn_matching.h
│ │ ├── track.cpp
│ │ ├── track.h
│ │ ├── tracker.cpp
│ │ ├── tracker.h
│ │ ├── temp.cpp
│ │ ├── move_so.sh
│ │ └── build.sh
│ ├── DeepAppearanceDescriptor #特征
│ │ ├── FeatureTensor.cpp
│ │ ├── FeatureTensor.h
│ │ ├── model.cpp
│ │ ├── model.h
│ │ └── dataType.h
│ ├── MunkresAssignment
│ │ ├── hungarianoper.cpp
│ │ ├── hungarianoper.h
│ │ └── munkres
│ │ ├── munkres.cpp
│ │ ├── munkres.h
│ │ └── matrix.h
│ └── MxpiTrackIdReplaceClassName # 跟踪编号取代类名插件
│ ├── CMakeLists.txt
│ ├── MxpiTrackIdReplaceClassName.cpp
│ ├── MxpiTrackIdReplaceClassName.h
│ ├── move_so.sh
│ └── build.sh
├── CMakeLists.txt
├── build.sh
├── main.cpp
└── run.sh
```
## 2 环境依赖
推荐系统为ubantu 18.04,环境依赖软件和版本如下表:
| 软件名称 | 版本 | 说明 | 获取方式 |
| ------------------- | ----------- | ----------------------------- | ------------------------------------------------------------ |
| MindX SDK | 2.0.4 | mxVision软件包 | [链接](https://www.hiascend.com/software/Mindx-sdk) |
| ubantu | 18.04.1 LTS | 操作系统 | Ubuntu官网获取 |
| Ascend-CANN-toolkit | 5.0.4 | Ascend-cann-toolkit开发套件包 | [链接](https://www.hiascend.com/software/cann/commercial) |
在编译运行项目前,需要设置环境变量:
```
export MX_SDK_HOME=/home/wangshengke0/MindX_SDK/mxVision
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 ASCEND_OPP_PATH=${install_path}/opp
export ASCEND_AICPU_PATH=${install_path}
export LD_LIBRARY_PATH=${install_path}/atc/lib64:${MX_SDK_HOME}/lib:${MX_SDK_HOME}/opensource/lib:$LD_LIBRARY_PATH
export GST_PLUGIN_SCANNER=${MX_SDK_HOME}/opensource/libexec/gstreamer-1.0/gst-plugin-scanner
export GST_PLUGIN_PATH=${MX_SDK_HOME}/opensource/lib/gstreamer-1.0:${MX_SDK_HOME}/lib/plugins
```
其中SDK安装路径${MX_SDK_HOME}替换为用户的SDK安装路径;install_path替换为开发套件包所在路径。LD_LIBRARY_PATH用以加载开发套件包中lib库。
## 3 软件依赖
推理中涉及到第三方软件依赖如下表所示。
| 依赖软件 | 版本 | 说明 | 使用教程 |
| -------- | ---------- | ------------------------------ | ------------------------------------------------------------ |
| live555 | 1.09 | 实现视频转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) |
| ffmpeg | 2021-07-21 | 实现mp4格式视频转为264格式视频 | [链接](https://gitee.com/ascend/mindxsdk-referenceapps/blob/master/docs/%E5%8F%82%E8%80%83%E8%B5%84%E6%96%99/pc%E7%AB%AFffmpeg%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B.md#https://ffmpeg.org/download.html) |
## 4 模型转换
本项目中适用的模型是FairMOT模型onnx模型可以直接[下载](https://mindx.sdk.obs.cn-north-4.myhuaweicloud.com/mindxsdk-referenceapps%20/contrib/FairMOT/mot_v2.onnx)。下载后使用模型转换工具 ATC 将 onnx 模型转换为 om 模型模型转换工具相关介绍参考链接https://support.huaweicloud.com/tg-cannApplicationDev330/atlasatc_16_0005.html 。
模型转换,步骤如下:
1. 从上述 onnx 模型下载链接中下载 onnx 模型至 `deepsort/models` 文件夹下文件名为mot_v2.onnx 。
2. 进入 `deepsort/models` 文件夹下执行命令:
```
atc --input_shape="input.1:1,3,480,864" --check_report=./network_analysis.report --input_format=NCHW --output=./mot_v2 --soc_version=Ascend310 --insert_op_conf=./aipp_FairMOT.config --framework=5 --model=./mot_v2.onnx
```
执行该命令后会在当前文件夹下生成项目需要的模型文件 mot_v2.om。执行后终端输出为
```
ATC start working now, please wait for a moment.
ATC run success, welcome to the next use.
```
表示命令执行成功。
## 5 准备
按照第3小结**软件依赖**安装live555和ffmpeg按照 [Live555离线视频转RTSP说明文档](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)将mp4视频转换为h264格式。并将生成的264格式的视频上传到`live/mediaServer`目录下,然后修改`FairMOT/pipeline`目录下的fairmot.pipeline文件中mxpi_rtspsrc0的内容。
```
"mxpi_rtspsrc0": {
"factory": "mxpi_rtspsrc",
"props": {
"rtspUrl":"rtsp://xxx.xxx.xxx.xxx:xxxx/xxx.264", // 修改为自己所使用的的服务器和文件名
"channelId": "0"
},
"next": "mxpi_videodecoder0"
},
```
## 6 编译与运行
**步骤1** 按照第2小结**环境依赖**中的步骤设置环境变量。
**步骤2** 按照第 4 小节 **模型转换** 中的步骤获得 om 模型文件,放置在 `deepsort/models` 目录下。
**步骤3** 编译。进入 `deepsort` 目录,在 `deepsort` 目录下执行命令:
```
bash build.sh
```
**步骤4** 运行。回到deepsort目录下在deepsort目录下执行命令
```
bash run.sh
```
命令执行成功后会在当前目录下生成检测结果视频文件out.h264,查看文件验证目标跟踪结果。
## 7 性能测试
**测试帧率:**
按照第6小结编译与运行中的步骤进行编译运行服务器会输出运行到该帧的平均帧率。
输入视频帧率应高于25否则无法发挥全部性能。
## 8 精度测试
**测试性能:**
以MOT16 数据集为基准测试模型的 MOTA 值。
执行步骤:
**步骤1** 下载 MOT16数据集下载链接https://motchallenge.net/。在deepsort 目录下创建 /py-motmetrics-develop/ 目录下载py-motmetrics工具下载链接https://github.com/cheind/py-motmetrics。
将MOT16 数据集的gt文件放入/py-motmetrics-develop/motmetrics/data/train/gt/1/gt/。将自己运行得到的txt文件放入/py-motmetrics-develop/motmetrics/data/train/并将命名改为1.txt.
注意自己运行得到的txt文件是按照第一列frame id的数值进行排序的需要先将其按照第二列track id的数值进行排序后放入。
**步骤2** 安装 pycocotools 评测工具包。执行命令:
```
pip install motmetrics
```
**步骤3** 在/py-motmetrics-develop/motmetrics/apps/目录下运行命令
```
python eval_motchallenge.py .../deepsort/py-motmetrics-develop/motmetrics/data/train/gt/ ..../deepsort/py-motmetrics-develop/motmetrics/data/train
```
每次运行得到的txt文件都需要删除并重新生成。
因为视频流是循环输入故在此测试精度时候选取视频前九百帧进行测试如测试需要可修改deepsort/plugins/DeepSort/DeepSort.cpp中的全局变量control值进行精度测试。
## 9 常见问题
9.1 测试输入视频流不存在或断流
**问题描述:**
运行时报错:
执行失败,提示 “connect stream failed.”
**解决方案:**
确保使用 live555 工具进行推流在deepsort 目录下下载live555并解压将测试用例放在deepsort/live/mediaServer/ 目录下;回到 deepsort/ 文件夹,在此文件夹下运行命令: bash run.sh

44
deepsort/build.sh Normal file
View File

@@ -0,0 +1,44 @@
#!/bin/bash
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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
current_folder="$( cd "$(dirname "$0")" ;pwd -P )"
SAMPLE_FOLDER=(
/plugins/FairmotPostProcess/
/plugins/DeepSort/
/plugins/MxpiTrackIdReplaceClassName/
)
err_flag=0
for sample in "${SAMPLE_FOLDER[@]}";do
cd "${current_folder}/${sample}"
bash build.sh || {
echo -e "Failed to build ${sample}"
err_flag=1
}
bash move_so.sh || {
echo -e "Failed to move ${sample}'s .so"
err_flag=1
}
done
if [ ${err_flag} -eq 1 ]; then
exit 1
fi
exit 0

BIN
deepsort/main Executable file

Binary file not shown.

125
deepsort/main.cpp Normal file
View File

@@ -0,0 +1,125 @@
/*
* Copyright (c) 2022.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.
*/
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <sys/time.h>
#include <ctime>
#include <stdio.h>
#include <chrono>
#include "MxBase/Log/Log.h"
#include "MxStream/StreamManager/MxStreamManager.h"
#include <sys/time.h>
#include <ctime>
namespace {
std::string ReadPipelineConfig(const std::string& pipelineConfigPath)
{
std::ifstream file(pipelineConfigPath.c_str(), std::ifstream::binary);
if (!file) {
LogError << pipelineConfigPath << " file dose not exist.";
return "";
}
file.seekg(0, std::ifstream::end);
uint32_t fileSize = file.tellg();
file.seekg(0);
std::unique_ptr<char[]> data(new char[fileSize]);
file.read(data.get(), fileSize);
file.close();
std::string pipelineConfig(data.get(), fileSize);
return pipelineConfig;
}
}
int main(int argc, char* argv[])
{
std::string pipelineConfigPath = "./pipeline/deepsort.pipeline";
std::string pipelineConfig = ReadPipelineConfig(pipelineConfigPath);
if (pipelineConfig == "") {
LogError << "Read pipeline failed.";
return APP_ERR_COMM_INIT_FAIL;
}
MxStream::MxStreamManager mxStreamManager;
APP_ERROR ret = mxStreamManager.InitManager();
if (ret != APP_ERR_OK) {
LogError << "Failed to init Stream manager, ret = " << ret << ".";
return ret;
}
ret = mxStreamManager.CreateMultipleStreams(pipelineConfig);
if (ret != APP_ERR_OK) {
LogError << "Failed to create Stream, ret = " << ret << ".";
return ret;
}
FILE *fp = fopen("./out.h264", "wb");
if (fp == nullptr) {
LogError << "Failed to open file.";
return APP_ERR_COMM_OPEN_FAIL;
}
bool m_bFoundFirstIDR = false;
bool bIsIDR = false;
uint32_t frameCount = 0;
uint32_t MaxframeCount = 5000;
std::string streamName = "encoder";
int inPluginId = 0;
int msTimeOut = 200000;
auto start = std::chrono::system_clock::now();
while (1) {
MxStream::MxstDataOutput* output = mxStreamManager.GetResult(streamName, inPluginId, msTimeOut);
if (output == nullptr) {
LogError << "Failed to get pipeline output.";
return ret;
}
bIsIDR = (output->dataSize > 1);
if (!m_bFoundFirstIDR) {
if (!bIsIDR) {
continue;
} else {
m_bFoundFirstIDR = true;
}
}
if (fwrite(output->dataPtr, output->dataSize, 1, fp) != 1) {
LogInfo << "write frame to file fail";
}
LogInfo << "Dealing frame id:" << frameCount;
frameCount++;
if (frameCount > MaxframeCount) {
LogInfo << "write frame to file done";
break;
}
delete output;
auto end = std::chrono::system_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
double average = (double)(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den / frameCount;
std::cout << "fps: " << 1 / average << std::endl;
}
fclose(fp);
mxStreamManager.DestroyAllStreams();
return 0;
}

View File

@@ -0,0 +1,37 @@
aipp_op{
aipp_mode:static
input_format : YUV420SP_U8
src_image_size_w : 864
src_image_size_h : 480
crop: false
load_start_pos_h : 0
load_start_pos_w : 0
crop_size_w : 864
crop_size_h: 480
csc_switch : true
rbuv_swap_switch : false
# 色域转换
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
# 均值归一化
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}

View File

@@ -0,0 +1,95 @@
{
"graph_fusion": {
"BatchNormPreprocessFusionPass": {
"effect_times": "49",
"match_times": "49"
},
"CastCastFusionPass": {
"effect_times": "0",
"match_times": "1"
},
"CastRemoveFusionPass": {
"effect_times": "0",
"match_times": "1"
},
"ConcatCToNOptimizeFusionPass": {
"effect_times": "12",
"match_times": "12"
},
"ConstToAttrPass": {
"effect_times": "9",
"match_times": "9"
},
"ConvBatchnormFusionPass": {
"effect_times": "49",
"match_times": "49"
},
"ConvConcatFusionPass": {
"effect_times": "0",
"match_times": "12"
},
"ConvToFullyConnectionFusionPass": {
"effect_times": "0",
"match_times": "57"
},
"ConvWeightCompressFusionPass": {
"effect_times": "0",
"match_times": "57"
},
"DeconvWeightTransFusionPass": {
"effect_times": "0",
"match_times": "6"
},
"ForceFp16CastFusionPass": {
"effect_times": "0",
"match_times": "1"
},
"MulSquareFusionPass": {
"effect_times": "0",
"match_times": "1"
},
"RefreshInt64ToInt32FusionPass": {
"effect_times": "1",
"match_times": "1"
},
"SplitConvConcatFusionPass": {
"effect_times": "0",
"match_times": "12"
},
"StrideHoistingPass": {
"effect_times": "0",
"match_times": "37"
},
"TBEConvAddFusion": {
"effect_times": "12",
"match_times": "12"
},
"TransdataCastFusionPass": {
"effect_times": "0",
"match_times": "67"
},
"TransposedUpdateFusionPass": {
"effect_times": "9",
"match_times": "9"
},
"ZConcatDFusionPass": {
"effect_times": "0",
"match_times": "12"
}
},
"session_and_graph_id": "0_0",
"ub_fusion": {
"TbeAippCommonFusionPass": {
"effect_times": "1",
"match_times": "1"
},
"TbeCommonRules0FusionPass": {
"effect_times": "45",
"match_times": "45"
},
"TbeConvDoubleInFusionPass": {
"effect_times": "4",
"match_times": "4"
}
}
}

View File

@@ -0,0 +1,164 @@
{
"encoder": {
"stream_config": {
"deviceId": "2"
},
"mxpi_rtspsrc0": {
"factory": "mxpi_rtspsrc",
"props": {
"rtspUrl":"rtsp://192.168.88.108:8554/MOT16-11.264",
"channelId": "0"
},
"next": "queue0"
},
"queue0": {
"props": {
"max-size-buffers": "200"
},
"factory": "queue",
"next": "mxpi_videodecoder0"
},
"mxpi_videodecoder0": {
"factory": "mxpi_videodecoder",
"props": {
"inputVideoFormat": "H264",
"outputImageFormat": "YUV420SP_NV12",
"vdecChannelId": "0"
},
"next": "tee0"
},
"tee0": {
"factory": "tee",
"next": [
"queue1",
"queue2"
]
},
"queue1": {
"props": {
"max-size-buffers": "200"
},
"factory": "queue",
"next": "mxpi_imageresize0"
},
"queue2": {
"props": {
"max-size-buffers": "200"
},
"factory": "queue",
"next": "mxpi_opencvosd0:0"
},
"mxpi_imageresize0": {
"props": {
"resizeHeight": "480",
"resizeWidth": "864",
"resizeType": "Resizer_KeepAspectRatio_Fit"
},
"factory": "mxpi_imageresize",
"next": "queue3"
},
"queue3": {
"props": {
"max-size-buffers": "200"
},
"factory": "queue",
"next": "mxpi_tensorinfer0"
},
"mxpi_tensorinfer0": {
"props": {
"dataSource": "mxpi_imageresize0",
"outputHasBatchDim":"0",
"modelPath": "./models/mot_v2.om"
},
"factory": "mxpi_tensorinfer",
"next": "fairmotpostprocess0"
},
"fairmotpostprocess0": {
"props": {
"dataSource": "mxpi_tensorinfer0"
},
"factory": "fairmotpostprocess",
"next": "deepsort0"
},
"deepsort0": {
"props": {
"dataSourceDetection": "mxpi_fairmot_obj",
"dataSourceFeature": "mxpi_fairmot_fea"
},
"factory": "deepsort",
"next": "mxpi_trackidreplaceclassname0"
},
"mxpi_trackidreplaceclassname0": {
"props": {
"dataSource": "mxpi_fairmot_obj",
"motSource": "deepsort0"
},
"factory": "mxpi_trackidreplaceclassname",
"next": "queue4"
},
"queue4": {
"props": {
"max-size-buffers": "200"
},
"factory": "queue",
"next": "mxpi_object2osdinstances0"
},
"mxpi_object2osdinstances0": {
"props": {
"dataSource": "mxpi_trackidreplaceclassname0",
"colorMap": "255,100,100|100,255,100|100,100,255|255,128,0",
"fontFace": "1",
"fontScale": "1",
"fontThickness": "1",
"fontLineType": "8",
"rectThickness": "3",
"rectLineType": "8"
},
"factory": "mxpi_object2osdinstances",
"next": "queue5"
},
"queue5": {
"props": {
"max-size-buffers": "200"
},
"factory": "queue",
"next": "mxpi_opencvosd0:1"
},
"mxpi_opencvosd0": {
"factory": "mxpi_opencvosd",
"next": "queue6"
},
"queue6": {
"props": {
"max-size-buffers": "200"
},
"factory": "queue",
"next": "mxpi_videoencoder0"
},
"mxpi_videoencoder0": {
"props": {
"inputFormat": "YUV420SP_NV12",
"outputFormat": "H264",
"fps": "1",
"iFrameInterval": "50"
},
"factory": "mxpi_videoencoder",
"next": "queue7"
},
"queue7": {
"props": {
"max-size-buffers": "200"
},
"factory": "queue",
"next": "appsink0"
},
"appsink0": {
"factory": "appsink",
"former": "mxpi_videoencoder0"
}
}
}

View File

@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.5.2)
project(deepsort)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_definitions(-Dgoogle=mindxsdk_private)
set(PLUGIN_NAME "deepsort")
set(TARGET_LIBRARY ${PLUGIN_NAME})
set(MX_SDK_HOME "/home/wangshengke1/MindX_SDK/mxVision")
include_directories(/usr/include/eigen3)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${MX_SDK_HOME}/include)
include_directories(${MX_SDK_HOME}/opensource/include)
include_directories(${MX_SDK_HOME}/opensource/include/gstreamer-1.0)
include_directories(${MX_SDK_HOME}/opensource/include/glib-2.0)
include_directories(${MX_SDK_HOME}/opensource/lib/glib-2.0/include)
include_directories(/home/wangshengke1/MindX_SDK/mxVision/opensource/include/opencv4)
link_directories(${MX_SDK_HOME}/lib)
link_directories(${MX_SDK_HOME}/opensource/lib)
add_compile_options(-std=c++11 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations)
add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}")
add_definitions(-DENABLE_DVPP_INTERFACE)
add_library(${TARGET_LIBRARY} SHARED
DeepSort.cpp
kalmanfilter.cpp
linear_assignment.cpp
nn_matching.cpp
track.cpp
tracker.cpp
../DeepAppearanceDescriptor/model.cpp
../MunkresAssignment/hungarianoper.cpp
../MunkresAssignment/munkres/munkres.cpp
)
target_link_libraries(${TARGET_LIBRARY} glib-2.0 gstreamer-1.0 gobject-2.0 gstbase-1.0 gmodule-2.0 glog)
target_link_libraries(${TARGET_LIBRARY} mxpidatatype plugintoolkit mxbase mindxsdk_protobuf)

View File

@@ -0,0 +1,268 @@
/*
* Copyright (c) 2022.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.
*/
#include "DeepSort.h"
#include "MxBase/Log/Log.h"
#include "tracker.h"
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <iomanip>
#define TWO 2
#define THREE 3
using namespace MxPlugins;
using namespace MxTools;
using namespace std;
const int nn_budget = 100;
static int frame_id = 0;
const float max_cosine_distance = 0.2;
int control = 900;
tracker mytracker(max_cosine_distance, nn_budget);
APP_ERROR DeepSort::Init(std::map<std::string, std::shared_ptr<void>>& configParamMap)
{
LogInfo << "DeepSort::Init start.";
APP_ERROR ret = APP_ERR_OK;
std::shared_ptr<string> objectNamePropSptr = std::static_pointer_cast<string>(configParamMap["dataSourceDetection"]);
objectName_ = *objectNamePropSptr.get();
std::shared_ptr<string> featureNamePropSptr = std::static_pointer_cast<string>(configParamMap["dataSourceFeature"]);
featureName_ = *featureNamePropSptr.get();
return APP_ERR_OK;
}
APP_ERROR DeepSort::DeInit()
{
LogInfo << "DeepSort::DeInit end.";
return APP_ERR_OK;
}
APP_ERROR DeepSort::GenerateSampleOutput (const MxpiObjectList srcMxpiObjectList,
const std::vector<TrackerInfo>& tracker_infos,
MxpiTrackLetList& dstMxpiTrackLetList)
{
for (int i = 0; i < tracker_infos.size(); i++) {
const TrackerInfo& r = tracker_infos[i];
int track_id = r.trackId;
int age = r.age;
int hits = r.hits;
int trackFlag = r.trackFlag;
MxpiTrackLet* dstMxpiTrackLet = dstMxpiTrackLetList.add_trackletvec();
MxpiMetaHeader* dstMxpiMetaHeaderList = dstMxpiTrackLet->add_headervec();
dstMxpiMetaHeaderList->set_datasource(parentName_);
dstMxpiMetaHeaderList->set_memberid(i);
dstMxpiTrackLet->set_trackid(track_id);
dstMxpiTrackLet->set_age(age);
dstMxpiTrackLet->set_hits(hits);
dstMxpiTrackLet->set_trackflag(trackFlag);
}
return APP_ERR_OK;
}
APP_ERROR DeepSort::Process(
std::vector<MxpiBuffer*>& mxpiBuffer) {
LogInfo << "DeepSort::Process start";
frame_id ++;
MxpiBuffer* buffer = mxpiBuffer[0];
MxpiMetadataManager mxpiMetadataManager(*buffer);
MxpiErrorInfo mxpiErrorInfo;
ErrorInfo_.str("");
auto errorInfoPtr = mxpiMetadataManager.GetErrorInfo();
if (errorInfoPtr != nullptr) {
ErrorInfo_ << GetError (APP_ERR_COMM_FAILURE, pluginName_) << "DeepSort process is not implemented";
mxpiErrorInfo.ret = APP_ERR_COMM_FAILURE;
mxpiErrorInfo.errorInfo = ErrorInfo_.str();
SetMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo);
LogError << "DeepSort process is not implemented";
return APP_ERR_COMM_FAILURE;
}
shared_ptr<void> objectMetadata = mxpiMetadataManager.GetMetadata(objectName_);
if (objectMetadata == nullptr) {
ErrorInfo_ << GetError(APP_ERR_METADATA_IS_NULL, pluginName_) << "objectMetadata is NULL, failed";
mxpiErrorInfo.ret = APP_ERR_METADATA_IS_NULL;
mxpiErrorInfo.errorInfo = ErrorInfo_.str();
SetMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo);
return APP_ERR_METADATA_IS_NULL;
}
shared_ptr<void> featureMetadata = mxpiMetadataManager.GetMetadata(featureName_);
if (featureMetadata == nullptr) {
ErrorInfo_ << GetError(APP_ERR_METADATA_IS_NULL, pluginName_) << "featureMetadata is NULL, failed";
mxpiErrorInfo.ret = APP_ERR_METADATA_IS_NULL;
mxpiErrorInfo.errorInfo = ErrorInfo_.str();
SetMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo);
return APP_ERR_METADATA_IS_NULL;
}
std::shared_ptr<MxpiObjectList> objectList = std::static_pointer_cast<MxpiObjectList>(
mxpiMetadataManager.GetMetadata(objectName_));
std::shared_ptr<MxpiFeatureVectorList> featureList;
std::vector<DetectObject> detectObjectList;
if (objectList->objectvec_size() == 0) {
LogDebug << "Object detection result of model infer is null.";
return APP_ERR_OK;
}
LogInfo << "object size : " << objectList->objectvec_size();
featureList = std::static_pointer_cast<MxpiFeatureVectorList>(
mxpiMetadataManager.GetMetadata(featureName_));
if (featureList->featurevec_size() == 0) {
APP_ERROR ret = APP_ERR_COMM_FAILURE;
errorInfo_ << GetError(ret, featureName_) << "Face short feature result of model infer is null.";
return ret;
}
for (int i = 0; i < objectList->objectvec_size(); ++i) {
DetectObject detectObject {};
detectObject.detectInfo = objectList->objectvec(i);
detectObject.memberId = static_cast<uint32_t>(i);
GetFeatureVector(featureList, i, detectObject);
detectObjectList.push_back(detectObject);
}
DETECTIONS detections;
for (int i = 0; i < detectObjectList.size(); ++i)
{
DETECTION_ROW detection;
DetectObject& detectObject = detectObjectList[i];
const MxTools::MxpiObject& detect_info = detectObject.detectInfo;
float x0 = detect_info.x0();
float y0 = detect_info.y0();
float x1 = detect_info.x1();
float y1 = detect_info.y1();
detection. tlwh(0, 0) = y0;
detection. tlwh(0, 1) = x0;
detection. tlwh(0, TWO) = x1-x0;
detection. tlwh(0, THREE) = y1-y0;
const auto& class_info = detect_info.classvec();
float confi = class_info[0].confidence();
detection. confidence = confi;
const auto& feature_Vector = detectObject.featureVector;
for (int j = 0; j < feature_Vector.featurevalues_size(); j++)
{
float value = feature_Vector.featurevalues(j);
detection. feature (0, j) = value;
}
detections.push_back(detection);
}
LogInfo << "predict ------";
mytracker.predict();
std::vector<std::pair<int, int>> det_track_idxs = mytracker.update(detections);
sort (det_track_idxs.begin(), det_track_idxs.end(),
[](std::pair<int, int>& d1, std::pair<int, int>& d2)
{
return d1.first < d2.first;
});
for (auto& track : mytracker.tracks)
{
LogInfo << "track id: " << track.track_id << ", age: " << track.age << ", hits: " << track.hits << ", state: " << track.state;
}
ofstream dataFile;
dataFile.open("gt.txt", ofstream::app);
fstream file("gt.txt", ios::app);
std::vector<TrackerInfo> tracker_infos;
for (const auto& det_track_idx : det_track_idxs)
{
int det_id = det_track_idx.first;
int track_idx = det_track_idx.second;
Track& track = mytracker.tracks[track_idx];
LogInfo << track.track_id << ",";
if (frame_id <= control) {
dataFile<<frame_id<<","<< track.track_id<<","<<int(detections[det_id].tlwh(0, 1))<<","<<int(detections[det_id].tlwh(0, 0))<<","<<int(detections[det_id].tlwh(0, TWO))<<","<<int(detections[det_id].tlwh(0, THREE))<<","<<1<<","<< 1 <<","<< 1 <<","<<endl;
}
TrackerInfo tracker_info;
tracker_info.trackId = track.track_id;
tracker_info.age = track.age;
tracker_info.hits = track.hits;
tracker_info.trackFlag = track.state == Track::Tentative ? 0 : track.state == Track::Confirmed ? 1 : track.state == Track::Deleted ? TWO : 0;
tracker_infos.push_back(tracker_info);
}
shared_ptr<MxpiTrackLetList> dstMxpiTrackLetListSptr = make_shared<MxpiTrackLetList>();
APP_ERROR ret = GenerateSampleOutput(*objectList, tracker_infos, *dstMxpiTrackLetListSptr);
if (ret != APP_ERR_OK) {
LogError << GetError(ret, pluginName_) << "DeepSort gets inference information failed.";
mxpiErrorInfo.ret = ret;
mxpiErrorInfo.errorInfo = ErrorInfo_.str();
SetMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo);
return ret;
}
ret = mxpiMetadataManager.AddProtoMetadata(pluginName_, static_pointer_cast<void>(dstMxpiTrackLetListSptr));
if (ret != APP_ERR_OK) {
ErrorInfo_ << GetError(ret, pluginName_) << "DeepSort add metadata failed.";
mxpiErrorInfo.ret = ret;
mxpiErrorInfo.errorInfo = ErrorInfo_.str();
SetMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo);
return ret;
}
SendData(0, *buffer);
LogInfo << "DeepSort::Process end";
return APP_ERR_OK;
}
void DeepSort::GetFeatureVector(const std::shared_ptr<MxTools::MxpiFeatureVectorList> &featureList,
const int32_t &memberId, DetectObject &detectObject)
{
for (int i = 0; i < featureList->featurevec_size(); ++i) {
if (featureList->featurevec(i).headervec_size() == 0) {
LogError << GetError(APP_ERR_COMM_OUT_OF_RANGE) << "protobuf message vector is invalid.";
return;
}
if (i == memberId) {
detectObject.featureVector = featureList->featurevec(i);
}
}
}
APP_ERROR DeepSort::SetMxpiErrorInfo(MxpiBuffer& buffer, const std::string pluginName,
const MxpiErrorInfo mxpiErrorInfo)
{
APP_ERROR ret = APP_ERR_OK;
MxpiMetadataManager mxpiMetadataManager(buffer);
ret = mxpiMetadataManager.AddErrorInfo(pluginName, mxpiErrorInfo);
if (ret != APP_ERR_OK) {
LogError << "Failed to AddErrorInfo.";
return ret;
}
ret = SendData(0, buffer);
return ret;
}
std::vector<std::shared_ptr<void>> DeepSort::DefineProperties()
{
std::vector<std::shared_ptr<void>> properties;
auto objectNameProSptr = std::make_shared<ElementProperty<string>>(ElementProperty<string> {
STRING, "dataSourceDetection", "inputName", "the name of fairmotpostprocessor", "mxpi_fairmot_obj", "NULL", "NULL"});
auto featureNameProSptr = std::make_shared<ElementProperty<string>>(ElementProperty<string> {
STRING, "dataSourceFeature", "inputName", "the name of fairmotpostprocessor", "mxpi_fairmot_fea", "NULL", "NULL"});
properties.push_back(objectNameProSptr);
properties.push_back(featureNameProSptr);
return properties;
}
MX_PLUGIN_GENERATE(DeepSort)

View File

@@ -0,0 +1,107 @@
/*
* 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.
*/
#ifndef SDKMEMORY_DEEPSORT_H
#define SDKMEMORY_DEEPSORT_H
#include "MxTools/PluginToolkit/base/MxPluginGenerator.h"
#include "MxTools/PluginToolkit/base/MxPluginBase.h"
#include "MxTools/PluginToolkit/metadata/MxpiMetadataManager.h"
#include "MxTools/Proto/MxpiDataType.pb.h"
#include "MxBase/ErrorCode/ErrorCode.h"
#include "track.h"
#include "tracker.h"
struct DetectObject {
uint32_t memberId;
MxTools::MxpiObject detectInfo;
MxTools::MxpiFeatureVector featureVector;
};
struct TrackerInfo {
uint32_t trackId;
uint32_t age; // 目标“存活”帧数
uint32_t hits; // 目标被成功记录帧数
int32_t trackFlag; // 路径记录状态 NEW_OBJECT = 0, TRACKED_OBJECT = 1, LOST_OBJECT = 2
DETECTBOX b;
};
/**
* @api
* @brief Definition of TrackIdReplaceClassName class.
*/
namespace MxPlugins {
class DeepSort : public MxTools::MxPluginBase {
public:
/**
* @api
* @brief Initialize configure parameter.
* @param configParamMap
* @return APP_ERROR
*/
APP_ERROR Init(std::map<std::string, std::shared_ptr<void>>& configParamMap) override;
/**
* @api
* @brief DeInitialize configure parameter.
* @return APP_ERROR
*/
APP_ERROR DeInit() override;
/**
* @api
* @brief Process the data of MxpiBuffer.
* @param mxpiBuffer
* @return APP_ERROR
*/
APP_ERROR Process(std::vector<MxTools::MxpiBuffer*>& mxpiBuffer) override;
/**
* @api
* @brief Definition the parameter of configure properties.
* @return std::vector<std::shared_ptr<void>>
*/
// static std::vector<std::shared_ptr<void>> DefineProperties();
/**
* @api
* @brief Replace className from mxpi_objectpostprocessor with trackId from mxpi_motsimplesortV2
* @param key
* @param buffer
* @return APP_ERROR
*/
static std::vector<std::shared_ptr<void>> DefineProperties();
/**
* @api
* @brief Replace className from mxpi_objectpostprocessor with trackId from mxpi_motsimplesortV2
* @param key
* @param buffer
* @return APP_ERROR
*/
APP_ERROR GenerateSampleOutput(const MxTools::MxpiObjectList srcMxpiObjectList,
const std::vector<TrackerInfo>& tracker_infos,
MxTools::MxpiTrackLetList& dstMxpiTrackLetList);
private:
APP_ERROR SetMxpiErrorInfo(MxTools::MxpiBuffer& buffer, const std::string pluginName, const MxTools::MxpiErrorInfo mxpiErrorInfo);
// APP_ERROR PrintMxpiErrorInfo(MxTools::MxpiBuffer& buffer, const std::string pluginName,
// const MxTools::MxpiErrorInfo mxpiErrorInfo, APP_ERROR app_error, std::string errorName);
void GetFeatureVector(const std::shared_ptr<MxTools::MxpiFeatureVectorList> &featureList,
const int32_t &memberId, DetectObject &detectObject);
std::string parentName_;
std::string objectName_;
std::string featureName_;
std::string descriptionMessage_;
std::ostringstream ErrorInfo_;
};
}
#endif // SDKMEMORY_DEEPSORT_H

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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.mitations under the License.
set -e
current_folder="$( cd "$(dirname "$0")" ;pwd -P )"
function build_plugin() {
build_path=$current_folder/build
if [ -d "$build_path" ]; then
rm -rf "$build_path"
else
echo "file $build_path is not exist."
fi
mkdir -p "$build_path"
cd "$build_path"
cmake ..
make -j
cd ..
exit 0
}
build_plugin
exit 0

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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.mitations under the License.
set -e
current_folder="$( cd "$(dirname "$0")" ;pwd -P )"
function move_so() {
build_path=$current_folder/build
if [ -d "$build_path" ]; then
echo "build is exist"
else
echo "file $build_path is not exist."
fi
chmod +w /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/libdeepsort.so
cd "$build_path"
cp libdeepsort.so /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/
chmod 440 /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/libdeepsort.so
cd ..
exit 0
}
move_so
exit 0

View File

@@ -0,0 +1,64 @@
/*
* Copyright (c) 2022.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.
*/
APP_ERROR MxpiMotSimpleSortBase::GetModelInferResult(MxpiBuffer &buffer, std::vector<DetectObject> &detectObjectList)
{
MxpiMetadataManager mxpiMetadataManager(buffer);
APP_ERROR ret = CheckDataStructure(mxpiMetadataManager);
if (ret != APP_ERR_OK) {
LogError << errorInfo_.str();
return ret;
}
std::shared_ptr<MxpiObjectList> objectList = std::static_pointer_cast<MxpiObjectList>(
mxpiMetadataManager.GetMetadata(dataSourceDetection_));
std::shared_ptr<MxpiFeatureVectorList> featureList;
if (objectList->objectvec_size() == 0) {
LogDebug << "Object detection result of model infer is null.";
return APP_ERR_OK;
}
if (withFeature_) {
featureList = std::static_pointer_cast<MxpiFeatureVectorList>(
mxpiMetadataManager.GetMetadata(dataSourceFeature_));
if (featureList->featurevec_size() == 0) {
ret = APP_ERR_COMM_FAILURE;
errorInfo_ << GetError(ret, elementName_) << "Face short feature result of model infer is null.";
return ret;
}
}
for (int i = 0; i < objectList->objectvec_size(); ++i) {
DetectObject detectObject {};
detectObject.detectInfo = objectList->objectvec(i);
detectObject.memberId = static_cast<uint32_t>(i);
if (withFeature_) {
GetFeatureVector(featureList, i, detectObject);
}
detectObjectList.push_back(detectObject);
}
return APP_ERR_OK;
}
void MxpiMotSimpleSortBase::GetFeatureVector(const std::shared_ptr<MxTools::MxpiFeatureVectorList> &featureList,
const int32_t &memberId, DetectObject &detectObject)
{
for (int i = 0; i < featureList->featurevec_size(); ++i) {
if (featureList->featurevec(i).headervec_size() == 0) {
LogError << GetError(APP_ERR_COMM_OUT_OF_RANGE) << "protobuf message vector is invalid.";
return;
}
if (featureList->featurevec(i).headervec(0).memberid() == memberId) {
detectObject.featureVector = featureList->featurevec(i);
}
}
}

View File

@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.5.2)
project(fairmotpostprocess)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_definitions(-Dgoogle=mindxsdk_private)
set(PLUGIN_NAME "fairmotpostprocess")
set(TARGET_LIBRARY ${PLUGIN_NAME})
set(MX_SDK_HOME "/home/wangshengke1/MindX_SDK/mxVision")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${MX_SDK_HOME}/include)
include_directories(${MX_SDK_HOME}/opensource/include)
include_directories(${MX_SDK_HOME}/opensource/include/gstreamer-1.0)
include_directories(${MX_SDK_HOME}/opensource/include/glib-2.0)
include_directories(${MX_SDK_HOME}/opensource/lib/glib-2.0/include)
include_directories(${MX_SDK_HOME}/opensource/include/opencv4)
link_directories(${MX_SDK_HOME}/lib)
link_directories(${MX_SDK_HOME}/opensource/lib)
add_compile_options(-std=c++11 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations)
add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}")
add_definitions(-DENABLE_DVPP_INTERFACE)
add_library(${TARGET_LIBRARY} SHARED FairmotPostProcess.cpp)
target_link_libraries(${TARGET_LIBRARY} glib-2.0 gstreamer-1.0 gobject-2.0 gstbase-1.0 gmodule-2.0 glog)
target_link_libraries(${TARGET_LIBRARY} mxpidatatype plugintoolkit mxbase mindxsdk_protobuf)

View File

@@ -0,0 +1,549 @@
/*
* 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.
*/
#include "FairmotPostProcess.h"
#include "MxBase/Log/Log.h"
#include "MxBase/Maths/FastMath.h"
#include "MxBase/CV/ObjectDetection/Nms/Nms.h"
#include "MxTools/Proto/MxpiDataType.pb.h"
#include "MxTools/PluginToolkit/buffer/MxpiBufferManager.h"
#include <typeinfo>
#define TWO 2
#define THREE 3
#define FOUR 4
#define REDUCE 0.5
#define REDUCE_NEG (-0.5)
using namespace MxBase;
using namespace MxPlugins;
using namespace MxTools;
using namespace std;
namespace {
const string INPUT_SHAPE_TYPE = "MxpiTensorPackageList";
const string METADATA_KEY_OBJ = "mxpi_fairmot_obj";
const string METADATA_KEY_FEA = "mxpi_fairmot_fea";
const float CONF_THRES = 0.35;
auto uint8Deleter = [] (uint8_t* p) { };
}
void GetTensors(const MxTools::MxpiTensorPackageList tensorPackageList,
std::vector<MxBase::TensorBase> &tensors) {
for (int i = 0; i < tensorPackageList.tensorpackagevec_size(); ++i) {
for (int j = 0; j < tensorPackageList.tensorpackagevec(i).tensorvec_size(); j++) {
MxBase::MemoryData memoryData = {};
memoryData.deviceId = tensorPackageList.tensorpackagevec(i).tensorvec(j).deviceid();
memoryData.type = (MxBase::MemoryData::MemoryType)tensorPackageList.
tensorpackagevec(i).tensorvec(j).memtype();
memoryData.size = (uint32_t) tensorPackageList.
tensorpackagevec(i).tensorvec(j).tensordatasize();
memoryData.ptrData = (void *) tensorPackageList.
tensorpackagevec(i).tensorvec(j).tensordataptr();
std::vector<uint32_t> outputShape = {};
for (int k = 0; k < tensorPackageList.
tensorpackagevec(i).tensorvec(j).tensorshape_size(); ++k) {
outputShape.push_back((uint32_t) tensorPackageList.
tensorpackagevec(i).tensorvec(j).tensorshape(k));
}
MxBase::TensorBase tmpTensor(memoryData, true, outputShape,
(MxBase::TensorDataType)tensorPackageList.
tensorpackagevec(i).tensorvec(j).tensordatatype());
tensors.push_back(tmpTensor);
}
}
}
void FairmotPostProcess::CoordinatesReduction(const uint32_t index,
const ResizedImageInfo &resizedImageInfo,
vector<ObjectInfo> &objInfos,
bool normalizedFlag)
{
if (!normalizedFlag) {
LogError << "Error CoordinatesReduction type in this example.";
}
int imgWidth = resizedImageInfo.widthOriginal;
int imgHeight = resizedImageInfo.heightOriginal;
float ratio = resizedImageInfo.keepAspectRatioScaling;
for (auto objInfo = objInfos.begin(); objInfo != objInfos.end();) {
objInfo->x0 *= resizedImageInfo.widthResize / ratio;
objInfo->y0 *= resizedImageInfo.heightResize / ratio;
objInfo->x1 *= resizedImageInfo.widthResize / ratio;
objInfo->y1 *= resizedImageInfo.heightResize / ratio;
if (objInfo->x0 > imgWidth || objInfo->y0 > imgHeight) {
objInfo = objInfos.erase(objInfo);
continue;
}
if (objInfo->x1 > imgWidth) {
objInfo->x1 = imgWidth;
}
if (objInfo->y1 > imgHeight) {
objInfo->y1 = imgHeight;
}
++objInfo;
}
}
APP_ERROR FairmotPostProcess::Init(std::map<std::string, std::shared_ptr<void>>& configParamMap) {
LogInfo << "FairmotPostProcess::Init start.";
APP_ERROR ret = APP_ERR_OK;
std::shared_ptr<string> parentNamePropSptr = std::static_pointer_cast<string>(configParamMap["dataSource"]);
parentName_ = *parentNamePropSptr.get();
std::shared_ptr<string> descriptionMessageProSptr = std::static_pointer_cast<string>(configParamMap["descriptionMessage"]);
descriptionMessage_ = *descriptionMessageProSptr.get();
return APP_ERR_OK;
}
APP_ERROR FairmotPostProcess::DeInit() {
LogInfo << "FairmotPostProcess::DeInit end.";
return APP_ERR_OK;
}
bool FairmotPostProcess::IsValidTensors(const std::vector <TensorBase> &tensors) {
int fairmotType_ = 4;
if (tensors.size() != (size_t) fairmotType_) {
LogError << "number of tensors (" << tensors.size() << ") " << "is unequal to fairmotType_("
<< fairmotType_ << ")";
return false;
}
return true;
}
APP_ERROR FairmotPostProcess::SetMxpiErrorInfo(MxpiBuffer& buffer, const std::string pluginName,
const MxpiErrorInfo mxpiErrorInfo) {
APP_ERROR ret = APP_ERR_OK;
MxpiMetadataManager mxpiMetadataManager(buffer);
ret = mxpiMetadataManager.AddErrorInfo(pluginName, mxpiErrorInfo);
if (ret != APP_ERR_OK) {
LogError << "Failed to AddErrorInfo.";
return ret;
}
ret = SendData(0, buffer);
return ret;
}
APP_ERROR FairmotPostProcess::PrintMxpiErrorInfo(MxpiBuffer& buffer, const std::string pluginName,
MxpiErrorInfo mxpiErrorInfo, APP_ERROR app_error, std::string errorName)
{
ErrorInfo_ << GetError(app_error, pluginName_) << errorName;
LogError << errorName;
mxpiErrorInfo.ret = app_error;
mxpiErrorInfo.errorInfo = ErrorInfo_.str();
SetMxpiErrorInfo(buffer, pluginName_, mxpiErrorInfo);
return app_error;
}
APP_ERROR FairmotPostProcess::GenerateresizedImageInfos(vector<MxpiBuffer*> mxpiBuffer,
const MxpiTensorPackageList srcMxpiTensorPackage,
vector <ResizedImageInfo> &resizedImageInfos)
{
auto dataSourceResize = srcMxpiTensorPackage.tensorpackagevec(0).headervec(0).datasource();
MxTools::MxpiMetadataManager mxpiMxpiMetadataManager(*mxpiBuffer[0]);
auto mxpiVisionList = std::static_pointer_cast<MxTools::MxpiVisionList>(
mxpiMxpiMetadataManager.GetMetadataWithType(dataSourceResize, "MxpiVisionList"));
if (mxpiVisionList == nullptr)
{
LogWarn << "Get mxpiVisionList failed from " << dataSourceResize;
return APP_ERR_OK;
}
else
{
for (size_t i = 0; i < mxpiVisionList->visionvec_size(); i++)
{
auto info = mxpiVisionList->visionvec(i).visioninfo();
MxBase::ResizedImageInfo reseizedImageInfo {
info.width(), info.height(), 0, 0, (MxBase::ResizeType)info.resizetype(), info.keepaspectratioscaling()
};
MxTools::MxpiFrame frameData = MxpiBufferManager::GetDeviceDataInfo(*mxpiBuffer[0]);
if (frameData.visionlist().visionvec_size() == 0)
{
reseizedImageInfo.widthOriginal = info.width();
reseizedImageInfo.heightOriginal = info.height();
}
else
{
reseizedImageInfo.widthOriginal = frameData.visionlist().visionvec(0).visioninfo().width();
reseizedImageInfo.heightOriginal = frameData.visionlist().visionvec(0).visioninfo().height();
}
resizedImageInfos.push_back(reseizedImageInfo);
}
}
return APP_ERR_OK;
}
int FairmotPostProcess::ObjectDetectionOutput(
const vector <TensorBase> &tensors,
vector <vector<ObjectInfo>> &objectInfos,
vector<vector<float>> &ID_feature,
const vector <ResizedImageInfo> &resizedImageInfos)
{
LogDebug << "FairmotPostProcess start to write results.";
if (tensors.size() == 0) {
return 0;
}
auto shape = tensors[0].GetShape();
if (shape.size() == 0) {
return 0;
}
std::vector <std::shared_ptr<void>> featLayerData = {};
std::vector <std::vector<size_t>> featLayerShapes = {};
for (uint32_t j = 0; j < tensors.size(); j++) {
auto dataPtr = (uint8_t *)tensors[j].GetBuffer();
std::shared_ptr<void> tmpPointer;
tmpPointer.reset(dataPtr, uint8Deleter);
featLayerData.push_back(tmpPointer);
shape = tensors[j].GetShape();
std::vector <size_t> featLayerShape = {};
for (auto s : shape) {
featLayerShape.push_back((size_t) s);
}
featLayerShapes.push_back(featLayerShape);
}
std::shared_ptr<void> hm_addr = featLayerData[0];
std::vector<std::vector<int>> XY;
for (uint32_t i = 0; i < featLayerShapes[0][1] * featLayerShapes[0][TWO]; i++) {
if (static_cast<float *>(hm_addr.get())[i] > CONF_THRES)
{
std::vector<int>xy;
int x = i / featLayerShapes[0][2];
int y = i - featLayerShapes[0][2] * x;
xy.push_back(x);
xy.push_back(y);
XY.push_back(xy);
}
}
if (XY.size() == 0) {
return 1;
}
std::vector<float>scores;
for (uint32_t i = 0; i < XY.size(); i++) {
scores.push_back(static_cast<float *>(hm_addr.get())[XY[i][0] * featLayerShapes[0][TWO] + XY[i][1]]);
}
std::shared_ptr<void> wh_addr = featLayerData[1];
std::shared_ptr<void> reg_addr = featLayerData[2];
std::vector<std::vector<float>>WH;
for (int i = 0; i < XY.size();i++) {
std::vector<float>wh;
for (int j = 0; j < featLayerShapes[1][THREE]; j++) {
wh.push_back(static_cast<float *>(wh_addr.get())[(XY[i][0] * featLayerShapes[0][TWO] + XY[i][1]) * featLayerShapes[1][THREE] + j]);
}
WH.push_back(wh);
}
std::vector<std::vector<float>>REG;
for (int i = 0; i < XY.size();i++) {
std::vector<float>reg;
for (int j = 0; j < featLayerShapes[TWO][THREE]; j++) {
reg.push_back(static_cast<float *>(reg_addr.get())[(XY[i][0] * featLayerShapes[0][TWO] + XY[i][1]) * featLayerShapes[TWO][THREE] + j]);
}
REG.push_back(reg);
}
std::shared_ptr<void> id_addr = featLayerData[3];
for (int i = 0; i < XY.size();i++) {
std::vector<float>id_feature;
for (int j = 0; j < featLayerShapes[THREE][THREE]; j++) {
id_feature.push_back(static_cast<float *>(id_addr.get())[(XY[i][0] * featLayerShapes[0][TWO] + XY[i][1]) * featLayerShapes[THREE][THREE] + j]);
}
ID_feature.push_back(id_feature);
}
std::vector<std::vector<float>> XY_f;
for (int i = 0; i < XY.size(); i++) {
std::vector<float>xy_f;
xy_f.push_back(XY[i][0]);
xy_f.push_back(XY[i][1]);
XY_f.push_back(xy_f);
}
for (int i = 0; i < XY_f.size(); i++) {
XY_f[i][1] = XY_f[i][1] + REG[i][0];
XY_f[i][0] = XY_f[i][0] + REG[i][1];
}
std::vector<std::vector<float>>dets;
for (int i = 0; i < XY.size(); i++) {
std::vector<float>det;
det.push_back(XY_f[i][1] - WH[i][0]);
det.push_back(XY_f[i][0] - WH[i][1]);
det.push_back(XY_f[i][1] + WH[i][TWO]);
det.push_back(XY_f[i][0] + WH[i][THREE]);
det.push_back(scores[i]);
det.push_back(0);
dets.push_back(det);
}
int width = resizedImageInfos[0].widthOriginal;
int height = resizedImageInfos[0].heightOriginal;
int inp_height = resizedImageInfos[0].heightResize;
int inp_width = resizedImageInfos[0].widthResize;
std::vector<float>c;
int half = 2;
c.push_back(width / half);
c.push_back(height / half);
std::vector<float>center(c);
float scale = 0;
scale = std::max(float(inp_width) / float(inp_height) * height, float(width)) * 1.0 ;
std::vector<float>Scale;
Scale.push_back(scale);
Scale.push_back(scale);
int down_ratio = 4;
int h = inp_height / down_ratio ;
int w = inp_width / down_ratio ;
std::vector<int>output_size;
output_size.push_back(w);
output_size.push_back(h);
int rot = 0;
std::vector<float>shift(TWO, 0);
int inv = 1;
std::vector<float>scale_tmp(Scale);
float src_w = scale_tmp[0];
int dst_w = output_size[0];
int dst_h = output_size[1];
float pi = 3.1415926;
int dir = 180;
float rot_rad = pi * rot / dir;
std::vector<float>src_point;
src_point.push_back(0);
src_point.push_back(src_w * (REDUCE_NEG));
float sn = sin(rot_rad);
float cs = cos(rot_rad);
std::vector<float>src_dir(TWO, 0);
src_dir[0] = src_point[0] * cs - src_point[1] * sn ;
src_dir[1] = src_point[0] * sn + src_point[1] * cs ;
std::vector<float>dst_dir;
dst_dir.push_back(0);
dst_dir.push_back(dst_w * (REDUCE_NEG));
float src[3][2] = {0};
float dst[3][2] = {0};
src[0][0] = center[0] + scale_tmp[0] * shift[0];
src[0][1] = center[1] + scale_tmp[1] * shift[1];
src[1][0] = center[0] + src_dir[0] + scale_tmp[0] * shift[0];
src[1][1] = center[1] + src_dir[1] + scale_tmp[1] * shift[1];
dst[0][0] = dst_w * REDUCE;
dst[0][1] = dst_h * REDUCE;
dst[1][0] = dst_w * REDUCE + dst_dir[0];
dst[1][1] = dst_h * REDUCE + dst_dir[1];
std::vector<float>direct;
direct.push_back(src[0][0]-src[1][0]);
direct.push_back(src[0][1]-src[1][1]);
src[TWO][0] = src[1][0] - direct[1];
src[TWO][1] = src[1][1] + direct[0];
direct[0] = dst[0][0] - dst[1][0];
direct[1] = dst[0][1] - dst[1][1];
dst[TWO][0] = dst[1][0] - direct[1];
dst[TWO][1] = dst[1][1] + direct[0];
cv::Point2f SRC[3];
cv::Point2f DST[3];
SRC[0] = cv::Point2f(src[0][0], src[0][1]);
SRC[1] = cv::Point2f(src[1][0], src[1][1]);
SRC[TWO] = cv::Point2f(src[TWO][0], src[TWO][1]);
DST[0] = cv::Point2f(dst[0][0], dst[0][1]);
DST[1] = cv::Point2f(dst[1][0], dst[1][1]);
DST[TWO] = cv::Point2f(dst[TWO][0], dst[TWO][1]);
cv::Mat trans(TWO, THREE, CV_64FC1);
if (inv == 1) {
trans = cv::getAffineTransform(DST, SRC);
}
else {
trans = cv::getAffineTransform(SRC, DST);
}
float Trans[2][3];
for (int i = 0; i < TWO; i++) {
for (int j = 0; j < THREE; j++) {
Trans[i][j] = trans.at<double>(i, j);
}
}
// affine_transform
// Calculate the coordinates of bbox_top_left x, y
for (int i = 0; i < dets.size(); i++) {
float new_pt[3] = {dets[i][0], dets[i][1], 1 };
dets[i][0] = Trans[0][0]* new_pt[0] + Trans[0][1]* new_pt[1] + Trans[0][TWO]* new_pt[TWO];
dets[i][1] = Trans[1][0]* new_pt[0] + Trans[1][1]* new_pt[1] + Trans[1][TWO]* new_pt[TWO];
}
// Calculate the coordinates of bbox_bottom_right x, y
for (int i = 0; i < dets.size(); i++) {
float new_pt[3] = {dets[i][2], dets[i][3], 1 };
dets[i][TWO] = Trans[0][0]* new_pt[0] + Trans[0][1]* new_pt[1] + Trans[0][TWO]* new_pt[TWO];
dets[i][THREE] = Trans[1][0]* new_pt[0] + Trans[1][1]* new_pt[1] + Trans[1][TWO]* new_pt[TWO];
}
// output
std::vector <ObjectInfo> objectInfo;
for (int i = 0; i < dets.size(); i++) {
ObjectInfo objInfo;
objInfo.classId = 0;
objInfo.confidence = dets[i][FOUR];
objInfo.className = " ";
// Normalization
objInfo.x0 = dets[i][0] / resizedImageInfos[0].widthOriginal;
objInfo.y0 = dets[i][1] / resizedImageInfos[0].heightOriginal;
objInfo.x1 = dets[i][TWO] / resizedImageInfos[0].widthOriginal;
objInfo.y1 = dets[i][THREE] / resizedImageInfos[0].heightOriginal;
objectInfo.push_back(objInfo);
}
objectInfos.push_back(objectInfo);
LogDebug << "FairmotPostProcess write results successed.";
return TWO;
}
APP_ERROR FairmotPostProcess::GenerateOutput(const MxTools::MxpiTensorPackageList srcMxpiTensorPackage,
std::vector <ResizedImageInfo> &resizedImageInfos,
MxTools::MxpiObjectList& dstMxpiObjectList,
MxpiFeatureVectorList& dstMxpiFeatureVectorList)
{
// Get Tensor
std::vector<MxBase::TensorBase> tensors = {};
GetTensors(srcMxpiTensorPackage, tensors);
// Check Tensor
bool isValid = IsValidTensors(tensors);
if (!isValid)
{
LogError << "Is unValid Tensors";
return APP_ERR_ACL_OP_INPUT_NOT_MATCH;
}
// Compute objects
std::vector<std::vector<ObjectInfo>> objectInfos;
std::vector<std::vector<float>> ID_feature;
int flag = ObjectDetectionOutput(tensors, objectInfos, ID_feature, resizedImageInfos);
if (flag == 1) {
// flag: 1 represents no pedestrians are detected
MxpiObject* dstMxpiObject = dstMxpiObjectList.add_objectvec();
MxpiClass* dstMxpiClass = dstMxpiObject->add_classvec();
MxpiFeatureVector* mxpiFeature = dstMxpiFeatureVectorList.add_featurevec();
MxpiMetaHeader* dstMxpiMetaHeaderList = mxpiFeature->add_headervec();
return APP_ERR_OK;
}
else if (flag == TWO) {
// flag: 2 represents pedestrian detected
for (uint32_t i = 0; i < resizedImageInfos.size(); i++) {
CoordinatesReduction(i, resizedImageInfos[i], objectInfos[i]);
}
// Generate ObjectList
for (size_t i = 0; i < objectInfos[0].size(); i++)
{
auto objInfo = objectInfos[0][i];
MxpiObject* dstMxpiObject = dstMxpiObjectList.add_objectvec();
MxpiMetaHeader* dstMxpiMetaHeaderList = dstMxpiObject->add_headervec();
dstMxpiMetaHeaderList->set_datasource(parentName_);
dstMxpiMetaHeaderList->set_memberid(0);
dstMxpiObject->set_x0(objInfo.x0);
dstMxpiObject->set_y0(objInfo.y0);
dstMxpiObject->set_x1(objInfo.x1);
dstMxpiObject->set_y1(objInfo.y1);
// Generate ClassList
MxpiClass* dstMxpiClass = dstMxpiObject->add_classvec();
MxpiMetaHeader* dstMxpiMetaHeaderList_c = dstMxpiClass->add_headervec();
dstMxpiMetaHeaderList_c->set_datasource(parentName_);
dstMxpiMetaHeaderList_c->set_memberid(0);
dstMxpiClass->set_classid(objInfo.classId);
dstMxpiClass->set_confidence(objInfo.confidence);
dstMxpiClass->set_classname(objInfo.className);
}
for (size_t i = 0; i < ID_feature.size(); i++)
{
MxpiFeatureVector* mxpiFeature = dstMxpiFeatureVectorList.add_featurevec();
MxpiMetaHeader* dstMxpiMetaHeaderList = mxpiFeature->add_headervec();
dstMxpiMetaHeaderList->set_datasource(parentName_);
dstMxpiMetaHeaderList->set_memberid(0);
for (size_t j = 0; j < ID_feature[i].size(); j++)
{
mxpiFeature->add_featurevalues(ID_feature[i][j]);
}
}
return APP_ERR_OK;
}
else {
// flag: 0 represents the input from tensorinfer is empty
LogError << "Is unValid Tensors";
return APP_ERR_ACL_OP_INPUT_NOT_MATCH;
}
}
APP_ERROR FairmotPostProcess::Process(std::vector<MxpiBuffer*>& mxpiBuffer) {
LogInfo << "FairmotPostProcess::Process start";
MxpiBuffer* buffer = mxpiBuffer[0];
MxpiMetadataManager mxpiMetadataManager(*buffer);
MxpiErrorInfo mxpiErrorInfo;
ErrorInfo_.str("");
auto errorInfoPtr = mxpiMetadataManager.GetErrorInfo();
if (errorInfoPtr != nullptr) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, APP_ERR_COMM_FAILURE, "FairmotPostProcess process is not implemented");
}
// Get the data from buffer
shared_ptr<void> metadata = mxpiMetadataManager.GetMetadata(parentName_);
if (metadata == nullptr) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, APP_ERR_METADATA_IS_NULL, "Metadata is NULL, failed");
}
// check the proto struct name
google::protobuf::Message* msg = (google::protobuf::Message*)metadata.get();
const google::protobuf::Descriptor* desc = msg->GetDescriptor();
if (desc->name() != INPUT_SHAPE_TYPE) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, APP_ERR_PROTOBUF_NAME_MISMATCH, "Proto struct name is not MxpiTensorPackageList, failed");
}
shared_ptr<MxpiTensorPackageList> srcMxpiTensorPackageListSptr = static_pointer_cast<MxpiTensorPackageList>(metadata);
shared_ptr<MxpiObjectList> dstMxpiObjectList = make_shared<MxpiObjectList>();
shared_ptr<MxpiFeatureVectorList> dstMxpiFeatureVectorList = make_shared<MxpiFeatureVectorList>();
std::vector <ResizedImageInfo> resizedImageInfos;
// Get resizedImageInfos
APP_ERROR ret = GenerateresizedImageInfos(mxpiBuffer, *srcMxpiTensorPackageListSptr, resizedImageInfos);
if (ret != APP_ERR_OK) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, ret, "Generate resizedImageInfos failed");
}
// Generate sample output
ret = GenerateOutput(*srcMxpiTensorPackageListSptr, resizedImageInfos, *dstMxpiObjectList, *dstMxpiFeatureVectorList);
if (ret != APP_ERR_OK) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, ret, "FairmotPostProcess gets inference information failed. Checkc tensor value!");
}
// Add Generated data to metedata
ret = mxpiMetadataManager.AddProtoMetadata(METADATA_KEY_OBJ, static_pointer_cast<void>(dstMxpiObjectList));
if (ret != APP_ERR_OK) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, ret, "FairmotPostProcess add MxpiObjectList metadata failed.");
}
ret = mxpiMetadataManager.AddProtoMetadata(METADATA_KEY_FEA, static_pointer_cast<void>(dstMxpiFeatureVectorList));
if (ret != APP_ERR_OK) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, ret, "FairmotPostProcess add MxpiFeatureVectorList metadata failed.");
}
// Send the data to downstream plugin
SendData(0, *buffer);
LogInfo << "FairmotPostProcess::Process end";
return APP_ERR_OK;
}
std::vector<std::shared_ptr<void>> FairmotPostProcess::DefineProperties()
{
// Define an A to store properties
std::vector<std::shared_ptr<void>> properties;
// Set the type and related information of the properties, and the key is the name
auto parentNameProSptr = std::make_shared<ElementProperty<string>>(ElementProperty<string> {
STRING, "dataSource", "name", "the name of previous plugin", "mxpi_tensorinfer0", "NULL", "NULL"});
auto descriptionMessageProSptr = std::make_shared<ElementProperty<string>>(ElementProperty<string> {
STRING, "descriptionMessage", "message", "Description mesasge of plugin", "This is FairmotPostProcess", "NULL", "NULL"});
properties.push_back(parentNameProSptr);
properties.push_back(descriptionMessageProSptr);
return properties;
}
// Register the Sample plugin through macro
MX_PLUGIN_GENERATE(FairmotPostProcess)

View File

@@ -0,0 +1,99 @@
/*
* 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.
*/
#ifndef SDKMEMORY_FairmotPostProcess_H
#define SDKMEMORY_FairmotPostProcess_H
#include "MxTools/PluginToolkit/base/MxPluginGenerator.h"
#include "MxTools/PluginToolkit/base/MxPluginBase.h"
#include "MxTools/PluginToolkit/metadata/MxpiMetadataManager.h"
#include "MxTools/Proto/MxpiDataType.pb.h"
#include "MxBase/ErrorCode/ErrorCode.h"
#include "MxBase/Tensor/TensorBase/TensorBase.h"
#include "opencv2/opencv.hpp"
#include "MxTools/PluginToolkit/PostProcessPluginBases/MxImagePostProcessorBase.h"
/**
* @api
* @brief Definition of FairmotPostProcess class.
*/
namespace MxPlugins {
class FairmotPostProcess : public MxTools::MxPluginBase {
public:
/**
* @api
* @brief Initialize configure parameter.
* @param configParamMap
* @return APP_ERROR
*/
APP_ERROR Init(std::map<std::string, std::shared_ptr<void>>& configParamMap) override;
/**
* @api
* @brief DeInitialize configure parameter.
* @return APP_ERROR
*/
APP_ERROR DeInit() override;
/**
* @api
* @brief Process the data of MxpiBuffer.
* @param mxpiBuffer
* @return APP_ERROR
*/
APP_ERROR Process(std::vector<MxTools::MxpiBuffer*>& mxpiBuffer) override;
/**
* @api
* @brief Definition the parameter of configure properties.
* @return std::vector<std::shared_ptr<void>>
*/
static std::vector<std::shared_ptr<void>> DefineProperties();
/**
* @api
* @brief Get the number of class id and confidence from model inference.
* @param key
* @param buffer
* @return APP_ERROR
*/
protected:
bool IsValidTensors(const std::vector <MxBase::TensorBase> &tensors);
APP_ERROR GenerateresizedImageInfos(std::vector<MxTools::MxpiBuffer*> mxpiBuffer,
const MxTools::MxpiTensorPackageList srcMxpiTensorPackage,
std::vector <MxBase::ResizedImageInfo> &resizedImageInfos);
APP_ERROR GenerateOutput(const MxTools::MxpiTensorPackageList srcMxpiTensorPackage,
std::vector <MxBase::ResizedImageInfo> &resizedImageInfos,
MxTools::MxpiObjectList& dstMxpiObjectList,
MxTools::MxpiFeatureVectorList& dstMxpiFeatureVectorList);
int ObjectDetectionOutput(const std::vector <MxBase::TensorBase> &tensors,
std::vector <std::vector<MxBase::ObjectInfo>> &objectInfos,
std::vector<std::vector<float>> &ID_feature,
const std::vector <MxBase::ResizedImageInfo> &resizedImageInfos = {});
void CoordinatesReduction(const uint32_t index,
const MxBase::ResizedImageInfo &resizedImageInfo,
std::vector<MxBase::ObjectInfo> &objInfos,
bool normalizedFlag = true);
private:
APP_ERROR SetMxpiErrorInfo(MxTools::MxpiBuffer& buffer, const std::string pluginName,
const MxTools::MxpiErrorInfo mxpiErrorInfo);
APP_ERROR PrintMxpiErrorInfo(MxTools::MxpiBuffer& buffer, const std::string pluginName,
const MxTools::MxpiErrorInfo mxpiErrorInfo, APP_ERROR app_error, std::string errorName);
std::string parentName_;
std::string descriptionMessage_;
std::ostringstream ErrorInfo_;
};
}
#endif // SDKMEMORY_FairmotPostProcess_H

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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.mitations under the License.
set -e
current_folder="$( cd "$(dirname "$0")" ;pwd -P )"
function build_plugin() {
build_path=$current_folder/build
if [ -d "$build_path" ]; then
rm -rf "$build_path"
else
echo "file $build_path is not exist."
fi
mkdir -p "$build_path"
cd "$build_path"
cmake ..
make -j
cd ..
exit 0
}
build_plugin
exit 0

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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.mitations under the License.
set -e
current_folder="$( cd "$(dirname "$0")" ;pwd -P )"
function move_so() {
build_path=$current_folder/build
if [ -d "$build_path" ]; then
echo "build is exist"
else
echo "file $build_path is not exist."
fi
chmod +w /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/libfairmotpostprocess.so
cd "$build_path"
cp libfairmotpostprocess.so /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/
chmod 440 /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/libfairmotpostprocess.so
cd ..
exit 0
}
move_so
exit 0

View File

@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.5.2)
project(mxpi_trackidreplaceclassname)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_definitions(-Dgoogle=mindxsdk_private)
set(PLUGIN_NAME "mxpi_trackidreplaceclassname")
set(TARGET_LIBRARY ${PLUGIN_NAME})
set(MX_SDK_HOME "/home/wangshengke1/MindX_SDK/mxVision")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${MX_SDK_HOME}/include)
include_directories(${MX_SDK_HOME}/opensource/include)
include_directories(${MX_SDK_HOME}/opensource/include/gstreamer-1.0)
include_directories(${MX_SDK_HOME}/opensource/include/glib-2.0)
include_directories(${MX_SDK_HOME}/opensource/lib/glib-2.0/include)
link_directories(${MX_SDK_HOME}/lib)
link_directories(${MX_SDK_HOME}/opensource/lib)
add_compile_options(-std=c++11 -fPIC -fstack-protector-all -pie -Wno-deprecated-declarations)
add_compile_options("-DPLUGIN_NAME=${PLUGIN_NAME}")
add_definitions(-DENABLE_DVPP_INTERFACE)
add_library(${TARGET_LIBRARY} SHARED MxpiTrackIdReplaceClassName.cpp)
target_link_libraries(${TARGET_LIBRARY} glib-2.0 gstreamer-1.0 gobject-2.0 gstbase-1.0 gmodule-2.0 glog)
target_link_libraries(${TARGET_LIBRARY} mxpidatatype plugintoolkit mxbase mindxsdk_protobuf)

View File

@@ -0,0 +1,166 @@
/*
* 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.
*/
#include "MxpiTrackIdReplaceClassName.h"
#include "MxBase/Log/Log.h"
#define TWO 2
using namespace MxPlugins;
using namespace MxTools;
using namespace std;
namespace {
const string SAMPLE_KEY = "MxpiObjectList";
const string SAMPLE_KEY2 = "MxpiTrackLetList";
}
APP_ERROR MxpiTrackIdReplaceClassName::Init(std::map<std::string, std::shared_ptr<void>>& configParamMap) {
LogInfo << "MxpiTrackIdReplaceClassName::Init start.";
APP_ERROR ret = APP_ERR_OK;
std::shared_ptr<string> parentNamePropSptr = std::static_pointer_cast<string>(configParamMap["dataSource"]);
parentName_ = *parentNamePropSptr.get();
std::shared_ptr<string> motNamePropSptr = std::static_pointer_cast<string>(configParamMap["motSource"]);
motName_ = *motNamePropSptr.get();
std::shared_ptr<string> descriptionMessageProSptr = std::static_pointer_cast<string>(configParamMap["descriptionMessage"]);
descriptionMessage_ = *descriptionMessageProSptr.get();
return APP_ERR_OK;
}
APP_ERROR MxpiTrackIdReplaceClassName::DeInit() {
LogInfo << "MxpiTrackIdReplaceClassName::DeInit end.";
return APP_ERR_OK;
}
APP_ERROR MxpiTrackIdReplaceClassName::SetMxpiErrorInfo(MxpiBuffer& buffer, const std::string pluginName,
const MxpiErrorInfo mxpiErrorInfo)
{
APP_ERROR ret = APP_ERR_OK;
MxpiMetadataManager mxpiMetadataManager(buffer);
ret = mxpiMetadataManager.AddErrorInfo(pluginName, mxpiErrorInfo);
if (ret != APP_ERR_OK) {
LogError << "Failed to AddErrorInfo.";
return ret;
}
ret = SendData(0, buffer);
return ret;
}
APP_ERROR MxpiTrackIdReplaceClassName::PrintMxpiErrorInfo(MxpiBuffer& buffer, const std::string pluginName,
MxpiErrorInfo mxpiErrorInfo, APP_ERROR app_error, std::string errorName)
{
ErrorInfo_ << GetError(app_error, pluginName_) << errorName;
LogError << errorName;
mxpiErrorInfo.ret = app_error;
mxpiErrorInfo.errorInfo = ErrorInfo_.str();
SetMxpiErrorInfo(buffer, pluginName_, mxpiErrorInfo);
return app_error;
}
APP_ERROR MxpiTrackIdReplaceClassName::GenerateSampleOutput(const MxpiObjectList srcMxpiObjectList,
const MxpiTrackLetList srcMxpiTrackLetList,
MxpiObjectList& dstMxpiObjectList)
{
for (int i = 0; i < srcMxpiObjectList.objectvec_size(); i++) {
MxpiObject srcMxpiObject = srcMxpiObjectList.objectvec(i);
MxpiClass srcMxpiClass = srcMxpiObject.classvec(0);
MxpiObject* dstMxpiObject = dstMxpiObjectList.add_objectvec();
dstMxpiObject->set_x0(srcMxpiObject.x0());
dstMxpiObject->set_y0(srcMxpiObject.y0());
dstMxpiObject->set_x1(srcMxpiObject.x1());
dstMxpiObject->set_y1(srcMxpiObject.y1());
MxpiClass* dstMxpiClass = dstMxpiObject->add_classvec();
dstMxpiClass->set_confidence(srcMxpiClass.confidence());
for (int j = 0; j < srcMxpiTrackLetList.trackletvec_size(); j++) {
MxpiTrackLet srcMxpiTrackLet = srcMxpiTrackLetList.trackletvec(j);
if (srcMxpiTrackLet.trackflag() != TWO) {
MxpiMetaHeader srcMxpiHeader = srcMxpiTrackLet.headervec(0);
if (srcMxpiHeader.memberid() == i) {
dstMxpiClass->set_classid(0);
dstMxpiClass->set_classname(to_string(srcMxpiTrackLet.trackid()));
continue;
}
}
}
}
return APP_ERR_OK;
}
APP_ERROR MxpiTrackIdReplaceClassName::Process(std::vector<MxpiBuffer*>& mxpiBuffer) {
LogInfo << "MxpiTrackIdReplaceClassName::Process start";
MxpiBuffer* buffer = mxpiBuffer[0];
MxpiMetadataManager mxpiMetadataManager(*buffer);
MxpiErrorInfo mxpiErrorInfo;
ErrorInfo_.str("");
auto errorInfoPtr = mxpiMetadataManager.GetErrorInfo();
if (errorInfoPtr != nullptr) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, APP_ERR_COMM_FAILURE, "MxpiTrackIdReplaceClassName process is not implemented");
}
shared_ptr<void> metadata = mxpiMetadataManager.GetMetadata(parentName_);
shared_ptr<void> metadata2 = mxpiMetadataManager.GetMetadata(motName_);
if (metadata == nullptr) {
shared_ptr<MxpiObjectList> dstMxpiObjectListSptr = make_shared<MxpiObjectList>();
MxpiObject* dstMxpiObject = dstMxpiObjectListSptr->add_objectvec();
MxpiClass* dstMxpiClass = dstMxpiObject->add_classvec();
APP_ERROR ret = mxpiMetadataManager.AddProtoMetadata(pluginName_, static_pointer_cast<void>(dstMxpiObjectListSptr));
if (ret != APP_ERR_OK) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, ret, "MxpiTrackIdReplaceClassName add metadata failed.");
}
SendData(0, *buffer);
LogInfo << "MxpiTrackIdReplaceClassName::Process end";
return APP_ERR_OK;
}
google::protobuf::Message* msg = (google::protobuf::Message*)metadata.get();
const google::protobuf::Descriptor* desc = msg->GetDescriptor();
google::protobuf::Message* msg2 = (google::protobuf::Message*)metadata2.get();
const google::protobuf::Descriptor* desc2 = msg2->GetDescriptor();
if (desc->name() != SAMPLE_KEY) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, APP_ERR_PROTOBUF_NAME_MISMATCH, "Proto struct name is not MxpiObjectList, failed");
}
if (desc2->name() != SAMPLE_KEY2) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, APP_ERR_PROTOBUF_NAME_MISMATCH, "Proto struct name is not MxpiTrackLetList, failed");
}
shared_ptr<MxpiObjectList> srcMxpiObjectListSptr = static_pointer_cast<MxpiObjectList>(metadata);
shared_ptr<MxpiTrackLetList> srcMxpiTrackLetListSptr = static_pointer_cast<MxpiTrackLetList>(metadata2);
shared_ptr<MxpiObjectList> dstMxpiObjectListSptr = make_shared<MxpiObjectList>();
APP_ERROR ret = GenerateSampleOutput(*srcMxpiObjectListSptr, *srcMxpiTrackLetListSptr, *dstMxpiObjectListSptr); // Generate sample output
if (ret != APP_ERR_OK) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, ret, "MxpiTrackIdReplaceClassName gets inference information failed.");
}
ret = mxpiMetadataManager.AddProtoMetadata(pluginName_, static_pointer_cast<void>(dstMxpiObjectListSptr)); // Add Generated data to metedata
if (ret != APP_ERR_OK) {
return PrintMxpiErrorInfo(*buffer, pluginName_, mxpiErrorInfo, ret, "MxpiTrackIdReplaceClassName add metadata failed.");
}
SendData(0, *buffer);
LogInfo << "MxpiTrackIdReplaceClassName::Process end";
return APP_ERR_OK;
}
std::vector<std::shared_ptr<void>> MxpiTrackIdReplaceClassName::DefineProperties() {
std::vector<std::shared_ptr<void>> properties;
auto parentNameProSptr = std::make_shared<ElementProperty<string>>(ElementProperty<string> {
STRING, "dataSource", "inputName", "the name of fairmotpostprocessor", "mxpi_fairmot_obj", "NULL", "NULL"});
auto motNameProSptr = std::make_shared<ElementProperty<string>>(ElementProperty<string> {
STRING, "motSource", "parentName", "the name of previous plugin", "mxpi_motsimplesortV20", "NULL", "NULL"});
auto descriptionMessageProSptr = std::make_shared<ElementProperty<string>>(ElementProperty<string> {
STRING, "descriptionMessage", "message", "Description mesasge of plugin", "This is MxpiTrackIdReplaceClassName", "NULL", "NULL"});
properties.push_back(parentNameProSptr);
properties.push_back(motNameProSptr);
properties.push_back(descriptionMessageProSptr);
return properties;
}
MX_PLUGIN_GENERATE(MxpiTrackIdReplaceClassName)

View File

@@ -0,0 +1,79 @@
/*
* 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.
*/
#ifndef SDKMEMORY_MXPITRACKIDREPLACECLASSNAME_H
#define SDKMEMORY_MXPITRACKIDREPLACECLASSNAME_H
#include "MxTools/PluginToolkit/base/MxPluginGenerator.h"
#include "MxTools/PluginToolkit/base/MxPluginBase.h"
#include "MxTools/PluginToolkit/metadata/MxpiMetadataManager.h"
#include "MxTools/Proto/MxpiDataType.pb.h"
#include "MxBase/ErrorCode/ErrorCode.h"
/**
* @api
* @brief Definition of TrackIdReplaceClassName class.
*/
namespace MxPlugins {
class MxpiTrackIdReplaceClassName : public MxTools::MxPluginBase {
public:
/**
* @api
* @brief Initialize configure parameter.
* @param configParamMap
* @return APP_ERROR
*/
APP_ERROR Init(std::map<std::string, std::shared_ptr<void>>& configParamMap) override;
/**
* @api
* @brief DeInitialize configure parameter.
* @return APP_ERROR
*/
APP_ERROR DeInit() override;
/**
* @api
* @brief Process the data of MxpiBuffer.
* @param mxpiBuffer
* @return APP_ERROR
*/
APP_ERROR Process(std::vector<MxTools::MxpiBuffer*>& mxpiBuffer) override;
/**
* @api
* @brief Definition the parameter of configure properties.
* @return std::vector<std::shared_ptr<void>>
*/
static std::vector<std::shared_ptr<void>> DefineProperties();
/**
* @api
* @brief Replace className from mxpi_objectpostprocessor with trackId from mxpi_motsimplesortV2
* @param key
* @param buffer
* @return APP_ERROR
*/
APP_ERROR GenerateSampleOutput(const MxTools::MxpiObjectList srcMxpiObjectList,
const MxTools::MxpiTrackLetList srcMxpiTrackLetList,
MxTools::MxpiObjectList& dstMxpiObjectList);
private:
APP_ERROR SetMxpiErrorInfo(MxTools::MxpiBuffer& buffer, const std::string pluginName,
const MxTools::MxpiErrorInfo mxpiErrorInfo);
APP_ERROR PrintMxpiErrorInfo(MxTools::MxpiBuffer& buffer, const std::string pluginName,
const MxTools::MxpiErrorInfo mxpiErrorInfo, APP_ERROR app_error, std::string errorName);
std::string parentName_;
std::string motName_;
std::string descriptionMessage_;
std::ostringstream ErrorInfo_;
};
}
#endif // SDKMEMORY_MXPITRACKIDREPLACECLASSNAME_H

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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.mitations under the License.
set -e
current_folder="$( cd "$(dirname "$0")" ;pwd -P )"
function build_plugin() {
build_path=$current_folder/build
if [ -d "$build_path" ]; then
rm -rf "$build_path"
else
echo "file $build_path is not exist."
fi
mkdir -p "$build_path"
cd "$build_path"
cmake ..
make -j
cd ..
exit 0
}
build_plugin
exit 0

View File

@@ -0,0 +1,36 @@
#!/bin/bash
# Copyright 2021 Huawei Technologies Co., Ltd
#
# 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.mitations under the License.
set -e
current_folder="$( cd "$(dirname "$0")" ;pwd -P )"
function move_so() {
build_path=$current_folder/build
if [ -d "$build_path" ]; then
echo "build is exist"
else
echo "file $build_path is not exist."
fi
chmod +w /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/libmxpi_trackidreplaceclassname.so
cd "$build_path"
cp libmxpi_trackidreplaceclassname.so /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/
chmod 440 /home/wangshengke1/MindX_SDK/mxVision/lib/plugins/libmxpi_trackidreplaceclassname.so
cd ..
exit 0
}
move_so
exit 0

31
deepsort/run.sh Normal file
View File

@@ -0,0 +1,31 @@
#!/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
CUR_PATH=$(cd "$(dirname "$0")" || { warn "Failed to check path/to/run.sh" ; exit ; } ; pwd)
# Simple log helper functions
info() { echo -e "\033[1;34m[INFO ][MxStream] $1\033[1;37m" ; }
warn() { echo >&2 -e "\033[1;31m[WARN ][MxStream] $1\033[1;37m" ; }
# complie
cmake -S . -Bbuild
make -C ./build -j
# run
./main
exit 0