默认没有带opencv库,但是实际项目中需要用到opencv库,因此添加一下此库;
1:编译opencv源码,这里具体可以参考
海思Hi3516移植opencv以及错误调试_海思hi3516摄像头开发-CSDN博客
2:在工程的根目录下新建一个3rdparty文件用于存放第三方的库,将编译安装好的库拷贝至3rdparty下并命名为opencv
3:修改src下的CMakeLists.txt,重点可以看一下#opencv的部分,总的说就是查找opencv的库,并链接到库即可
# CMake lowest version requirement
cmake_minimum_required(VERSION 3.5.1)# project information
project(ACL_CLASSIFICATION_RESNET50)# Compile options
add_compile_options(-std=c++11-fPIC-fstack-protector-all-D_FORTIFY_SOURCE=2 -O2)# Specify target generation path
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../../../out")
set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -O0 -g -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O2 -Wall -s")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie")
set(CMAKE_SKIP_RPATH TRUE)# Header path
include_directories(
$ENV{DDK_PATH}/acllib/include/../inc/../3rdparty/opencv/opencv-3.4.3/lib
)# add host lib path
if (target MATCHES "Simulator_Function" OR target MATCHES "Simulator_Instruction" OR target MATCHES "Simulator_Performance")set(ENV{NPU_HOST_LIB} $ENV{DDK_PATH}/toolkit/tools/sim/lib)
else()set(ENV{NPU_HOST_LIB} $ENV{DDK_PATH}/acllib/lib64/stub) #this case
endif()# opencv
set(OpenCV_DIR "../3rdparty/opencv/opencv-3.4.3/share/OpenCV")
# 查找opencv的path
find_package(OpenCV REQUIRED)
# 打印opencv的相关信息
message(STATUS "OpenCV library status:")
message(STATUS "version: ${OpenCV_VERSION}")
message(STATUS "libraries: ${OpenCV_LIBS}")
message(STATUS "include path: ${OpenCV_INCLUDE_DIRS}")
#
set(LIB_PATH $ENV{NPU_HOST_LIB} )
MESSAGE(NPU_HOST_LIB=$ENV{NPU_HOST_LIB})
link_directories(${LIB_PATH})
set(OPENCV_LIB ${OpenCV_DIR})
link_directories(${OPENCV_LIB})
message(${OPENCV_LIB})
FILE(GLOB SAMPLE_SRC_FILE *.cpp)add_executable(main ${SAMPLE_SRC_FILE})if (target MATCHES "Simulator_Function")target_link_libraries(main funcsim )
elseif (target MATCHES "Simulator_Instruction" OR target MATCHES "Simulator_Performance")target_link_libraries(main instsim )
else()target_link_libraries(main svp_acl ss_mpi_sysmem ss_mpi_km pthread securec dl protobuf-c stdc++ ${OpenCV_LIBS})
endif()install(TARGETS main DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
4:cmake测试
5:代码测试,头文件包含opencv的头文件
至此opencv库移植成功