Contrib guide

OpenCV contrib modules on Windows — install & use extra features

Install OpenCV contrib modules on Windows in one command: pip install opencv-contrib-python. Covers SIFT, face recognition, ArUco, object tracking and more.

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:

ModuleWhat it provides
xfeatures2dSIFT, SURF, ORB descriptors (patent-free since 2020)
faceFace recognition (Eigenfaces, Fisherfaces, LBPH)
textScene text detection and recognition
arucoArUco marker detection
trackingObject tracking algorithms (CSRT, KCF, MOSSE)
bgsegmBackground subtraction algorithms
dnn_superresSuper-resolution with neural networks
ximgprocGuided filter, domain transform, superpixels

Install contrib with pip

The easiest way to get contrib modules on Windows is via the opencv-contrib-python pip package:

cmd.exe
# 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.

Using contrib modules in Python

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)

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.

Need SIFT for face recognition?

Full face detection and recognition quickstart.

Face detection guide