# opencv/opencv_contrib architecture

> Architecture diagram of the GitHub repository opencv/opencv_contrib, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/opencv/opencv_contrib
- Repository: https://github.com/opencv/opencv_contrib

## Overview

##### Overall Project Structure and Purpose
- The repository is intended to collect “extra” modules that contribute functionality not yet added to the core OpenCV. Modules may be experimental or maturing and are integrated via a CMake build process.
- The repository is structured with individual modules located in the “modules” folder. Each module has its own subdirectories for source code (src), headers (include), documentation (doc), samples, tests, and sometimes configuration files such as CMakeLists.txt.

##### Main Components
a. OpenCV Build Integration:
– Represent a central “OpenCV Core” (or main OpenCV repository) that “includes” the extra modules via the CMake parameter OPENCV_EXTRA_MODULES_PATH.
b. Contrib Modules Collection:
– Show a large container labeled “Extra Modules” or “Contrib Modules” which houses many modular components (for example, aruco, bioinspired, bgsegm, etc.). You may choose to group them if desired (or simply list a few representative module blocks) to reflect their independently developed nature.
– For each module, show sub-components: source, header files, documentation, samples, and tests.
c. Samples and Tests:
– Indicate a “Samples” component at the top level (and within individual modules) that demonstrates usage.
– Include “Tests” components that validate each module’s functionality.
d. Optional Dependencies and Build Options:
– Include a component for “CMake Configuration” which takes parameters such as OPENCV_EXTRA_MODULES_PATH and BUILD_EXAMPLES. This illustrates that the extra modules are only included if provided properly during the configuration process.
– Mention that some modules might rely on external dependencies (e.g., other libraries, optional modules) and may have separate build options (like BUILD_opencv_legacy).

##### Architectural Relationships and Data Flow
- Dependency lines from individual modules to the OpenCV Core indicating that these modules extend or rely on core computer vision routines.
- Optionally, if modules share sample applications or tests, show communication flows among “Module Samples” and “Test Suites.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["CMake (Build Configuration)"]:::build
    B["OpenCV Core Build Integration"]:::core
    C["Extra Modules Collection"]:::module
    D["Samples & Examples"]:::samples
    E["Test Suite"]:::tests
    F["Documentation & Tutorials"]:::docs

    %% Main Integration Flow
    A -->|"configures"| B
    A -->|"adds"| C
    C -->|"contains"| G["Module: aruco"]:::module
    C -->|"contains"| H["Other Modules"]:::module
    G -->|"extends"| B
    C -->|"provides"| D
    C -->|"validates"| E
    C -->|"supports"| F

    %% Module: aruco Internal Structure
    subgraph "Module: aruco Details"
        GA["Source (src)"]:::module
        GB["Headers (include)"]:::module
        GC["Documentation (doc)"]:::docs
        GD["Samples"]:::samples
        GE["Tests"]:::tests
        G --> GA
        GA --> GB
        GB --> GC
        GC --> GD
        GD --> GE
    end

    %% Click Events
    click A "https://github.com/opencv/opencv_contrib/blob/4.x/CMakeLists.txt (in each module folder, and also use of OPENCV_EXTRA_MODULES_PATH in the main OpenCV build)"
    click C "https://github.com/opencv/opencv_contrib/tree/4.x/modules/"
    click G "https://github.com/opencv/opencv_contrib/tree/4.x/modules/*"
    click D "https://github.com/opencv/opencv_contrib/tree/4.x/modules/*/samples/ & samples/"
    click E "https://github.com/opencv/opencv_contrib/tree/4.x/modules/*/test/"
    click F "https://github.com/opencv/opencv_contrib/tree/4.x/doc/ & modules/*/doc/ and modules/*/tutorials/"
    click B "https://github.com/opencv/opencv_contrib/blob/4.x/Root-level files like CMakeLists.txt, and usage instructions in README.md"

    %% Styles
    classDef build fill:#FDD835,stroke:#000,stroke-width:2px;
    classDef core fill:#90CAF9,stroke:#000,stroke-width:2px;
    classDef module fill:#A5D6A7,stroke:#000,stroke-width:2px;
    classDef samples fill:#FFE082,stroke:#000,stroke-width:2px;
    classDef tests fill:#C5E1A5,stroke:#000,stroke-width:2px;
    classDef docs fill:#B3E5FC,stroke:#000,stroke-width:2px;
```
