From bc39a492085eb4a94881034bced24c4f57c74939 Mon Sep 17 00:00:00 2001 From: Malanchi Date: Wed, 18 Dec 2024 18:53:13 +0800 Subject: [PATCH 1/9] =?UTF-8?q?protocalsample=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/README.md | 71 +++++++++++++++- tutorials/protocolSample/main.py | 130 ----------------------------- 2 files changed, 70 insertions(+), 131 deletions(-) delete mode 100644 tutorials/protocolSample/main.py diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index 8b408d557..708dc46d1 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -1,4 +1,73 @@ # protocolSample 样例说明 * 本样例构建一个metadata的protocol数据并送入stream,随后输出至log * 上传一张jpg格式图片并重命名为test.jpg,在运行目录下执行run.sh。请勿使用大分辨率图片 -* 如构建的proto数据正确则可在命令行输出中看到warn登记的日志,以"Output:"开头 \ No newline at end of file + + +# SampleOsd 样例说明 + +## 1 介绍 +### 1.1 简介 +* 本样例构建一个metadata的protocol数据并送入stream,随后输出至log + +* 上传一张jpg格式图片并重命名为test.jpg,在运行目录下执行run.sh。请勿使用大分辨率图片 + +### 1.2 支持的产品 +本项目支持昇腾Atlas 300I pro、 Atlas 300V pro。 + +### 1.3 支持的版本 +本样例配套的MxVision版本、CANN版本、Driver/Firmware版本: + +| MxVision版本 | CANN版本 | Driver/Firmware版本 | +| --------- | ------------------ | -------------- | +| 6.0.RC3 | 8.0.RC3 | 24.1.RC3 | + +### 1.4 代码目录结构说明 + +``` +. +| +|-------- CMakeLists.txt +|-------- main.cpp +|-------- run.sh +|-------- pipeSample.pipeline +|-------- README.md // ReadMe +|-------- test.jpg + +``` + +## 2 设置环境变量 + + ``` +# 设置环境变量(请确认SDK_INSTALL_PATH路径是否正确) +. /usr/local/Ascend/ascend-toolkit/set_env.sh #toolkit默认安装路径,根据实际安装路径修改 +. ${SDK_INSTALL_PATH}/mxVision/set_env.sh + ``` + +## 3 准备模型 +```bash +#设置CANN环境变量,ascend-toolkit-path为cann安装路径 +. ${ascend-toolkit-path}/set_env.sh + +#设置MindX SDK 环境变量,SDK-path为mxVision SDK 安装路径 +. ${SDK-path}/set_env.sh +``` + +## 4 编译与运行 + +**步骤1**:图片准备 +``` +准备一张测试图片,项目文件中并重命名为 `test.jpg` +``` + +**步骤2**:编译与运行 + +执行以下命令: +```bash +bash run.sh # 编译 +./main # 执行 +``` + +**步骤3**:查看结果 +``` +*如构建的proto数据正确则可在命令行输出中看到warn登记的日志,以"Output:"开头 +``` diff --git a/tutorials/protocolSample/main.py b/tutorials/protocolSample/main.py deleted file mode 100644 index ef945da41..000000000 --- a/tutorials/protocolSample/main.py +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -from os import pipe -import MxpiDataType_pb2 as MxpiDataType -from StreamManagerApi import StreamManagerApi, \ - MxDataInput, MxProtobufIn, InProtobufVector, MxBufferInput, \ - MxMetadataInput, MetadataInputVector, StringVector - -if __name__ == '__main__': - # type1:SendData type2:SendProtobuf - INTERFACE_TYPE = 1 - - # init stream manager - stream_mgr_api = StreamManagerApi() - ret = stream_mgr_api.InitManager() - if ret != 0: - print("Failed to init Stream manager, ret=%s" %str(ret)) - exit() - - # creat streams by pipeline file - with open("./pipeSample.pipeline", 'rb') as f: - pipeline_str = f.read() - ret = stream_mgr_api.CreateMultipleStream(pipeline_str) - if ret != 0: - print("Failed to create stream, ret=%s" %str(ret)) - exit() - - # Construct the input of the stream - data_input = MxDataInput() - with open("test.jpg", 'rb') as f: - data_input.data = f.read() - - stream_name = b'pipeSample' - inplugin_id = 0 - elment_name = b'appsrc0' - - if INTERFACE_TYPE == 1: - # streamName: bytes, elementName: bytes, data_input: MxDataInput - # Input data to a specified stream based on streamName - - # build senddata data source - frame_info = MxpiDataType.MxpiFrameInfo() - frame_info.frameId = 0 - frame_info.channelId = 0 - - vision_list = MxpiDataType.MxpiVisionList() - vision_vec = vision_list.visionVec.add() - vision_vec.visionData.dataStr = data_input.data - - buffer_input = MxBufferInput() - buffer_input.mxpiFrameInfo = frame_info.SerializeToString() - buffer_input.mxpiVisionInfo = vision_vec.SerializeToString() - buffer_input.data = data_input.data - - metedata_input = MxMetadataInput() - metedata_input.dataSource = elment_name - metedata_input.dataType = b"MxTools.MxpiVisionList" - metedata_input.serializedMetadaata = vision_list.SerializeToString() - - metedata_vec = MetadataInputVector() - metedata_vec.push_back(metedata_input) - - error_code = stream_mgr_api.\ - SendData(stream_name, elment_name, metedata_vec, buffer_input) - - if error_code < 0: - print("Failed to send data to stream.") - exit() - - data_source_vector = StringVector() - data_source_vector.push_back(elment_name) - - infer_result = stream_mgr_api.\ - GetResult(stream_name, b'appsink0', data_source_vector) - - # print the infer result - if (infer_result.errorCode != 0): - print("GetResult failed") - exit() - - if (infer_result.bufferOutput.data is None): - print("bufferOutput nullptr") - exit() - - print("result: {}".format(infer_result.bufferOutput.data.decode())) - - elif INTERFACE_TYPE == 2: - # streanName: bytes, inPluginId: int, protobufVec: list - # Input data to specified stream base on inplugin_id - - vision_list = MxpiDataType.MxpiVisionList() - vision_vec = vision_list.visionVec.add() - vision_vec.visionData.dataStr = data_input.data - - protobuf = MxProtobufIn() - protobuf.key = elment_name - protobuf.type = b'MxTools.MxpiVisionList' - protobuf.protobuf = vision_list.SerializeToString() - protobuf_vec = InProtobufVector() - protobuf_vec.push_back(protobuf) - - error_code = stream_mgr_api. \ - SendProtobuf(stream_name, inplugin_id, protobuf_vec) - if error_code < 0: - print("Failed to send data to stream.") - exit() - - key_vec = StringVector() - key_vec.push_back(elment_name) - infer_result = stream_mgr_api. \ - GetProtobuf(stream_name, inplugin_id, key_vec) - if infer_result.size() == 0: - print("infer_result is null") - exit() - if infer_result[0].errorCode != 0: - print("infer_result error. \ - errorCode=%d" % (infer_result[0].errorCode)) - exit() - - # print the infer result - print("GetProtobuf errorCode=%d" % (infer_result[0].errorCode)) - print("KEY: {}".format(str(infer_result[0].messageName))) - - result_visionlist = MxpiDataType.MxpiVisionList() - result_visionlist.ParseFromString(infer_result[0].messageBuf) - print("result: {}".format( - result_visionlist.visionVec[0].visionData.dataStr)) - - # destroy streams - stream_mgr_api.DestroyAllStreams() \ No newline at end of file -- Gitee From 56e6ed318c9f2fc222955a47daeaaa31af58433b Mon Sep 17 00:00:00 2001 From: Malanchi Date: Wed, 18 Dec 2024 19:36:48 +0800 Subject: [PATCH 2/9] =?UTF-8?q?protocalSample=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/README.md | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index 708dc46d1..704df0503 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -1,9 +1,4 @@ # protocolSample 样例说明 -* 本样例构建一个metadata的protocol数据并送入stream,随后输出至log -* 上传一张jpg格式图片并重命名为test.jpg,在运行目录下执行run.sh。请勿使用大分辨率图片 - - -# SampleOsd 样例说明 ## 1 介绍 ### 1.1 简介 @@ -37,13 +32,6 @@ ## 2 设置环境变量 - ``` -# 设置环境变量(请确认SDK_INSTALL_PATH路径是否正确) -. /usr/local/Ascend/ascend-toolkit/set_env.sh #toolkit默认安装路径,根据实际安装路径修改 -. ${SDK_INSTALL_PATH}/mxVision/set_env.sh - ``` - -## 3 准备模型 ```bash #设置CANN环境变量,ascend-toolkit-path为cann安装路径 . ${ascend-toolkit-path}/set_env.sh @@ -52,7 +40,8 @@ . ${SDK-path}/set_env.sh ``` -## 4 编译与运行 + +## 3 编译与运行 **步骤1**:图片准备 ``` -- Gitee From 5acca1fe33d03fa9a3466fc28c0a248bb768f51e Mon Sep 17 00:00:00 2001 From: Malanchi Date: Thu, 19 Dec 2024 09:18:49 +0800 Subject: [PATCH 3/9] =?UTF-8?q?protocal=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/README.md | 14 +++++++++++--- tutorials/protocolSample/main.cpp | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index 704df0503..664c7960f 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -43,12 +43,20 @@ ## 3 编译与运行 -**步骤1**:图片准备 +**步骤1**:修改日志配置 + +修改${SDK-path}/config/logging.conf中的第21行console_level为0 + +```bash +21 console_level=0 +``` + +**步骤2**:图片准备 ``` 准备一张测试图片,项目文件中并重命名为 `test.jpg` ``` -**步骤2**:编译与运行 +**步骤3**:编译与运行 执行以下命令: ```bash @@ -58,5 +66,5 @@ bash run.sh # 编译 **步骤3**:查看结果 ``` -*如构建的proto数据正确则可在命令行输出中看到warn登记的日志,以"Output:"开头 +如构建的proto数据正确则可在命令行输出中看到warn登记的日志,以"Output:"开头 ``` diff --git a/tutorials/protocolSample/main.cpp b/tutorials/protocolSample/main.cpp index a4cc81e66..a05cc1736 100644 --- a/tutorials/protocolSample/main.cpp +++ b/tutorials/protocolSample/main.cpp @@ -109,7 +109,7 @@ namespace protocol_example { namespace { constexpr int COS_LEN_VALUE = 416; constexpr int COS_FORMAT_VALUE = 12; - constexpr bool USE_SENDDATA = false; // switch different send data method + constexpr bool USE_SENDDATA = true; // switch different send data method // read data File to MxstDataInput structure APP_ERROR ReadFile(const std::string& filePath, MxStream::MxstDataInput& dataBuffer) -- Gitee From 280e91f3bb7277075cfa347087d4d2e135ae783b Mon Sep 17 00:00:00 2001 From: Malanchi Date: Thu, 19 Dec 2024 09:24:29 +0800 Subject: [PATCH 4/9] =?UTF-8?q?protocal=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/README.md | 3 +-- tutorials/protocolSample/run.sh | 14 -------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index 664c7960f..fdf01c0f0 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -60,8 +60,7 @@ 执行以下命令: ```bash -bash run.sh # 编译 -./main # 执行 +bash run.sh ``` **步骤3**:查看结果 diff --git a/tutorials/protocolSample/run.sh b/tutorials/protocolSample/run.sh index 64381a3c1..c245b83c0 100644 --- a/tutorials/protocolSample/run.sh +++ b/tutorials/protocolSample/run.sh @@ -14,20 +14,6 @@ # 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;34m[WARN ][MxStream] $1\033[1;37m" ; } - -# set env -export MX_SDK_HOME="${CUR_PATH}/../../.." -export 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":${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" - # complie cmake -S . -B build make -C ./build -j -- Gitee From 05b331741b88c5225c9a41b09747fafeeae3b946 Mon Sep 17 00:00:00 2001 From: Malanchi Date: Thu, 19 Dec 2024 09:28:01 +0800 Subject: [PATCH 5/9] =?UTF-8?q?protocal=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/CMakeLists.txt | 6 +++--- tutorials/protocolSample/README.md | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tutorials/protocolSample/CMakeLists.txt b/tutorials/protocolSample/CMakeLists.txt index 3c7b9dfdd..5aa234fb1 100644 --- a/tutorials/protocolSample/CMakeLists.txt +++ b/tutorials/protocolSample/CMakeLists.txt @@ -1,10 +1,10 @@ -cmake_minimum_required(VERSION 3.18) +cmake_minimum_required(VERSION 3.16) project(pipeSample) set(CMAKE_CXX_STANDARD 14) set(CMAKE_BUILD_TYPE Debug) -set(MX_SDK_HOME /usr/local/Ascend/mxVision) +set(MX_SDK_HOME "$ENV{MX_SDK_HOME}") if (NOT DEFINED ENV{MX_SDK_HOME}) string(REGEX REPLACE "(.*)/(.*)/(.*)/(.*)" "\\1" MX_SDK_HOME ${CMAKE_CURRENT_SOURCE_DIR}) @@ -16,7 +16,7 @@ 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) +add_compile_options(-std=c++14 -fPIC -fstack-protector-all -Wall) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack -pie") diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index fdf01c0f0..8c8637ec0 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -16,7 +16,13 @@ | --------- | ------------------ | -------------- | | 6.0.RC3 | 8.0.RC3 | 24.1.RC3 | -### 1.4 代码目录结构说明 +### 1.4 三方依赖 + +| 软件名称 | 版本 | +|-------|------| +| cmake | 3.16 | + +### 1.5 代码目录结构说明 ``` . @@ -25,8 +31,8 @@ |-------- main.cpp |-------- run.sh |-------- pipeSample.pipeline -|-------- README.md // ReadMe -|-------- test.jpg +|-------- README.md +|-------- test.jpg // 需用户准备 ``` -- Gitee From 8134789384a98f4c88eb3ef57e43363d503547a6 Mon Sep 17 00:00:00 2001 From: Malanchi Date: Thu, 19 Dec 2024 09:29:19 +0800 Subject: [PATCH 6/9] =?UTF-8?q?protocal=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index 8c8637ec0..e6fdfc21c 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -69,7 +69,7 @@ bash run.sh ``` -**步骤3**:查看结果 +**步骤4**:查看结果 ``` 如构建的proto数据正确则可在命令行输出中看到warn登记的日志,以"Output:"开头 ``` -- Gitee From 42e83eacab8e6943e593ae976a1f138749d36d0a Mon Sep 17 00:00:00 2001 From: Malanchi Date: Thu, 19 Dec 2024 09:30:56 +0800 Subject: [PATCH 7/9] =?UTF-8?q?protocal=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index e6fdfc21c..f76b346a8 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -4,10 +4,12 @@ ### 1.1 简介 * 本样例构建一个metadata的protocol数据并送入stream,随后输出至log -* 上传一张jpg格式图片并重命名为test.jpg,在运行目录下执行run.sh。请勿使用大分辨率图片 +* 上传一张jpg格式图片并重命名为test.jpg,在运行目录下执行run.sh + +* 请勿使用大分辨率图片 ### 1.2 支持的产品 -本项目支持昇腾Atlas 300I pro、 Atlas 300V pro。 +本项目支持昇腾Atlas 300I pro、 Atlas 300V pro ### 1.3 支持的版本 本样例配套的MxVision版本、CANN版本、Driver/Firmware版本: -- Gitee From f60a6fb6b2a92b3d365038f244051f629951e1ec Mon Sep 17 00:00:00 2001 From: Malanchi Date: Thu, 19 Dec 2024 09:45:10 +0800 Subject: [PATCH 8/9] =?UTF-8?q?protocal=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index f76b346a8..b6aef3379 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -4,10 +4,6 @@ ### 1.1 简介 * 本样例构建一个metadata的protocol数据并送入stream,随后输出至log -* 上传一张jpg格式图片并重命名为test.jpg,在运行目录下执行run.sh - -* 请勿使用大分辨率图片 - ### 1.2 支持的产品 本项目支持昇腾Atlas 300I pro、 Atlas 300V pro @@ -61,7 +57,7 @@ **步骤2**:图片准备 ``` -准备一张测试图片,项目文件中并重命名为 `test.jpg` +准备一张测试图片,项目文件中并重命名为 `test.jpg`,请勿使用大分辨率图片 ``` **步骤3**:编译与运行 -- Gitee From d64b10cc4dd118c710f6a6fa159272cae72a6e40 Mon Sep 17 00:00:00 2001 From: Malanchi Date: Thu, 19 Dec 2024 09:46:24 +0800 Subject: [PATCH 9/9] =?UTF-8?q?protocal=E9=80=82=E9=85=8D310P?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutorials/protocolSample/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/protocolSample/README.md b/tutorials/protocolSample/README.md index b6aef3379..89c840aac 100644 --- a/tutorials/protocolSample/README.md +++ b/tutorials/protocolSample/README.md @@ -2,7 +2,7 @@ ## 1 介绍 ### 1.1 简介 -* 本样例构建一个metadata的protocol数据并送入stream,随后输出至log +本样例构建一个metadata的protocol数据并送入stream,随后输出至log ### 1.2 支持的产品 本项目支持昇腾Atlas 300I pro、 Atlas 300V pro -- Gitee