Library / SDK
opencv/opencv_contrib avatar
opencv/opencv_contrib

opencv_contrib: Building and Using OpenCV's Extra Modules

Repository for OpenCV's extra modules

10,208 stars5,954 forksC++Apache-2.0

At a glance

What is it?
opencv_contrib is the staging repository for experimental OpenCV modules that are not yet stable enough for the core library. It is the correct place to look when a capability is absent from standard OpenCV, and the CMake build flag OPENCV_EXTRA_MODULES_PATH is the mechanism for including any or all of its modules in a local build.
Who is it for?
Developers who need a module that is absent from the core OpenCV distribution should check opencv_contrib before building a custom solution. The trade-off is explicit: these modules lack stable APIs, are not as thoroughly tested as core modules, and the README recommends using them alongside the master branch or the latest releases of OpenCV rather than pinning to an older version.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 5 days ago.
What is it written in?
Mainly C++, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 29, 2026, and from our analysis. They are not legal advice.

Editorial analysis

Why opencv_contrib Exists and What It Stages

The core OpenCV library maintains binary compatibility and tries to provide stable performance and reliability across releases. That constraint means new or experimental modules cannot go directly into the core repository. They need time to mature, gain users, and stabilize their API before they are ready for that level of commitment.

openCV_contrib solves this with a staging area. The README describes its purpose: new modules should be developed separately and published in opencv_contrib first. Once a module matures and gains popularity, it is moved to the central OpenCV repository, and the development team provides production-quality support for it.

This model means opencv_contrib is always a mixed bag. Some of its modules are years old and practically stable. Others were added recently and may have breaking changes between point releases. The README is direct about this: modules quite often do not have stable APIs and are not well-tested. This is not a quality failure; it is the intended state of a staging repository.

Building OpenCV with Contrib Modules Using CMake

opencv_contrib does not build on its own. It builds together with the main OpenCV source. The cmake command that includes all contrib modules is:

bash
cd <opencv_build_directory>
cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
make -j5

The `OPENCV_EXTRA_MODULES_PATH` variable points to the `modules/` subdirectory of the opencv_contrib clone, not the repository root. After cmake completes, the standard make command builds OpenCV with all contrib modules included.

The README notes that contrib modules are under constant development and recommends using them alongside the master branch or the latest releases of OpenCV, not older pinned versions. Building a specific release of contrib against a different-version OpenCV core may produce compilation errors.

Selecting Specific Modules and Excluding Others

Building all contrib modules is not always necessary or desirable. CMake's `BUILD_opencv_*` options let the builder include only the modules they need. To exclude a specific module, pass its build flag as OFF:

bash
cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -DBUILD_opencv_legacy=OFF <opencv_source_directory>

This example excludes the `legacy` module. The same pattern applies to any module in the repository: replace `legacy` with the module name. To include samples from each module's samples folder:

bash
cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -DBUILD_EXAMPLES=ON <opencv_source_directory>

This builds the sample programs from each module's samples directory alongside the libraries. The top-level samples/ directory in the repository also contains shared sample data and Python samples.

Using cmake-gui to Add Contrib Modules

For users who prefer the graphical CMake interface, the README describes the cmake-gui workflow in seven steps. After launching cmake-gui and selecting the source and build directories, the key step is locating the OPENCV_EXTRA_MODULES_PATH parameter in the parameter list (the search form helps focus on it quickly) and setting it to the path of the `<opencv_contrib>/modules` directory using the browse button.

After pressing configure and generate, the build proceeds using the same make and make install sequence as the command-line workflow. The README notes that on the first configure pass, cmake-gui asks which makefile style to use.

The cmake-gui path produces an identical result to the command-line cmake invocation. The choice between them is a matter of preference. The command-line path is easier to script and reproduce in CI environments.

Linker Flags for Contrib Modules in Application Code

Building contrib modules into the OpenCV installation does not automatically link them into application code. Each contrib module requires its own linker flag. The README gives one explicit example: to use the aruco module, the `-lopencv_aruco` flag must be added to the linker flags in the application's build system or IDE.

