本文主要是介绍rv1126-rknpu-v1.7.3添加opencv库,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
rv1126所使用的rknn sdk里默认是不带opencv库的,官方所用的例程里也没有使用opencv,但是这样在进行图像处理的时候有点麻烦了,这里有两种办法:
一是先用python将所需要的图片处理好后在转化为bin格式文件,在使用c++或c进行读取,可以参考->;
二是为其添加opencv库,可以直接在程序中调用opencv接口;下面介绍具体步骤
1:首先利用rv1126的交叉编译工具,将opencv源码生成可在rv1126上运行的库,参考
-> Rv1126移植opencv-CSDN博客
2:将编译生成的install下的所有文件拷贝支/3rdparty/opencv/下
3:编辑CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
set(PROJECT_NAME rknn_template)
project(${PROJECT_NAME})set(CMAKE_SYSTEM_NAME Linux)set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")if(CMAKE_SIZEOF_VOID_P EQUAL 8)message(STATUS "64bit")set(LIB_ARCH lib64)
else()message(STATUS "32bit")set(LIB_ARCH lib)
endif()# rknn api
set(RKNN_API_PATH ${CMAKE_SOURCE_DIR}/../../librknn_api)
include_directories(${RKNN_API_PATH}/include)
set(RKNN_API_LIB ${RKNN_API_PATH}/${LIB_ARCH}/librknn_api.so)# opencv
if(LIB_ARCH STREQUAL "lib")set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/../3rdparty/opencv/opencv-3.4.3/share/OpenCV)message(STATUS "--------armhf")
else()set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/../3rdparty/opencv/opencv-linux-aarch64/share/OpenCV)message(STATUS "aarch64")
endif()
find_package(OpenCV REQUIRED)#stb
include_directories(${CMAKE_SOURCE_DIR}/../3rdparty/)set(CMAKE_INSTALL_RPATH "lib")add_executable(${PROJECT_NAME}src/main.cc
)target_link_libraries(${PROJECT_NAME}${RKNN_API_LIB}${OpenCV_LIBS}dl)# install target and libraries
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} DESTINATION ./)
install(DIRECTORY model DESTINATION ./)
install(PROGRAMS ${RKNN_API_LIB} DESTINATION lib)
build.sh
#!/bin/bashset -e# for rv1109/rv1126 armhfGCC_COMPILER=/opt/atk-dlrv1126-toolchain/bin/arm-linux-gnueabihfROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )# build rockxBUILD_DIR=${ROOT_PWD}/buildif [[ ! -d "${BUILD_DIR}" ]]; thenmkdir -p ${BUILD_DIR}ficd ${BUILD_DIR}cmake .. \-DCMAKE_C_COMPILER=${GCC_COMPILER}-gcc \-DCMAKE_CXX_COMPILER=${GCC_COMPILER}-g++make -j4make installcd -
main.cc里加入opencv库
此时有可能报错,使用ldd xxxx查看
这是因为板端没有找到相应的库,此时把缺失的库拷贝到提示缺失的路径下,再次运行即可,若依然有报错则继续添加到相应路径下即可。
这篇关于rv1126-rknpu-v1.7.3添加opencv库的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!