add sample

This commit is contained in:
luoliang
2022-07-27 10:06:34 +08:00
parent c3e709b788
commit 2ca1fce800
5 changed files with 122 additions and 0 deletions

44
samples/CMakeLists.txt Normal file
View File

@@ -0,0 +1,44 @@
# cmake needs this line
cmake_minimum_required(VERSION 3.1)
# Define project name
project(opencv_example_project)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
#find_package(OpenCV REQUIRED)
set(acl_lib "/usr/local/Ascend/ascend-toolkit/latest/acllib/lib64/stub/")
set(acl_lib "/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64/stub/")
link_directories(${acl_lib})
set(acl_inc "/usr/local/Ascend/ascend-toolkit/latest/acllib/include/")
set(acl_inc "/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/include/")
include_directories(${acl_inc})
set(cv_inc "/home/perfxlab4/include/opencv4")
include_directories(${cv_inc})
set(cv_lib "/home/perfxlab4/lib")
link_directories(${cv_lib})
set(cv_libs "opencv_core" "opencv_acl" "opencv_imgproc" "opencv_highgui" "opencv_imgcodecs")
set(ACL_LIBRARIES "ascendcl" "stdc++" "acl_op_compiler")
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)
# Link your application with OpenCV libraries
target_link_libraries(opencv_example PRIVATE ${OpenCV_LIBS} ${ACL_LIBRARIES} ${cv_libs})

16
samples/README_CN.md Executable file
View File

@@ -0,0 +1,16 @@
# Opencv ACL模块简单使用示例<a name="ZH-CN_TOPIC_0302083215"></a>
## 功能描述<a name="section1421916179418"></a>
主要演示了aclMat类的简单使用,用acl模块中的merge和split算子对图片进行操作
## 步骤说明
1. 在acl模块安装完成后修改CMakeLists.txt文件中acl_inc,acl_lib,cv_inc,cv_lib的路径
2. 在samples目录下创建build目录: mkdir build
3. 进入build目录: cd build
4. 运行cmake: cmake ..
5: 编译: make
6: 运行可执行文件opencv_example

1
samples/acl.json Normal file
View File

@@ -0,0 +1 @@
{}

BIN
samples/cat1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

61
samples/example.cpp Normal file
View File

@@ -0,0 +1,61 @@
#include "opencv2/core.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/acl/acl.hpp"
#include "acl/acl.h"
#include <iostream>
using namespace cv;
using namespace cv::acl;
using namespace std;
int main()
{
// 初始化
aclCxt *acl_context_0 = set_device("../acl.json", 1, 2);
Mat src = imread("../cat1.jpg");
if (src.empty()) {
cerr << "could not image !" << endl;
return -1;
}
// 上传数据到aclMat对象中
aclMat acl_src(src, acl_context_0);
aclMat acl_dest1;
aclMat acl_dest2;
aclMat acl_dest3;
vector<aclMat> mv;
mv.emplace_back(acl_dest1);
mv.emplace_back(acl_dest2);
mv.emplace_back(acl_dest3);
imshow("src", src);
split(acl_src, mv);
//下载aclMat数据到Mat类中
Mat dest1 = mv.data()[0].operator cv::Mat();
Mat dest2 = mv.data()[1].operator cv::Mat();
Mat dest3 = mv.data()[2].operator cv::Mat();
imshow("dest1", dest1);
imshow("dest2", dest2);
imshow("dest3", dest3);
aclMat acl_imgdest;
merge(mv, acl_imgdest);
Mat imgdest = acl_imgdest.operator cv::Mat();
imshow("imgdest", imgdest);
// 去初始化
release_device(acl_context_0);
waitKey(0);
return 0;
}