OpenCV (Open Source Computer Vision Library) is a high-performance C++ library for real-time computer vision and image processing. It provides a modular framework for handling image data, mathematical computations, and hardware-accelerated inference.
The repository is organized into a core library, optional functional modules, and platform-specific build scripts.
| Directory | Contents |
|---|---|
modules/ | Functional modules (core, imgproc, dnn, etc.). |
cmake/ | Build infrastructure, dependency detection, and module macros. |
platforms/ | Platform-specific configurations (Android, iOS, Maven, etc.). |
3rdparty/ | Bundled dependencies (zlib, libjpeg, libpng, etc.). |
Version constants are defined in the core headers and propagated through the build system:
| Macro | Value | File Reference |
|---|---|---|
CV_VERSION_MAJOR | 4 | modules/core/include/opencv2/core/version.hpp8 |
CV_VERSION_MINOR | 14 | modules/core/include/opencv2/core/version.hpp9 |
CV_VERSION_REVISION | 0 | modules/core/include/opencv2/core/version.hpp10 |
CV_VERSION_STATUS | "-pre" | modules/core/include/opencv2/core/version.hpp11 |
Sources: modules/core/include/opencv2/core/version.hpp1-27 CMakeLists.txt177-183
OpenCV is a collection of modules. Every module depends on opencv_core, which defines the fundamental Mat and UMat structures.
The following diagram illustrates the canonical dependencies between major modules and how they bridge from low-level data structures to high-level vision tasks.
Code Entity Mapping:
opencv_core: Defined in modules/core.opencv_imgproc: Defined in modules/imgproc.opencv_highgui: Defined in modules/highgui.ocv_add_module: CMake macro in cmake/OpenCVModule.cmake.Sources: modules/highgui/CMakeLists.txt3-7 modules/java/CMakeLists.txt16 cmake/OpenCVModule.cmake124-127
ocv_add_moduleModules are registered using the ocv_add_module macro cmake/OpenCVModule.cmake124 This macro handles dependency resolution and categorization.
Sources: cmake/OpenCVModule.cmake77-117 cmake/OpenCVModule.cmake124-155
OpenCV uses a sophisticated CMake-based build system that manages cross-platform compilation, hardware optimization, and third-party library integration.
The configuration process is split into two passes:
System Initialization Diagram:
Sources: CMakeLists.txt98-108 CMakeLists.txt189 cmake/OpenCVModule.cmake54-74
OpenCV utilizes a Universal Intrinsics layer to abstract SIMD instructions across architectures (SSE, AVX, NEON, VSX).
opencv2/core/hal/intrin.hpp (referenced via core_hal_intrin group modules/core/include/opencv2/core.hpp93).Sources: modules/core/src/system.cpp132-175 modules/core/include/opencv2/core.hpp89-98
OpenCV abstracts platform differences through backends, particularly for GUI and Video I/O.
The highgui module selects a windowing backend based on the environment modules/highgui/CMakeLists.txt50-192:
Backends for video capture and encoding include FFmpeg, GStreamer, Media Foundation (MSMF), and AVFoundation. These are often built as dynamic plugins modules/highgui/CMakeLists.txt9
Sources: modules/highgui/CMakeLists.txt50-192 CMakeLists.txt200-210
OpenCV provides high-level bindings by parsing C++ headers and generating glue code.
hdr_parser.py and gen2.py.modules/java. The build process generates JNI wrappers and JAR files modules/java/CMakeLists.txt58-63WRAP argument in ocv_add_module modules/java/CMakeLists.txt16Sources: modules/java/CMakeLists.txt1-18 cmake/OpenCVModule.cmake93-116
This wiki is structured to follow the library's architecture:
ocv_add_module, and cross-compilation.Mat, UMat, OpenCL, and SIMD.imgproc, dnn, features2d, calib3d, etc.ts), G-API, and specialized toolsets.Refresh this wiki