目录
1.编译opencv
编译opencv是为了,在编译Tengine时指定OpenCVConfig.cmake,以便寻找特定的opencv动态库
01.从github拉取opencv源代码
git clone -b 4.5.5 https://github.com/opencv/opencv.git
02.在虚拟机安装cmake
sudo apt-get update
sudo apt-get install cmake
04.解压opencv源码,并进入文件
05.新建文件ax620a.toolchain.cmake配置交叉编译工具链
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
#如果未设置交叉编译器到环境变量,要加入绝对路径,我这里已经加入到环境变量中了
set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon")
# cache flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags")
06.创建build文件夹并配置cmake
mkdir build && cd build
#sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=./build -D OPENCV_ENABLE_NONFREE=True -DCMAKE_TOOLCHAIN_FILE=../ax620a.toolchain.cmake -D WITH_FFMPEG=ON ../
# -D CMAKE_INSTALL_PREFIX指定编译后的安装路径
# -D CMAKE_BUILD_TYPE=Release优化编译,删除没必要的调试信息等
# -D OPENCV_ENABLE_NONFREE开启了非自由模块的支持
# -DCMAKE_TOOLCHAIN_FILE指定了交叉编译工具链文件的位置
# -D WITH_FFMPEG开启了FFmpeg的支持
cmake -DCMAKE_TOOLCHAIN_FILE=../ax620a.toolchain.cmake -DCMAKE_INSTALL_PREFIX=$(pwd)/_install -DOPENCV_FORCE_3RDPARTY_BUILD=ON ../
07.编译并安装
#sudo make && make install
make -j$(nproc --ignore 1)
查看在build目录下是否存在OpenCVConfig.cmake文件
2.拷贝SDK源码到虚拟机
SDK源码中带有Tengine需要的动态库,所以必须把SDK源码拷贝到虚拟机
3. 拉取TIM-VX代码
git clone https://github.com/VeriSilicon/TIM-VX.git
cd TIM-VX
git checkout 68b5acb
4.拉取Tengine源码并配置
01拉取代码
git clone https://github.com/OAID/Tengine.git tengine-lite
cd tengine-lite
02.将 TIM-VX 的 include 和 src 目录复制到 Tengine-Lite 的 source/device/tim-vx 目录下,以便于 CMake 查找文件完成编译
cd tengine-lite
cp -rf ../TIM-VX/include ./source/device/tim-vx/
cp -rf ../TIM-VX/src ./source/device/tim-vx/
03. 准备 x86_64 3rdparty 依赖
准备的
include
目录和 VIM3/VIM3L 本地编译 NPU 最新版本相同,下载一份 perbuild SDK,将其中的include
文件夹复制到3rdparty/tim-vx
目录。 依赖的 lib 目录下的文件需要从前面 SDK 中解压出来的external/rknpu/drivers/linux-armhf-puma/usr/lib
目录提取。将该目录下的文件全部(实际上不需要全部复制,FAQ 有文件列表)复制到3rdparty/tim-vx/lib/aarch32
文件夹下即可
wget -c https://github.com/VeriSilicon/TIMVX/releases/download/v1.1.28/aarch64_S905D3_D312513_A294074_R311680_T312233_O312045.tgz
tar zxvf aarch64_S905D3_D312513_A294074_R311680_T312233_O312045.tgz
mv aarch64_S905D3_D312513_A294074_R311680_T312233_O312045 prebuild-sdk-s905d3
cd tengine-lite
mkdir -p ./3rdparty/tim-vx/include
mkdir -p ./3rdparty/tim-vx/lib/aarch32
cp -rf ../prebuild-sdk-s905d3/include/* ./3rdparty/tim-vx/include/
cp -rf <rk_sdk_npu_lib>/* ./3rdparty/tim-vx/lib/aarch32/
#<rk_sdk_npu_lib>是external/rknpu/drivers/linux-armhf-puma/usr/lib
04.修改cmake文件
cd toolchains
vi arm-linux-gnueabihf.toolchain.cmake
修改为绝对路径
05.设置 OpenCV_DIR 环境变量
设置 OpenCV_DIR 环境变量是为了指定OpenCVConfig.cmake文件的路径
exoprt OpenCV_DIR=/home/alientek/opencv-4.x/build
06.编译
cd tengine-lite-root-dir
mkdir build && cd build
export PATH=<cross_tool_chain>/bin:$PATH
ln -s ../3rdparty/tim-vx/lib/aarch32/libOpenVX.so.1.2 ../3rdparty/tim-vx/lib/aarch32/libOpenVX.so
cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/arm-linux-gnueabihf.toolchain.cmake -DTENGINE_ENABLE_TIM_VX=ON -DTENGINE_OPENMP=OFF ..
make -j`nproc` && make install
提取 install 目录下的文件到板子上测试即可。需要注意的是,不设置OpenCV_DIR环境变量部分 OpenCV 依赖的 example 在这个过程中不会编译,需要先准备好交叉编译的OpenCV,并正确设置 OpenCV_DIR 到环境变量中方可打开这部分 example 的编译。(咱们已经设置过了)可以看到,我们把所有组件都编译出来了
文章出处登录后可见!