This pattern extends to every contrib module. A project that uses the aruco module and any additional contrib module must add a `-lopencv_*` flag for each one. The module name in the flag matches the directory name under the `modules/` folder in the repository.

For CMake-based application projects, the `find_package(OpenCV)` call and the resulting `OpenCV_LIBS` variable typically include the contrib module libraries if they were built into the same OpenCV installation. The README does not document this scenario explicitly; it notes the flag requirement for IDE and non-CMake build systems.

Limitations and Stability Expectations

The README is clear that contrib modules should not be treated as production-stable. The specific language is: new modules quite often do not have stable APIs, and they are not well-tested. Teams that build products on contrib modules take on the maintenance burden of tracking API changes each time OpenCV is updated.

The repository has no GitHub releases. Tracking the 5.x branch directly, rather than tagged releases, means changes arrive continuously. The last push to the 5.x branch was on 2026-09-24, showing active development.

The repository's primary language is C++, and the documented build process is CMake-based. Teams using Python, Java, or Android through pre-built packages rather than custom builds should check their package distribution (such as pip-installed OpenCV wheels or Android SDK packages) to see which contrib modules, if any, are included. The README does not document pre-built package sources; it covers source builds only.

opencv_contrib vs Core OpenCV

The core OpenCV library, maintained in the separate opencv/opencv repository, contains modules that have passed through the contrib staging process or were developed directly in the core. They carry stable APIs, production-level test coverage, and binary compatibility guarantees between minor versions.

openCV_contrib contains what the core does not: modules in development, niche algorithms, and capabilities that have not yet reached the stability threshold for core inclusion. For many computer vision tasks, the core library is sufficient, and adding contrib introduces build complexity without benefit. When a needed algorithm is absent from core, opencv_contrib is the first place to check before writing the algorithm from scratch.

The movement from contrib to core is documented in the README as the intended lifecycle. Modules that are relied upon in contrib today may eventually arrive in core with a stable API, at which point the contrib build flag is no longer necessary. Teams should monitor OpenCV release notes for notifications of such promotions.

Editorial conclusion

Developers who need a module that is absent from the core OpenCV distribution should check opencv_contrib before building a custom solution. The trade-off is explicit: these modules lack stable APIs, are not as thoroughly tested as core modules, and the README recommends using them alongside the master branch or the latest releases of OpenCV rather than pinning to an older version. The 5.x default branch had its last push on 2026-09-24, showing active development. Any project that depends on a contrib module should plan for API changes and test compatibility each time OpenCV is updated, since the stability guarantees are different from what the core library provides.

Frequently asked questions

What is opencv_contrib?

opencv_contrib is the staging repository for OpenCV's extra modules. It contains new or experimental modules that are not yet stable enough for the core OpenCV library. Once a module matures and gains popularity, it is moved to the central OpenCV repository.

How do I build OpenCV with opencv_contrib modules?

Clone both the opencv and opencv_contrib repositories, create a build directory, and run cmake with -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules pointing to the modules subfolder of the opencv_contrib clone. Then run make to build.

What is the difference between OpenCV Python and OpenCV Contrib Python?

The standard OpenCV Python package includes only the core OpenCV modules. The contrib variant includes the additional experimental modules from the opencv_contrib repository. The contrib modules lack stable APIs and the README warns they should be used alongside the master branch or latest releases of OpenCV.

How do I install only specific opencv_contrib modules?

Pass the BUILD_opencv_* CMake flag set to OFF for each module you want to exclude. For example, -DBUILD_opencv_legacy=OFF excludes the legacy module. All other modules in the OPENCV_EXTRA_MODULES_PATH will be built.

Official sources

  1. Issues
  2. License: Apache-2.0
  3. opencv/opencv_contrib on GitHub
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/opencv-opencv-contrib.svg)](https://hysenlabs.com/projects/opencv-opencv-contrib)