20220830-hi3516交叉编译opencv4.6.0
1. 下载opencv4.6.0并解压
unzip opencv-4.6.0.zip
cd opencv-4.6.0
2. 安装基础工具
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
3. 在opencv-4.6.0/目录下编写编译脚本
vim build.sh
#!/bin/bash set -e # Exit immediately if a command exits with a non-zero status. BuildDir=/home/ydf/work/src/001/opencv/opencv-4.6.0/build ToolChain=/opt/hisi-linux/x86-arm/arm-himix200-linux if [ ! -d "$BuildDir" ]; then # Take action if $BuildDir doesnât exists. echo "create ${BuildDir}..." mkdir -p ${BuildDir} fi cd ${BuildDir} echo "building OpenCV4" cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D BUILD_SHARED_LIBS=OFF \ -D CMAKE_FIND_ROOT_PATH=${ToolChain}/ \ -D CMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake \ -D CMAKE_C_COMPILER=${ToolChain}/bin/arm-himix200-linux-gcc \ -D CMAKE_CXX_COMPILER=${ToolChain}/bin/arm-himix200-linux-g++ \ -D CMAKE_C_FLAGS="-mfloat-abi=softfp -mfpu=neon" \ -D CMAKE_CXX_FLAGS="-mfloat-abi=softfp -mfpu=neon" \ -D CMAKE_INSTALL_PREFIX=${BuildDir}/install \ -D WITH_TBB=ON \ -D WITH_EIGEN=ON \ -D BUILD_ZLIB=ON \ -D BUILD_TIFF=ON \ -D BUILD_JASPER=ON \ -D BUILD_JPEG=ON \ -D BUILD_PNG=ON \ -D ENABLE_NEON=ON \ -D ENABLE_VFPV3=ON \ -D WITH_LIBV4L=ON \ -D BUILD_opencv_python=OFF \ -D ENABLE_PRECOMPILED_HEADERS=OFF \ -D BUILD_EXAMPLES=OFF \ -D BUILD_TESTS=OFF \ -D BUILD_PERF_TESTS=OFF \ -D BUILD_WITH_DEBUG_INFO=OFF \ -D BUILD_DOCS=OFF \ -D WITH_OPENCL=OFF \ -D WITH_1394=OFF \ .. make -j$(nproc)
4. 编译opencv
sh build.sh
5. 编写测试程序
vim test.cpp
#include <stdio.h> #include <opencv2/opencv.hpp> using namespace cv; int main(int argc, char** argv) { if ( argc != 2 ) { printf("usage: test.out <image_Path>\n"); return -1; } Mat image = imread(argv[1]); if (image.empty()) { printf("Reading image fails.\n"); return -1; } Mat gray; cvtColor(image, gray, COLOR_BGR2GRAY); imwrite("gray.jpg", gray); printf("Writing gray image success.\n"); return 0; }
6. 编写cmake文件
vim CMakeLists.txt
# 设置目标工程名称 project(TEST) # 设置生成文件名称 set(TARGET test) # 设置编译最小版本 cmake_minimum_required(VERSION 3.12) # 设置目标平台系统 set(CMAKE_SYSTEM_NAME Linux) # 设置交叉编译路径 set(CMAKE_FIND_ROOT_PATH /opt/hisi-linux/x86-arm/arm-himix200-linux/bin) # 设置交叉编译工具 set(CMAKE_C_COMPILER arm-himix200-linux-gcc) set(CMAKE_CXX_COMPILER arm-himix200-linux-g++) set(CMAKE_C_EXTENSIONS "") set(CMAKE_CXX_EXTENSIONS "") # 设置库的目录路径 set(OpenCV_DIR /home/ydf/work/src/001/opencv/opencv-4.6.0/build) find_package(OpenCV REQUIRED) message(STATUS "OpenCV library status:") message(STATUS " version: ${OpenCV_VERSION}") message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") # 添加编译文件目录 aux_source_directory(${PROJECT_SOURCE_DIR} USRSRC) # 添加生成执行文件 add_executable(${TARGET} ${USRSRC}) # 执行生成文件链接 TARGET_LINK_LIBRARIES(${TARGET} ${OpenCV_LIBS}) 7.编译测试文件 rm -rf build && mkdir build && cd build && cmake .. && make
7. 编译测试文件
rm -rf build && mkdir build && cd build && cmake .. && make
8. 拷贝生成文件到开发版,如果出现symbol _ZNSt15__exception_ptr13exception_ptrC1Ev, version CXXABI_1.3.11 not defined in file libstdc++.so.6 with link time reference问题,请使用/opt/hisi-linux/x86-arm/arm-himix200-linux/arm-linux-gnueabi/lib/libstdc++.so.6.0.23复制到板子上/lib进行替换,可能开发板自带的libstdc++.so.6.0.23存在问题。
参考:
opencv编译
https://www.cnblogs.com/zhangxingcomeon/p/15039284.html
https://blog.csdn.net/a1874738854/article/details/88841844
https://blog.csdn.net/weixin_39553776/article/details/110108136
https://zhuanlan.zhihu.com/p/84839635
https://www.abaozhan.com/news_txtlist_i22535v.html
https://wenku.baidu.com/view/aa51fe5601768e9951e79b89680203d8ce2f6ad0.html
https://blog.csdn.net/weixin_42405819/article/details/117996788
https://blog.csdn.net/m0_38061927/article/details/108189587
https://blog.csdn.net/avideointerfaces/article/details/89477828
https://blog.csdn.net/juluwangriyue/article/details/114339457
https://blog.csdn.net/aslily1234/article/details/105348946/
https://blog.csdn.net/weixin_34167819/article/details/88977429
https://www.thinbug.com/q/15170136
https://blog.csdn.net/weixin_30773135/article/details/95141139
https://cloud.tencent.com/developer/article/1940015
cmake编译
https://blog.csdn.net/niewei120/article/details/124386802
http://t.zoukankan.com/geoffreyone-p-10837606.html
https://blog.csdn.net/qq_29935433/article/details/123554805
https://zhuanlan.zhihu.com/p/106473031
https://www.cnblogs.com/ZQQH/p/8710800.html
https://blog.csdn.net/bbszhenshuai/article/details/106200228