交叉编译 opencv-4.10

编译说明

opencv 下包含很多模块,各个模块的作用可以参考Opencv---模块概览. 嵌入式考虑有限存储等因素会对模块进行裁剪,我这里主要保留图像拼接(stitching)图片编解码(imgcodecs)与特征点匹配(feature2d)及其依赖模块,下面是编译过程。

编译过程

  1. github下载opencv库.
  2. 配置交叉编译工具,我这里是 hi3159dv500 的交叉编译工具链,大家根据自己的进行cmake配置。
bash 复制代码
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)

# 环境库
set(CMAKE_FIND_ROOT_PATH /home/hisi/workspace/hocker/pack/3ds/buildroot/output/hisi_3519/host/aarch64-buildroot-linux-gnu/sysroot)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_SYSROOT ${CMAKE_FIND_ROOT_PATH})

# 安装路径配置,这个他们需要绝对路径
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/lib-aarch64" CACHE PATH "Installation Directory")  


set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH FALSE)
# set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH FALSE)
set(CMAKE_FIND_USE_CMAKE_PATH FALS)


set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CMAKE_FIND_ROOT_PATH})
set(ENV{PKG_CONFIG_LIBDIR} ${CMAKE_FIND_ROOT_PATH}/usr/lib/pkgconfig)
set(ENV{PKG_CONFIG_PATH} "")

set(TARGET_ARCH arm64)
bash 复制代码
cd build
# rm ../build/* -rf 
# 这里的命令一定要加 TARGET_ARCH=arm64, 不然 编译 png 的时候 不支持 neno, 导致 imgcodecs 编译失败
cmake .. \
  -DBUILD_LIST=core,imgproc,features2d,stitching,calib3d,flann,imgcodecs \
  -DBUILD_opencv_dnn=OFF \
  -DBUILD_opencv_highgui=OFF \
  -DBUILD_opencv_videoio=OFF \
  -DBUILD_opencv_calib3d=ON \
  -DWITH_PYTHON=OFF \
  -DWITH_opencv_stitching=ON \
  -DBUILD_opencv_world=OFF \
  -DBUILD_TESTS=OFF \
  -DBUILD_EXAMPLES=OFF \
  -DWITH_GTK=OFF \
  -DWITH_JPEG=ON \
  -DWITH_PNG=ON \
  -DTARGET_ARCH=arm64 \
  -DCMAKE_TOOLCHAIN_FILE=../toolchain.cmake
make -j8

编译结果

  1. 编译过程输出(这里主要看库编译过程,仅供参考)
bash 复制代码
-- Build files have been written to: /home/hisi/workspace/hocker/3ds/opencv-4.10.0/build
Consolidate compiler generated dependencies of target libopenjp2
Consolidate compiler generated dependencies of target jpeg16-static
Consolidate compiler generated dependencies of target zlib
[  0%] Built target opencv_dnn_plugins
Consolidate compiler generated dependencies of target jpeg12-static
[  0%] Built target opencv_highgui_plugins
[  0%] Built target opencv_videoio_plugins
Consolidate compiler generated dependencies of target libwebp
[  3%] Built target zlib
[  7%] Built target libopenjp2
[ 10%] Built target jpeg16-static
Scanning dependencies of target libpng
Consolidate compiler generated dependencies of target libpng
Consolidate compiler generated dependencies of target libtiff
[ 15%] Built target jpeg12-static
[ 18%] Built target libpng
Consolidate compiler generated dependencies of target libjpeg-turbo
[ 26%] Built target libtiff
Consolidate compiler generated dependencies of target opencv_core
[ 45%] Built target libwebp
[ 54%] Built target libjpeg-turbo
[ 69%] Built target opencv_core
Consolidate compiler generated dependencies of target opencv_version
Consolidate compiler generated dependencies of target opencv_flann
[ 69%] Built target opencv_version
[ 70%] Built target opencv_flann
Consolidate compiler generated dependencies of target opencv_imgproc
[ 82%] Built target opencv_imgproc
Consolidate compiler generated dependencies of target opencv_imgcodecs
Consolidate compiler generated dependencies of target opencv_features2d
[ 90%] Built target opencv_imgcodecs
[ 90%] Built target opencv_features2d
Consolidate compiler generated dependencies of target opencv_calib3d
[ 97%] Built target opencv_calib3d
Consolidate compiler generated dependencies of target opencv_stitching
[100%] Built target opencv_stitching
  1. 编译出来的库文件如下
bash 复制代码
$ ls ../build/lib/ 
libopencv_calib3d.so         libopencv_features2d.so.410     libopencv_imgcodecs.so.4.10.0
libopencv_calib3d.so.410     libopencv_features2d.so.4.10.0  libopencv_imgproc.so
libopencv_calib3d.so.4.10.0  libopencv_flann.so              libopencv_imgproc.so.410
libopencv_core.so            libopencv_flann.so.410          libopencv_imgproc.so.4.10.0
libopencv_core.so.410        libopencv_flann.so.4.10.0       libopencv_stitching.so
libopencv_core.so.4.10.0     libopencv_imgcodecs.so          libopencv_stitching.so.410
libopencv_features2d.so      libopencv_imgcodecs.so.410      libopencv_stitching.so.4.10.0
  1. 编译出来的库大小
bash 复制代码
$ du --max-depth=0 -h ../build/lib/
16M     ../build/lib/
bash 复制代码
  1. 编译出来的库结果
bash 复制代码
$ file  ../build/lib/libopencv_*.4.10.0
../build/lib/libopencv_calib3d.so.4.10.0:    ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped
../build/lib/libopencv_core.so.4.10.0:       ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped
../build/lib/libopencv_features2d.so.4.10.0: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped
../build/lib/libopencv_flann.so.4.10.0:      ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped
../build/lib/libopencv_imgcodecs.so.4.10.0:  ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped
../build/lib/libopencv_imgproc.so.4.10.0:    ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped
../build/lib/libopencv_stitching.so.4.10.0:  ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped
相关推荐
onceco27 分钟前
领域LLM九讲——第5讲 为什么选择OpenManus而不是QwenAgent(附LLM免费api邀请码)
人工智能·python·深度学习·语言模型·自然语言处理·自动化
whoarethenext3 小时前
使用 C++/OpenCV 和 MFCC 构建双重认证智能门禁系统
开发语言·c++·opencv·mfcc
jndingxin3 小时前
OpenCV CUDA模块设备层-----高效地计算两个 uint 类型值的带权重平均值
人工智能·opencv·计算机视觉
Sweet锦3 小时前
零基础保姆级本地化部署文心大模型4.5开源系列
人工智能·语言模型·文心一言
hie988944 小时前
MATLAB锂离子电池伪二维(P2D)模型实现
人工智能·算法·matlab
晨同学03274 小时前
opencv的颜色通道问题 & rgb & bgr
人工智能·opencv·计算机视觉
蓝婷儿5 小时前
Python 机器学习核心入门与实战进阶 Day 3 - 决策树 & 随机森林模型实战
人工智能·python·机器学习
大千AI助手5 小时前
PageRank:互联网的马尔可夫链平衡态
人工智能·机器学习·贝叶斯·mc·pagerank·条件概率·马尔科夫链
小和尚同志5 小时前
Cline | Cline + Grok3 免费 AI 编程新体验
人工智能·aigc
我就是全世界5 小时前
TensorRT-LLM:大模型推理加速的核心技术与实践优势
人工智能·机器学习·性能优化·大模型·tensorrt-llm