diff --git a/tutorials/protocolSample/CMakeLists.txt b/tutorials/protocolSample/CMakeLists.txt index 3c7b9dfddb5b6ddc6c15171c53292cef177c932e..5aa234fb15c56ab8d23684fe0dcca54a57e94fab 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 8b408d557c65073a27374026382844c1048eb169..89c840aac3790e3e7879f6dc7fc3704f9c59a4af 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 + +## 1 介绍 +### 1.1 简介 +本样例构建一个metadata的protocol数据并送入stream,随后输出至log + +### 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 三方依赖 + +| 软件名称 | 版本 | +|-------|------| +| cmake | 3.16 | + +### 1.5 代码目录结构说明 + +``` +. +| +|-------- CMakeLists.txt +|-------- main.cpp +|-------- run.sh +|-------- pipeSample.pipeline +|-------- README.md +|-------- test.jpg // 需用户准备 + +``` + +## 2 设置环境变量 + +```bash +#设置CANN环境变量,ascend-toolkit-path为cann安装路径 +. ${ascend-toolkit-path}/set_env.sh + +#设置MindX SDK 环境变量,SDK-path为mxVision SDK 安装路径 +. ${SDK-path}/set_env.sh +``` + + +## 3 编译与运行 + +**步骤1**:修改日志配置 + +修改${SDK-path}/config/logging.conf中的第21行console_level为0 + +```bash +21 console_level=0 +``` + +**步骤2**:图片准备 +``` +准备一张测试图片,项目文件中并重命名为 `test.jpg`,请勿使用大分辨率图片 +``` + +**步骤3**:编译与运行 + +执行以下命令: +```bash +bash run.sh +``` + +**步骤4**:查看结果 +``` +如构建的proto数据正确则可在命令行输出中看到warn登记的日志,以"Output:"开头 +``` diff --git a/tutorials/protocolSample/main.cpp b/tutorials/protocolSample/main.cpp index a4cc81e667c15343e950d126ea44f191eee5b34e..a05cc173693e47dbe9197316b29994f45c9073cf 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) diff --git a/tutorials/protocolSample/main.py b/tutorials/protocolSample/main.py deleted file mode 100644 index ef945da410731c9e9d7a4b2ba8084b71ee3f0b45..0000000000000000000000000000000000000000 --- 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 diff --git a/tutorials/protocolSample/run.sh b/tutorials/protocolSample/run.sh index 64381a3c1ad6288e3bba37f204b064ec259e797c..c245b83c049259cd34a8a1aff15482202f093d69 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