rv1126所使用的rknn sdk里默认是不带opencv库的,官方所用的例程里也没有使用opencv,但是这样在进行图像处理的时候有点麻烦了,这里有两种办法:
一是先用python将所需要的图片处理好后在转化为bin格式文件,在使用c++或c进行读取,可以参考->;
二是为其添加opencv库,可以直接在程序中调用opencv接口;下面介绍具体步骤
1:首先利用rv1126的交叉编译工具,将opencv源码生成可在rv1126上运行的库,参考
2:将编译生成的install下的所有文件拷贝支/3rdparty/opencv/下
3:编辑CMakeLists.txt
bash
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)
bash
#!/bin/bash
set -e
# for rv1109/rv1126 armhf
GCC_COMPILER=/opt/atk-dlrv1126-toolchain/bin/arm-linux-gnueabihf
ROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )
# build rockx
BUILD_DIR=${ROOT_PWD}/build
if [[ ! -d "${BUILD_DIR}" ]]; then
mkdir -p ${BUILD_DIR}
fi
cd ${BUILD_DIR}
cmake .. \
-DCMAKE_C_COMPILER=${GCC_COMPILER}-gcc \
-DCMAKE_CXX_COMPILER=${GCC_COMPILER}-g++
make -j4
make install
cd -
main.cc里加入opencv库
此时有可能报错,使用ldd xxxx查看
这是因为板端没有找到相应的库,此时把缺失的库拷贝到提示缺失的路径下,再次运行即可,若依然有报错则继续添加到相应路径下即可。