OpenCV介绍
OpenCV(Open Source Computer Vision Library) 是全球规模最大的计算机视觉库,自 2000 年 6 月起正式推出并持续迭代。作为开源项目,它由非营利性组织 开源视觉基金会(Open Source Vision Foundation) 维护运营,凭借免费开放的特性与强大的技术能力,成为计算机视觉领域的行业标杆。
该库涵盖超过 2500 种算法,全面覆盖图像识别、特征检测、目标跟踪、视频分析、机器学习、三维重建等核心场景,广泛应用于机器人、自动驾驶、医疗影像、安防监控、智能终端等众多领域。其跨平台特性支持 Windows、Linux、macOS、Android、iOS 等主流操作系统,且提供 C++、Python、Java 等多语言接口,满足不同开发者的技术需求。
官网地址:https://opencv.org/
![图片[1]-从零开始:RK3588 平台上 OpenCV 4.12.0 编译全流程详解-天煜博客](https://blog.itianyu.cn/wp-content/uploads/2025/10/20251026162114690-image.png)
下载最新代码
![图片[2]-从零开始:RK3588 平台上 OpenCV 4.12.0 编译全流程详解-天煜博客](https://blog.itianyu.cn/wp-content/uploads/2025/10/20251026144608476-image-1024x410.png)
然后会跳转到下方的页面,能够看到各个发布版本和发布时间等信息:
![图片[3]-从零开始:RK3588 平台上 OpenCV 4.12.0 编译全流程详解-天煜博客](https://blog.itianyu.cn/wp-content/uploads/2025/10/20251026145255799-image-732x1024.png)
在 OpenCV 的版本发布列表中,带红色星号的版本(如 OpenCV 4.12.0、4.11.0、4.10.0)通常表示该版本是当前推荐的稳定版本或最新发布的主要版本,用于突出显示,方便开发者快速识别优先选择的版本。
每个版本下都提供了多种资源入口,包括:
- Sources:源码获取入口;
- GitHub:指向该版本在 GitHub 的代码仓库;
- Get Started:新手入门引导;
- Docs:官方文档;
- Release Notes:版本发布说明(包含新特性、改进、修复等信息);
- Windows:Windows 系统的安装包;
- Android:Android 平台的资源;
- iOS pack:iOS 平台的资源包;
- Java Docs:Java 语言相关的文档。
这些资源入口方便开发者根据自己的需求(如开发平台、使用语言等)获取对应的 OpenCV 版本和支持文档,体现了 OpenCV 在开源生态中对多平台、多语言的广泛支持。
这里我选择最新稳定版本4.12.0的代码进行下载,直接点击 OpenCV 4.12.0模块下方的Sources即可下载,如果下载过慢可以试试科学上网。
下载好的压缩包信息:
![图片[4]-从零开始:RK3588 平台上 OpenCV 4.12.0 编译全流程详解-天煜博客](https://blog.itianyu.cn/wp-content/uploads/2025/10/20251026145722648-image.png)
然后使用SSH工具将opencv-4.12.0.zip上传到RK3588的开发板上合适的目录:
![图片[5]-从零开始:RK3588 平台上 OpenCV 4.12.0 编译全流程详解-天煜博客](https://blog.itianyu.cn/wp-content/uploads/2025/10/20251026145952555-image-1024x367.png)
也可以直接使用git命令下载代码:
git clone --branch 4.12.0 https://github.com/opencv/opencv.git
cd opencv-4.12.0
mkdir build && cd build
编译代码
我的编译根目录为: /home/topeet/work/opencv_compile
解压压缩包
# 进入编译根目录
cd /home/topeet/work/opencv_compile
# 解压压缩包
unzip opencv-4.12.0.zip
# 等待解压完成 会出现opencv-4.12.0目录 该目录下就是完整的代码了
![图片[6]-从零开始:RK3588 平台上 OpenCV 4.12.0 编译全流程详解-天煜博客](https://blog.itianyu.cn/wp-content/uploads/2025/10/20251026150931570-image.png)
在 OpenCV 4.12.0 的源码目录中,各文件夹和文件的作用如下:
- 3rdparty存放第三方依赖库的源码或预编译文件,例如 zlib(压缩库)、libjpeg(图像编解码)、tiff(图像格式处理)等。OpenCV 依赖这些库实现部分底层功能,避免重复开发。
- apps包含 OpenCV 官方提供的一些实用工具程序,例如
opencv_annotation(标注工具)、opencv_interactive-calibration(相机标定工具)等,用于辅助开发或测试。 - cmake存放 CMake 构建系统所需的配置文件(如
.cmake脚本),用于定义编译规则、检测系统环境、配置依赖项等,是 OpenCV 跨平台编译的核心配置目录。 - data包含测试、示例程序所需的素材文件,例如训练好的 Haar 级联分类器模型(用于人脸检测等)、测试图像、视频样本等。
- doc存放 OpenCV 的文档源码(如 Markdown 或 HTML 原始文件),部分版本中可能包含离线文档或生成文档的脚本。
- hal(Hardware Acceleration Layer,硬件加速层)用于适配不同硬件平台的加速接口,例如针对 CPU 指令集(如 NEON、SSE)或特定硬件(如 GPU)的优化实现,提升 OpenCV 运算效率。
- include存放 OpenCV 的头文件(
.h/.hpp),包含所有公开的 API 声明,是开发者编写代码时需要引用的核心文件目录(例如opencv2/core.hpp等)。 - modules最核心的目录,包含 OpenCV 各功能模块的源码,例如:
core:核心数据结构与基础算法;imgproc:图像处理(滤波、边缘检测等);video:视频分析(目标跟踪等);dnn:深度学习模块;每个子模块独立实现一类功能,是 OpenCV 算法的主要载体。
- platforms针对不同操作系统或硬件平台的编译配置脚本,例如
linux、android、ios等子目录,包含对应平台的特殊编译规则或工具链配置。 - samples存放官方示例程序,涵盖 C++、Python 等语言,展示 OpenCV 各类 API 的使用方法(如图像读取、特征检测、目标识别等),适合新手学习参考。
- 关键文件
CMakeLists.txt:OpenCV 顶层编译配置文件,是使用 CMake 构建项目的入口,定义了全局编译规则和模块依赖;LICENSE/COPYRIGHT:开源协议(OpenCV 采用 BSD 协议)和版权声明;README.md:项目说明文档,包含编译指南、版本信息、核心功能简介等;CONTRIBUTING.md:贡献指南,指导开发者如何向 OpenCV 项目提交代码;SECURITY.md:安全相关说明,如漏洞报告流程等。
编译前准备
# 进入opencv-4.12.0目录后创建编译目录
mkdir build && cd build
# 安装系统依赖包,确保编译环境完整:
sudo apt update
sudo apt install build-essential cmake git pkg-config libgtk-3-dev libavcodec-dev libavformat-dev libswscale-dev
libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev gfortran openexr libatlas-base-dev python3-dev python3-numpy libtbb2 libtbb-dev libopenblas-dev liblapack-dev libprotobuf-dev protobuf-compiler libgoogle-glog-dev libgflags-dev libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
CMake配置(关键参数适配 RK3588 平台)
执行 CMake 命令配置编译参数,以下为推荐配置(可根据需求调整):
# 如果安装路径无权限可能需要加上sudo
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/home/topeet/work/opencv_compile/opencv-4.12.0-install \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_opencv_java=OFF \
-D BUILD_opencv_python3=ON \
-D WITH_OPENMP=ON \
-D WITH_GSTREAMER=ON \
-D WITH_LIBV4L=ON \
-D WITH_OPENGL=ON \
-D WITH_TBB=ON \
-D BUILD_SHARED_LIBS=ON \
-D ENABLE_NEON=ON \
-D WITH_FFMPEG=ON \
-D WITH_JPEG=ON \
-D WITH_PNG=ON \
-D WITH_TIFF=ON \
-D WITH_GTK=ON \
-D WITH_OPENCL=ON \
..
# CMake配置输出日志
topeet@topeet:~/work/opencv_compile/opencv-4.12.0/build$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
> -D CMAKE_INSTALL_PREFIX=/home/topeet/work/opencv_compile/opencv-4.12.0-install \
> -D OPENCV_GENERATE_PKGCONFIG=ON \
> -D BUILD_opencv_java=OFF \
> -D BUILD_opencv_python3=ON \
> -D WITH_OPENMP=ON \
> -D WITH_GSTREAMER=ON \
> -D WITH_LIBV4L=ON \
> -D WITH_OPENGL=ON \
> -D WITH_TBB=ON \
> -D BUILD_SHARED_LIBS=ON \
> -D ENABLE_NEON=ON \
> -D WITH_FFMPEG=ON \
> -D WITH_JPEG=ON \
> -D WITH_PNG=ON \
> -D WITH_TIFF=ON \
> -D WITH_GTK=ON \
> -D WITH_OPENCL=ON \
> ..
-- The CXX compiler identification is GNU 11.4.0
-- The C compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default.
-- Detected processor: aarch64
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3.2")
-- Found PythonLibs: /usr/lib/aarch64-linux-gnu/libpython3.10.so (found suitable exact version "3.10.12")
-- Looking for ccache - not found
-- Performing Test HAVE_CXX_FSIGNED_CHAR
-- Performing Test HAVE_CXX_FSIGNED_CHAR - Success
-- Performing Test HAVE_C_FSIGNED_CHAR
-- Performing Test HAVE_C_FSIGNED_CHAR - Success
-- Performing Test HAVE_CXX_W
-- Performing Test HAVE_CXX_W - Success
-- Performing Test HAVE_C_W
-- Performing Test HAVE_C_W - Success
-- Performing Test HAVE_CXX_WALL
-- Performing Test HAVE_CXX_WALL - Success
-- Performing Test HAVE_C_WALL
-- Performing Test HAVE_C_WALL - Success
-- Performing Test HAVE_CXX_WRETURN_TYPE
-- Performing Test HAVE_CXX_WRETURN_TYPE - Success
-- Performing Test HAVE_C_WRETURN_TYPE
-- Performing Test HAVE_C_WRETURN_TYPE - Success
-- Performing Test HAVE_CXX_WNON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_WNON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_C_WNON_VIRTUAL_DTOR
-- Performing Test HAVE_C_WNON_VIRTUAL_DTOR - Failed
-- Performing Test HAVE_CXX_WADDRESS
-- Performing Test HAVE_CXX_WADDRESS - Success
-- Performing Test HAVE_C_WADDRESS
-- Performing Test HAVE_C_WADDRESS - Success
-- Performing Test HAVE_CXX_WSEQUENCE_POINT
-- Performing Test HAVE_CXX_WSEQUENCE_POINT - Success
-- Performing Test HAVE_C_WSEQUENCE_POINT
-- Performing Test HAVE_C_WSEQUENCE_POINT - Success
-- Performing Test HAVE_CXX_WFORMAT
-- Performing Test HAVE_CXX_WFORMAT - Success
-- Performing Test HAVE_C_WFORMAT
-- Performing Test HAVE_C_WFORMAT - Success
-- Performing Test HAVE_CXX_WFORMAT_SECURITY
-- Performing Test HAVE_CXX_WFORMAT_SECURITY - Success
-- Performing Test HAVE_C_WFORMAT_SECURITY
-- Performing Test HAVE_C_WFORMAT_SECURITY - Success
-- Performing Test HAVE_CXX_WMISSING_DECLARATIONS
-- Performing Test HAVE_CXX_WMISSING_DECLARATIONS - Success
-- Performing Test HAVE_C_WMISSING_DECLARATIONS
-- Performing Test HAVE_C_WMISSING_DECLARATIONS - Success
-- Performing Test HAVE_CXX_WMISSING_PROTOTYPES
-- Performing Test HAVE_CXX_WMISSING_PROTOTYPES - Failed
-- Performing Test HAVE_C_WMISSING_PROTOTYPES
-- Performing Test HAVE_C_WMISSING_PROTOTYPES - Success
-- Performing Test HAVE_CXX_WSTRICT_PROTOTYPES
-- Performing Test HAVE_CXX_WSTRICT_PROTOTYPES - Failed
-- Performing Test HAVE_C_WSTRICT_PROTOTYPES
-- Performing Test HAVE_C_WSTRICT_PROTOTYPES - Success
-- Performing Test HAVE_CXX_WUNDEF
-- Performing Test HAVE_CXX_WUNDEF - Success
-- Performing Test HAVE_C_WUNDEF
-- Performing Test HAVE_C_WUNDEF - Success
-- Performing Test HAVE_CXX_WINIT_SELF
-- Performing Test HAVE_CXX_WINIT_SELF - Success
-- Performing Test HAVE_C_WINIT_SELF
-- Performing Test HAVE_C_WINIT_SELF - Success
-- Performing Test HAVE_CXX_WPOINTER_ARITH
-- Performing Test HAVE_CXX_WPOINTER_ARITH - Success
-- Performing Test HAVE_C_WPOINTER_ARITH
-- Performing Test HAVE_C_WPOINTER_ARITH - Success
-- Performing Test HAVE_CXX_WSHADOW
-- Performing Test HAVE_CXX_WSHADOW - Success
-- Performing Test HAVE_C_WSHADOW
-- Performing Test HAVE_C_WSHADOW - Success
-- Performing Test HAVE_CXX_WSIGN_PROMO
-- Performing Test HAVE_CXX_WSIGN_PROMO - Success
-- Performing Test HAVE_C_WSIGN_PROMO
-- Performing Test HAVE_C_WSIGN_PROMO - Failed
-- Performing Test HAVE_CXX_WUNINITIALIZED
-- Performing Test HAVE_CXX_WUNINITIALIZED - Success
-- Performing Test HAVE_C_WUNINITIALIZED
-- Performing Test HAVE_C_WUNINITIALIZED - Success
-- Performing Test HAVE_CXX_WSUGGEST_OVERRIDE
-- Performing Test HAVE_CXX_WSUGGEST_OVERRIDE - Success
-- Performing Test HAVE_C_WSUGGEST_OVERRIDE
-- Performing Test HAVE_C_WSUGGEST_OVERRIDE - Failed
-- Performing Test HAVE_CXX_WNO_DELETE_NON_VIRTUAL_DTOR
-- Performing Test HAVE_CXX_WNO_DELETE_NON_VIRTUAL_DTOR - Success
-- Performing Test HAVE_C_WNO_DELETE_NON_VIRTUAL_DTOR
-- Performing Test HAVE_C_WNO_DELETE_NON_VIRTUAL_DTOR - Failed
-- Performing Test HAVE_CXX_WNO_UNNAMED_TYPE_TEMPLATE_ARGS
-- Performing Test HAVE_CXX_WNO_UNNAMED_TYPE_TEMPLATE_ARGS - Failed
-- Performing Test HAVE_C_WNO_UNNAMED_TYPE_TEMPLATE_ARGS
-- Performing Test HAVE_C_WNO_UNNAMED_TYPE_TEMPLATE_ARGS - Failed
-- Performing Test HAVE_CXX_WNO_COMMENT
-- Performing Test HAVE_CXX_WNO_COMMENT - Success
-- Performing Test HAVE_C_WNO_COMMENT
-- Performing Test HAVE_C_WNO_COMMENT - Success
-- Performing Test HAVE_CXX_WIMPLICIT_FALLTHROUGH_3
-- Performing Test HAVE_CXX_WIMPLICIT_FALLTHROUGH_3 - Success
-- Performing Test HAVE_C_WIMPLICIT_FALLTHROUGH_3
-- Performing Test HAVE_C_WIMPLICIT_FALLTHROUGH_3 - Success
-- Performing Test HAVE_CXX_WNO_STRICT_OVERFLOW
-- Performing Test HAVE_CXX_WNO_STRICT_OVERFLOW - Success
-- Performing Test HAVE_C_WNO_STRICT_OVERFLOW
-- Performing Test HAVE_C_WNO_STRICT_OVERFLOW - Success
-- Performing Test HAVE_CXX_FDIAGNOSTICS_SHOW_OPTION
-- Performing Test HAVE_CXX_FDIAGNOSTICS_SHOW_OPTION - Success
-- Performing Test HAVE_C_FDIAGNOSTICS_SHOW_OPTION
-- Performing Test HAVE_C_FDIAGNOSTICS_SHOW_OPTION - Success
-- Performing Test HAVE_CXX_PTHREAD
-- Performing Test HAVE_CXX_PTHREAD - Success
-- Performing Test HAVE_C_PTHREAD
-- Performing Test HAVE_C_PTHREAD - Success
-- Performing Test HAVE_CXX_FOMIT_FRAME_POINTER
-- Performing Test HAVE_CXX_FOMIT_FRAME_POINTER - Success
-- Performing Test HAVE_C_FOMIT_FRAME_POINTER
-- Performing Test HAVE_C_FOMIT_FRAME_POINTER - Success
-- Performing Test HAVE_CXX_FFUNCTION_SECTIONS
-- Performing Test HAVE_CXX_FFUNCTION_SECTIONS - Success
-- Performing Test HAVE_C_FFUNCTION_SECTIONS
-- Performing Test HAVE_C_FFUNCTION_SECTIONS - Success
-- Performing Test HAVE_CXX_FDATA_SECTIONS
-- Performing Test HAVE_CXX_FDATA_SECTIONS - Success
-- Performing Test HAVE_C_FDATA_SECTIONS
-- Performing Test HAVE_C_FDATA_SECTIONS - Success
-- WARNING: Option ENABLE_NEON='ON' is deprecated and should not be used anymore
-- Behaviour of this option is not backward compatible
-- Refer to 'CPU_BASELINE'/'CPU_DISPATCH' CMake options documentation
-- Performing Test HAVE_CPU_NEON_SUPPORT (check file: cmake/checks/cpu_neon.cpp)
-- Performing Test HAVE_CPU_NEON_SUPPORT - Success
-- Performing Test HAVE_CPU_FP16_SUPPORT (check file: cmake/checks/cpu_fp16.cpp)
-- Performing Test HAVE_CPU_FP16_SUPPORT - Success
-- Performing Test HAVE_CPU_NEON_DOTPROD_SUPPORT (check file: cmake/checks/cpu_neon_dotprod.cpp)
-- Performing Test HAVE_CPU_NEON_DOTPROD_SUPPORT - Failed
-- Performing Test HAVE_CXX_MARCH_ARMV8_2_A+DOTPROD (check file: cmake/checks/cpu_neon_dotprod.cpp)
-- Performing Test HAVE_CXX_MARCH_ARMV8_2_A+DOTPROD - Success
-- Performing Test HAVE_CPU_NEON_FP16_SUPPORT (check file: cmake/checks/cpu_neon_fp16.cpp)
-- Performing Test HAVE_CPU_NEON_FP16_SUPPORT - Failed
-- Performing Test HAVE_CXX_MARCH_ARMV8_2_A+FP16 (check file: cmake/checks/cpu_neon_fp16.cpp)
-- Performing Test HAVE_CXX_MARCH_ARMV8_2_A+FP16 - Success
-- Performing Test HAVE_CPU_NEON_BF16_SUPPORT (check file: cmake/checks/cpu_neon_bf16.cpp)
-- Performing Test HAVE_CPU_NEON_BF16_SUPPORT - Failed
-- Performing Test HAVE_CXX_MARCH_ARMV8_2_A+BF16 (check file: cmake/checks/cpu_neon_bf16.cpp)
-- Performing Test HAVE_CXX_MARCH_ARMV8_2_A+BF16 - Success
-- Performing Test HAVE_CPU_BASELINE_FLAGS
-- Performing Test HAVE_CPU_BASELINE_FLAGS - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_NEON_DOTPROD
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_NEON_DOTPROD - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_NEON_FP16
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_NEON_FP16 - Success
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_NEON_BF16
-- Performing Test HAVE_CPU_DISPATCH_FLAGS_NEON_BF16 - Success
-- Performing Test HAVE_CXX_FVISIBILITY_HIDDEN
-- Performing Test HAVE_CXX_FVISIBILITY_HIDDEN - Success
-- Performing Test HAVE_C_FVISIBILITY_HIDDEN
-- Performing Test HAVE_C_FVISIBILITY_HIDDEN - Success
-- Performing Test HAVE_CXX_FVISIBILITY_INLINES_HIDDEN
-- Performing Test HAVE_CXX_FVISIBILITY_INLINES_HIDDEN - Success
-- Performing Test HAVE_C_FVISIBILITY_INLINES_HIDDEN
-- Performing Test HAVE_C_FVISIBILITY_INLINES_HIDDEN - Failed
-- Performing Test HAVE_LINK_AS_NEEDED
-- Performing Test HAVE_LINK_AS_NEEDED - Success
-- Performing Test HAVE_LINK_NO_UNDEFINED
-- Performing Test HAVE_LINK_NO_UNDEFINED - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for posix_memalign
-- Looking for posix_memalign - found
-- Looking for malloc.h
-- Looking for malloc.h - found
-- Looking for memalign
-- Looking for memalign - found
-- Looking for getauxval
-- Looking for getauxval - found
-- Looking for elf_aux_info
-- Looking for elf_aux_info - not found
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Found ZLIB: /usr/lib/aarch64-linux-gnu/libz.so (found suitable version "1.2.11", minimum required is "1.2.3")
-- Could NOT find AVIF (missing: AVIF_LIBRARY AVIF_INCLUDE_DIR)
-- Found JPEG: /usr/lib/aarch64-linux-gnu/libjpeg.so (found version "80")
-- Found TIFF: /usr/lib/aarch64-linux-gnu/libtiff.so (found version "4.3.0")
-- Performing Test HAVE_C_WNO_UNUSED_VARIABLE
-- Performing Test HAVE_C_WNO_UNUSED_VARIABLE - Success
-- Performing Test HAVE_C_WNO_UNUSED_FUNCTION
-- Performing Test HAVE_C_WNO_UNUSED_FUNCTION - Success
-- Performing Test HAVE_C_WNO_SHADOW
-- Performing Test HAVE_C_WNO_SHADOW - Success
-- Performing Test HAVE_C_WNO_MAYBE_UNINITIALIZED
-- Performing Test HAVE_C_WNO_MAYBE_UNINITIALIZED - Success
-- Performing Test HAVE_C_WNO_MISSING_PROTOTYPES
-- Performing Test HAVE_C_WNO_MISSING_PROTOTYPES - Success
-- Performing Test HAVE_C_WNO_MISSING_DECLARATIONS
-- Performing Test HAVE_C_WNO_MISSING_DECLARATIONS - Success
-- Performing Test HAVE_C_WNO_IMPLICIT_FALLTHROUGH
-- Performing Test HAVE_C_WNO_IMPLICIT_FALLTHROUGH - Success
-- Performing Test HAVE_C_WNO_UNUSED_BUT_SET_VARIABLE
-- Performing Test HAVE_C_WNO_UNUSED_BUT_SET_VARIABLE - Success
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- Performing Test HAVE_C_WNO_IMPLICIT_CONST_INT_FLOAT_CONVERSION
-- Performing Test HAVE_C_WNO_IMPLICIT_CONST_INT_FLOAT_CONVERSION - Failed
-- Performing Test HAVE_C_WNO_DOCUMENTATION
-- Performing Test HAVE_C_WNO_DOCUMENTATION - Failed
-- OpenJPEG: VERSION = 2.5.3, BUILD = opencv-4.12.0-openjp2-2.5.3
-- Looking for string.h
-- Looking for string.h - found
-- Looking for memory.h
-- Looking for memory.h - found
-- Looking for stdlib.h
-- Looking for stdlib.h - found
-- Looking for stdio.h
-- Looking for stdio.h - found
-- Looking for math.h
-- Looking for math.h - found
-- Looking for float.h
-- Looking for float.h - found
-- Looking for time.h
-- Looking for time.h - found
-- Looking for stdarg.h
-- Looking for stdarg.h - found
-- Looking for ctype.h
-- Looking for ctype.h - found
-- Looking for assert.h
-- Looking for assert.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for strings.h
-- Looking for strings.h - found
-- Looking for sys/stat.h
-- Looking for sys/stat.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for include file malloc.h
-- Looking for include file malloc.h - found
-- Looking for _aligned_malloc
-- Looking for _aligned_malloc - not found
-- Looking for posix_memalign
-- Looking for posix_memalign - found
-- Looking for memalign
-- Looking for memalign - found
-- Performing Test HAVE_C_WNO_UNDEF
-- Performing Test HAVE_C_WNO_UNDEF - Success
-- Performing Test HAVE_C_WNO_STRICT_PROTOTYPES
-- Performing Test HAVE_C_WNO_STRICT_PROTOTYPES - Success
-- Performing Test HAVE_C_WNO_CAST_FUNCTION_TYPE
-- Performing Test HAVE_C_WNO_CAST_FUNCTION_TYPE - Success
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.3")
-- Looking for semaphore.h
-- Looking for semaphore.h - found
-- Performing Test HAVE_CXX_WNO_SHADOW
-- Performing Test HAVE_CXX_WNO_SHADOW - Success
-- Performing Test HAVE_CXX_WNO_UNUSED
-- Performing Test HAVE_CXX_WNO_UNUSED - Success
-- Performing Test HAVE_CXX_WNO_SIGN_COMPARE
-- Performing Test HAVE_CXX_WNO_SIGN_COMPARE - Success
-- Performing Test HAVE_CXX_WNO_UNDEF
-- Performing Test HAVE_CXX_WNO_UNDEF - Success
-- Performing Test HAVE_CXX_WNO_MISSING_DECLARATIONS
-- Performing Test HAVE_CXX_WNO_MISSING_DECLARATIONS - Success
-- Performing Test HAVE_CXX_WNO_UNINITIALIZED
-- Performing Test HAVE_CXX_WNO_UNINITIALIZED - Success
-- Performing Test HAVE_CXX_WNO_SWITCH
-- Performing Test HAVE_CXX_WNO_SWITCH - Success
-- Performing Test HAVE_CXX_WNO_PARENTHESES
-- Performing Test HAVE_CXX_WNO_PARENTHESES - Success
-- Performing Test HAVE_CXX_WNO_ARRAY_BOUNDS
-- Performing Test HAVE_CXX_WNO_ARRAY_BOUNDS - Success
-- Performing Test HAVE_CXX_WNO_EXTRA
-- Performing Test HAVE_CXX_WNO_EXTRA - Success
-- Performing Test HAVE_CXX_WNO_DEPRECATED_DECLARATIONS
-- Performing Test HAVE_CXX_WNO_DEPRECATED_DECLARATIONS - Success
-- Performing Test HAVE_CXX_WNO_MISLEADING_INDENTATION
-- Performing Test HAVE_CXX_WNO_MISLEADING_INDENTATION - Success
-- Performing Test HAVE_CXX_WNO_DEPRECATED
-- Performing Test HAVE_CXX_WNO_DEPRECATED - Success
-- Performing Test HAVE_CXX_WNO_SUGGEST_OVERRIDE
-- Performing Test HAVE_CXX_WNO_SUGGEST_OVERRIDE - Success
-- Performing Test HAVE_CXX_WNO_INCONSISTENT_MISSING_OVERRIDE
-- Performing Test HAVE_CXX_WNO_INCONSISTENT_MISSING_OVERRIDE - Failed
-- Performing Test HAVE_CXX_WNO_IMPLICIT_FALLTHROUGH
-- Performing Test HAVE_CXX_WNO_IMPLICIT_FALLTHROUGH - Success
-- Performing Test HAVE_CXX_WNO_TAUTOLOGICAL_COMPARE
-- Performing Test HAVE_CXX_WNO_TAUTOLOGICAL_COMPARE - Success
-- Performing Test HAVE_CXX_WNO_MISSING_PROTOTYPES
-- Performing Test HAVE_CXX_WNO_MISSING_PROTOTYPES - Failed
-- Performing Test HAVE_CXX_WNO_REORDER
-- Performing Test HAVE_CXX_WNO_REORDER - Success
-- Performing Test HAVE_CXX_WNO_UNUSED_RESULT
-- Performing Test HAVE_CXX_WNO_UNUSED_RESULT - Success
-- Performing Test HAVE_CXX_WNO_IMPLICIT_CONST_INT_FLOAT_CONVERSION
-- Performing Test HAVE_CXX_WNO_IMPLICIT_CONST_INT_FLOAT_CONVERSION - Failed
-- Performing Test HAVE_CXX_WNO_CLASS_MEMACCESS
-- Performing Test HAVE_CXX_WNO_CLASS_MEMACCESS - Success
-- Found OpenBLAS in the system
-- OpenBLAS_LIBRARIES=/usr/lib/aarch64-linux-gnu/libopenblas.so
-- OpenBLAS_INCLUDE_DIRS=/usr/include/aarch64-linux-gnu
-- LAPACK(OpenBLAS): LAPACK_LIBRARIES: /usr/lib/aarch64-linux-gnu/libopenblas.so
CMake Warning at cmake/OpenCVFindLAPACK.cmake:60 (message):
LAPACK(OpenBLAS): CBLAS/LAPACK headers are not found in
'/usr/include/aarch64-linux-gnu'
Call Stack (most recent call first):
cmake/OpenCVFindLAPACK.cmake:190 (ocv_lapack_check)
CMakeLists.txt:817 (include)
-- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR Atlas_CBLAS_LIBRARY Atlas_BLAS_LIBRARY)
-- Looking for sgemm_
-- Looking for sgemm_ - not found
-- Found Threads: TRUE
-- Looking for sgemm_
-- Looking for sgemm_ - found
-- Found BLAS: /usr/lib/aarch64-linux-gnu/libopenblas.so
-- Looking for cheev_
-- Looking for cheev_ - found
-- Found LAPACK: /usr/lib/aarch64-linux-gnu/libopenblas.so;-lm;-ldl
-- Performing Test HAVE_CXX_WNO_UNUSED_PARAMETER
-- Performing Test HAVE_CXX_WNO_UNUSED_PARAMETER - Success
-- Performing Test HAVE_CXX_WNO_UNUSED_LOCAL_TYPEDEFS
-- Performing Test HAVE_CXX_WNO_UNUSED_LOCAL_TYPEDEFS - Success
-- Performing Test HAVE_CXX_WNO_SIGN_PROMO
-- Performing Test HAVE_CXX_WNO_SIGN_PROMO - Success
-- Performing Test HAVE_CXX_WNO_TAUTOLOGICAL_UNDEFINED_COMPARE
-- Performing Test HAVE_CXX_WNO_TAUTOLOGICAL_UNDEFINED_COMPARE - Failed
-- Performing Test HAVE_CXX_WNO_IGNORED_QUALIFIERS
-- Performing Test HAVE_CXX_WNO_IGNORED_QUALIFIERS - Success
-- Performing Test HAVE_CXX_WNO_UNUSED_FUNCTION
-- Performing Test HAVE_CXX_WNO_UNUSED_FUNCTION - Success
-- Performing Test HAVE_CXX_WNO_UNUSED_CONST_VARIABLE
-- Performing Test HAVE_CXX_WNO_UNUSED_CONST_VARIABLE - Success
-- Performing Test HAVE_CXX_WNO_SHORTEN_64_TO_32
-- Performing Test HAVE_CXX_WNO_SHORTEN_64_TO_32 - Failed
-- Performing Test HAVE_CXX_WNO_INVALID_OFFSETOF
-- Performing Test HAVE_CXX_WNO_INVALID_OFFSETOF - Success
-- Performing Test HAVE_CXX_WNO_ENUM_COMPARE_SWITCH
-- Performing Test HAVE_CXX_WNO_ENUM_COMPARE_SWITCH - Failed
-- Performing Test HAVE_CXX_WNO_STRINGOP_OVERFLOW
-- Performing Test HAVE_CXX_WNO_STRINGOP_OVERFLOW - Success
-- Performing Test HAVE_CXX_WNO_STRINGOP_OVERREAD
-- Performing Test HAVE_CXX_WNO_STRINGOP_OVERREAD - Success
-- Performing Test HAVE_CXX_WNO_EXTRA_SEMI
-- Performing Test HAVE_CXX_WNO_EXTRA_SEMI - Success
-- Performing Test HAVE_CXX_WNO_COMMA
-- Performing Test HAVE_CXX_WNO_COMMA - Failed
-- Could NOT find Java (missing: Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE)
-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Looking for dlerror in dl
-- Looking for dlerror in dl - found
-- Performing Test HAVE_C_WNO_SIGN_COMPARE
-- Performing Test HAVE_C_WNO_SIGN_COMPARE - Success
-- ADE: Downloading v0.1.2e.zip from https://github.com/opencv/ade/archive/v0.1.2e.zip
-- Checking for module 'gtk+-3.0'
-- Found gtk+-3.0, version 3.24.33
-- Checking for module 'gtk+-2.0'
-- No package 'gtk+-2.0' found
-- Checking for modules 'libavcodec;libavformat;libavutil;libswscale'
-- Found libavcodec, version 58.134.100
-- Found libavformat, version 58.76.100
-- Found libavutil, version 56.70.100
-- Found libswscale, version 5.9.100
-- Checking for module 'libavresample'
-- No package 'libavresample' found
-- Checking for module 'gstreamer-base-1.0'
-- No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-app-1.0'
-- No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
-- No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
-- No package 'gstreamer-pbutils-1.0' found
-- Checking for module 'gstreamer-video-1.0'
-- No package 'gstreamer-video-1.0' found
-- Checking for module 'gstreamer-audio-1.0'
-- No package 'gstreamer-audio-1.0' found
-- Allocator metrics storage type: 'int'
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse3.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.ssse3.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse4_1.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.sse4_2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin128.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin512.avx512_skx.cpp
-- Excluding from source files list: modules/imgproc/src/corner.avx.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.avx2.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.sse4_1.cpp
-- Excluding from source files list: modules/imgproc/src/resize.avx2.cpp
-- Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/resize.sse4_1.cpp
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/topeet/work/opencv_compile/opencv-4.12.0/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out cuda4dnn source code
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.avx512_skx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.avx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.avx2.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.lasx.cpp
-- Excluding from source files list: modules/features2d/src/fast.avx2.cpp
-- imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326
-- highgui: using builtin backend: GTK3
-- Use autogenerated whitelist /home/topeet/work/opencv_compile/opencv-4.12.0/build/modules/js_bindings_generator/whitelist.json
-- Found 'misc' Python modules from /home/topeet/work/opencv_compile/opencv-4.12.0/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from /home/topeet/work/opencv_compile/opencv-4.12.0/modules/core/misc/python/package
-- Found 'gapi' Python modules from /home/topeet/work/opencv_compile/opencv-4.12.0/modules/gapi/misc/python/package
-- Performing Test HAVE_CXX_WNO_OVERLOADED_VIRTUAL
-- Performing Test HAVE_CXX_WNO_OVERLOADED_VIRTUAL - Success
-- Performing Test HAVE_CXX_WNO_UNUSED_PRIVATE_FIELD
-- Performing Test HAVE_CXX_WNO_UNUSED_PRIVATE_FIELD - Failed
-- Found 'misc' Python modules from /home/topeet/work/opencv_compile/opencv-4.12.0/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from /home/topeet/work/opencv_compile/opencv-4.12.0/modules/core/misc/python/package
-- Found 'gapi' Python modules from /home/topeet/work/opencv_compile/opencv-4.12.0/modules/gapi/misc/python/package
--
-- General configuration for OpenCV 4.12.0 =====================================
-- Version control: unknown
--
-- Platform:
-- Timestamp: 2025-10-26T07:37:11Z
-- Host: Linux 5.10.198 aarch64
-- CMake: 3.22.1
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/gmake
-- Configuration: RELEASE
-- Algorithm Hint: ALGO_HINT_ACCURATE
--
-- CPU/HW features:
-- Baseline: NEON FP16
-- requested: DETECT
-- required: NEON
-- Dispatched code generation: NEON_DOTPROD NEON_FP16 NEON_BF16
-- requested: NEON_FP16 NEON_BF16 NEON_DOTPROD
-- NEON_DOTPROD (2 files): + NEON_DOTPROD
-- NEON_FP16 (2 files): + NEON_FP16
-- NEON_BF16 (0 files): + NEON_BF16
--
-- C/C++:
-- Built as dynamic libs?: YES
-- C++ standard: 11
-- C++ Compiler: /usr/bin/c++ (ver 11.4.0)
-- C++ flags (Release): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -O3 -DNDEBUG -DNDEBUG
-- C++ flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -g -O0 -DDEBUG -D_DEBUG
-- C Compiler: /usr/bin/cc
-- C flags (Release): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fopenmp -O3 -DNDEBUG -DNDEBUG
-- C flags (Debug): -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fopenmp -g -O0 -DDEBUG -D_DEBUG
-- Linker flags (Release): -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
-- Linker flags (Debug): -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
-- ccache: NO
-- Precompiled headers: NO
-- Extra dependencies: dl m pthread rt
-- 3rdparty dependencies:
--
-- OpenCV modules:
-- To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching ts video videoio
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: java python2
-- Applications: tests perf_tests apps
-- Documentation: NO
-- Non-free algorithms: NO
--
-- GUI: GTK3
-- GTK+: YES (ver 3.24.33)
-- OpenGL support: YES (/usr/lib/aarch64-linux-gnu/libGL.so)
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
-- JPEG: /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 80)
-- WEBP: build (ver decoder: 0x0209, encoder: 0x020f, demux: 0x0107)
-- AVIF: NO
-- PNG: /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.37)
-- TIFF: /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.3.0)
-- JPEG 2000: build (ver 2.5.3)
-- OpenEXR: build (ver 2.3.0)
-- GIF: YES
-- HDR: YES
-- SUNRASTER: YES
-- PXM: YES
-- PFM: YES
--
-- Video I/O:
-- FFMPEG: YES
-- avcodec: YES (58.134.100)
-- avformat: YES (58.76.100)
-- avutil: YES (56.70.100)
-- swscale: YES (5.9.100)
-- avresample: NO
-- GStreamer: NO
-- v4l/v4l2: YES (linux/videodev2.h)
--
-- Parallel framework: OpenMP
--
-- Trace: YES (with Intel ITT(3.25.4))
--
-- Other third-party libraries:
-- Lapack: NO
-- Eigen: NO
-- Custom HAL: YES (carotene (ver 0.0.1))
-- Protobuf: build (3.19.1)
-- Flatbuffers: builtin/3rdparty (23.5.9)
--
-- OpenCL: YES (no extra features)
-- Include path: /home/topeet/work/opencv_compile/opencv-4.12.0/3rdparty/include/opencl/1.2
-- Link libraries: Dynamic load
--
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.10.12)
-- Libraries: /usr/lib/aarch64-linux-gnu/libpython3.10.so (ver 3.10.12)
-- Limited API: NO
-- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.21.5)
-- install path: lib/python3.10/dist-packages/cv2/python-3.10
--
-- Python (for build): /usr/bin/python3
--
-- Java:
-- ant: NO
-- Java: NO
-- JNI: NO
-- Java wrappers: NO
-- Java tests: NO
--
-- Install to: /home/topeet/work/opencv_compile/opencv-4.12.0-install
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/topeet/work/opencv_compile/opencv-4.12.0/build
进行编译
# 编译命令
make -j16
# 安装到安装目录
make install
安装命令执行之后,会将编译好的头文件、库文件、可执行文件安装到设置的安装目录中。
OpenCV 4.12.0 编译安装后的 opencv-4.12.0-install 目录,是按 Linux 标准软件安装结构组织的,4 个核心目录分别对应可执行文件、头文件、库文件和资源文件,作用如下:
1. bin 目录:可执行工具
存放 OpenCV 官方提供的实用工具程序,用于开发测试或辅助操作,常用工具包括:
opencv_version:查看已安装的 OpenCV 版本(如./opencv_version直接输出 4.12.0);opencv_annotation:图像标注工具(用于生成训练数据,如目标检测标注);opencv_interactive-calibration:相机标定工具(校准摄像头畸变参数);opencv_perf_*/opencv_test_*:性能测试和功能测试工具(验证编译后的模块可用性)。
这些工具可直接在终端执行,无需额外配置依赖(已关联安装目录下的库文件)。
2. include 目录:开发头文件
存放 OpenCV 所有公开 API 的头文件,是 C/C++ 开发的核心依赖目录,结构如下:
plaintext
include/
└── opencv2/
├── core.hpp # 核心数据结构(矩阵、点、尺寸等)
├── imgproc.hpp # 图像处理(滤波、边缘检测等)
├── video.hpp # 视频分析(目标跟踪等)
├── highgui.hpp # 图形界面(imshow 显示图像等)
└── ...(其他模块头文件)
开发时需通过编译命令指定该目录为头文件搜索路径(如 g++ -I/path/to/include ...),才能正确引用 #include <opencv2/core.hpp> 等头文件。
3. lib 目录:核心库文件
存放编译生成的动态链接库(.so 文件)和静态库(.a 文件),是 OpenCV 功能实现的核心载体,也是开发和运行时的关键依赖:
- 动态链接库(
.so结尾,默认优先使用):如libopencv_core.so(核心模块)、libopencv_imgproc.so(图像处理模块),程序运行时需加载这些库; - 静态库(
.a结尾,可选):如libopencv_core.a,编译时可直接链接到程序中,无需依赖外部.so文件(生成的程序体积较大); pkgconfig目录:包含opencv4.pc文件,通过pkg-config --cflags --libs opencv4可快速获取编译所需的头文件路径和库文件链接参数(需配置环境变量指向该目录)。
4. share 目录:资源与文档
存放 OpenCV 的辅助资源和文档,主要包括:
OpenCV/子目录:包含测试图像、训练好的模型(如人脸检测的 Haar 级联分类器)、示例配置文件等;doc/子目录:OpenCV 离线文档(部分版本包含 HTML 格式的 API 说明,可直接用浏览器打开);- 其他资源:如
cmake/目录下的配置脚本,用于支持其他项目通过 CMake 自动查找该目录下的 OpenCV 库。
使用ximgproc拓展(可选)
🧩 一、模块概述
opencv_contrib/ximgproc 是 OpenCV 官方扩展仓库 opencv_contrib 中的一个模块,全称为:
ximgproc — Extended Image Processing Module
它的定位是:
为 OpenCV 核心
imgproc模块提供更高阶、更实用、更前沿的图像处理算法,
涵盖边缘增强、滤波、超像素、结构化森林、立体匹配等领域。
模块名中的 x 代表 “experimental/extended”。
🧠 二、主要功能类别
ximgproc 涵盖了多个图像处理领域,常用功能如下:
| 功能类别 | 代表函数/类 | 简介 |
|---|---|---|
| 🔹 滤波 / 边缘保留增强 | cv::ximgproc::guidedFilter, cv::ximgproc::anisotropicDiffusion, cv::ximgproc::rollingGuidanceFilter | 比传统高斯/双边滤波更保边缘,常用于图像平滑与深度图优化 |
| 🔹 WLS视差滤波 | cv::ximgproc::createDisparityWLSFilter() | 对立体匹配输出的视差图进行边缘保留平滑(非常适合 SGBM 输出) |
| 🔹 结构化边缘检测 (Structured Edge Detection) | cv::ximgproc::StructuredEdgeDetection | 使用随机森林模型的高质量边缘检测器(效果优于 Canny) |
| 🔹 超像素分割 (Superpixel) | cv::ximgproc::createSuperpixelSLIC(), createSuperpixelLSC(), createSuperpixelSEEDS() | 图像分割成“颜色连贯”的小区域(常用于目标检测预处理) |
| 🔹 图像引导滤波 (Guided Filtering) | cv::ximgproc::guidedFilter | 在引导图像下平滑目标图(经典论文 He et al. 2013) |
| 🔹 边缘/轮廓增强 | cv::ximgproc::thinning, cv::ximgproc::GradientDericheX/Y | 图像细化、边缘增强、骨架提取 |
| 🔹 线检测 (Fast Line Detector) | cv::ximgproc::createFastLineDetector() | 基于 LSD 的快速线段检测器 |
| 🔹 结构化森林深度学习边缘检测 | cv::ximgproc::StructuredEdgeDetection | 用预训练模型(.yml.gz)预测边缘概率图 |
| 🔹 立体匹配增强 | cv::ximgproc::createRightMatcher, cv::ximgproc::createDisparityWLSFilterGeneric() | 用于 StereoBM/SGBM 左右一致性优化与滤波 |
| 🔹 色彩映射 / 断层增强 | cv::ximgproc::colorMatchTemplate, cv::ximgproc::fastGlobalSmootherFilter | 匹配、平滑、边缘感知滤波 |
🔬 三、典型应用场景
| 场景 | 说明 |
|---|---|
| 🧱 立体视觉深度优化 | StereoSGBM 输出噪点多,WLS 滤波后深度边缘清晰、噪声抑制显著 |
| 👁️ 视觉SLAM / 3D重建前处理 | 使用 guidedFilter 或 rollingGuidanceFilter 平滑纹理、保留结构 |
| 🧍 人体/目标分割 | 超像素 + 边缘检测提高 mask 精度 |
| 📸 相机 ISP 后处理 | 双边滤波 / 导向滤波用于图像降噪、HDR 融合、色彩平滑 |
| 🛰️ 遥感 / 工业检测 | 结构化边缘检测、线检测、轮廓增强用于特征提取 |
四、构建配置
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/home/topeet/work/opencv_compile/opencv-4.12.0-install \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_opencv_java=OFF \
-D BUILD_opencv_python3=ON \
-D WITH_OPENMP=ON \
-D WITH_GSTREAMER=ON \
-D WITH_LIBV4L=ON \
-D WITH_OPENGL=ON \
-D WITH_TBB=ON \
-D BUILD_SHARED_LIBS=ON \
-D ENABLE_NEON=ON \
-D WITH_FFMPEG=ON \
-D WITH_JPEG=ON \
-D WITH_PNG=ON \
-D OPENCV_EXTRA_MODULES_PATH=/home/topeet/work/opencv_compile/opencv_contrib/modules \
-D BUILD_opencv_ximgproc=ON \
-D OPENCV_DOWNLOAD_DATA=OFF \
-D BUILD_opencv_xfeatures2d=OFF \
-D BUILD_opencv_face=OFF \
-D BUILD_opencv_wechat_qrcode=OFF \
..
可以关闭掉需要下载的模型
| 模块 | 功能 | 是否下载模型 | 是否可关 |
|---|---|---|---|
| ximgproc | WLS滤波/导向滤波/超像素 | 否 | 保留 |
| face | 人脸对齐 | ✅ 会下载 .dat | 可关 |
| xfeatures2d | SIFT/SURF/VGG | ✅ 会下载 .i | 可关 |
| wechat_qrcode | 微信二维码检测 | ✅ 会下载 .caffemodel | 可关 |
⚙️ 五、C++ 接口示例
✅ 1. 使用 WLS 滤波器优化 StereoSGBM 结果
#include <opencv2/opencv.hpp>
#include <opencv2/ximgproc/disparity_filter.hpp>
using namespace cv;
using namespace cv::ximgproc;
int main() {
Mat left = imread("left.png", IMREAD_GRAYSCALE);
Mat right = imread("right.png", IMREAD_GRAYSCALE);
Ptr<StereoSGBM> sgbm = StereoSGBM::create(0, 160, 5);
Mat dispL, dispR;
sgbm->compute(left, right, dispL);
Ptr<StereoMatcher> right_matcher = createRightMatcher(sgbm);
right_matcher->compute(right, left, dispR);
Ptr<DisparityWLSFilter> wls = createDisparityWLSFilter(sgbm);
wls->setLambda(8000.0);
wls->setSigmaColor(1.2);
Mat filtered_disp;
wls->filter(dispL, left, filtered_disp, dispR);
Mat filtered_8u;
filtered_disp.convertTo(filtered_8u, CV_8U, 255 / (160. * 16.));
imshow("WLS disparity", filtered_8u);
waitKey();
return 0;
}
✅ 2. 导向滤波 (Guided Filter)
#include <opencv2/ximgproc.hpp>
Mat src = imread("input.jpg");
Mat guide = src.clone();
Mat filtered;
cv::ximgproc::guidedFilter(guide, src, filtered, 8, 0.1);
🧱 五、CMake 配置
CMake 必须包含 ximgproc 模块:
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui calib3d ximgproc)
target_link_libraries(myapp PRIVATE ${OpenCV_LIBS})
🧩 六、常见版本与依赖关系
| OpenCV 主版本 | 对应 contrib 分支 | 是否含 ximgproc | 备注 |
|---|---|---|---|
| 4.5.x ~ 4.10.x | opencv_contrib-4.x | ✅ | 推荐 |
| 3.x | opencv_contrib-3.x | ✅ | 旧版本API略不同 |
| 5.x (未来) | 仍在 opencv_contrib | ✅ | 一般需要一起更新 |
⚠️ 七、常见问题
| 问题 | 原因 | 解决 |
|---|---|---|
undefined reference to cv::ximgproc::... | 没链接 ximgproc | 在 find_package 加 ximgproc |
No such file or directory | 没编译 contrib 模块 | 用 -DOPENCV_EXTRA_MODULES_PATH 重新编译 |
| WLS 输出全黑/错位 | 右视差未计算或类型不对 | createRightMatcher 必须匹配同一个 SGBM |
| OpenCV 找不到 ximgproc | 未安装 pkgconfig 或 PATH 不正确 | export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig |
🎯 八、总结
| 优势 | 缺点 |
|---|---|
| ✔️ 边缘保留效果出色 | ❌ 默认未编译进主 OpenCV,需额外模块 |
| ✔️ 提供超像素、结构化边缘、WLS、导向滤波等强大功能 | ❌ 一些算法速度较慢(CPU实现) |
| ✔️ 立体匹配后处理的标准方案(WLS) | ❌ CUDA 版本仅部分支持 |
本网站尊重知识产权,如有侵权,请及时联系我们删除。
本站所有原创内容仅用于学习和交流目的,未经作者和本站授权不得进行商业使用或盈利行为。








暂无评论内容