What are contrib modules?
OpenCV contrib — extra community modules
opencv_contrib is a separate repository of extra OpenCV modules that are maintained by the community. They include algorithms that are either experimental, patented (SIFT, SURF), or too specialised for the main repository. Some of the most popular contrib modules:
| Module | What it provides |
|---|---|
xfeatures2d | SIFT, SURF, ORB descriptors (patent-free since 2020) |
face | Face recognition (Eigenfaces, Fisherfaces, LBPH) |
text | Scene text detection and recognition |
aruco | ArUco marker detection |
tracking | Object tracking algorithms (CSRT, KCF, MOSSE) |
bgsegm | Background subtraction algorithms |
dnn_superres | Super-resolution with neural networks |
ximgproc | Guided filter, domain transform, superpixels |
Easiest method
Install contrib with pip
The easiest way to get contrib modules on Windows is via the opencv-contrib-python pip package:
# Remove any existing opencv-python first:
C:\> pip uninstall opencv-python -y
# Install the contrib variant:
C:\> pip install opencv-contrib-python
Successfully installed opencv-contrib-python-4.12.0.86
# Verify contrib modules are available:
C:\> python -c "import cv2; print(cv2.xfeatures2d)"
<module 'cv2.xfeatures2d'>
Do not install both
opencv-python and opencv-contrib-python at the same time. Uninstall the regular package first.Usage examples
Using contrib modules in Python
import cv2
# SIFT feature detection (from xfeatures2d):
sift = cv2.SIFT_create()
kp, des = sift.detectAndCompute(gray_img, None)
# Face recogniser (from face module):
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.train(images, labels)
# ArUco marker detection:
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
corners, ids, _ = cv2.aruco.detectMarkers(frame, aruco_dict)
FAQ
Contrib module questions
cv2.xfeatures2d has no attribute SIFT_create
SIFT was moved to the main OpenCV module in version 4.4.0 (the patent expired). Use
cv2.SIFT_create() directly instead of cv2.xfeatures2d.SIFT_create(). If you still get an error, make sure you have opencv-contrib-python 4.4+.cv2.face module not available
Install
opencv-contrib-python (not just opencv-python). Run pip show opencv-contrib-python to check. If you have the regular package, uninstall it first: pip uninstall opencv-python -y then pip install opencv-contrib-python.Do I need to build from source to get contrib?
No. For Python,
pip install opencv-contrib-python is sufficient. For C++, vcpkg with opencv4[contrib] is the easiest way. Build from source only if you need a custom configuration or CUDA with contrib modules.