OpenCV Contrib Python Headless

4.13.0.92 · active · verified Thu Apr 09

OpenCV (Open Source Computer Vision Library) is a powerful, open-source computer vision and machine learning software library. This specific Python binding package, `opencv-contrib-python-headless`, provides access to both the main OpenCV modules and the 'contrib' (extra) modules, but without any graphical user interface (GUI) dependencies like Qt. This makes it ideal for server-side processing, cloud deployments, Docker containers, and embedded systems where no display is available. It is currently at version 4.13.0.92 and follows a frequent release cadence, often tied to major OpenCV C++ library releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic image manipulation in a headless environment. It creates a dummy image, performs a rectangle drawing and grayscale conversion, and prints image properties. It explicitly avoids GUI functions like `cv2.imshow()` which are not available in the headless build.

import cv2
import numpy as np

# Create a dummy image (e.g., a black 100x100 pixel image)
# In a headless environment, you would typically load an image from disk or a stream
image = np.zeros((100, 100, 3), dtype=np.uint8)

# Perform a simple operation: draw a white rectangle
cv2.rectangle(image, (20, 20), (80, 80), (255, 255, 255), -1)

# Convert image to grayscale
grayscale_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Print image properties (no GUI interaction)
print(f"OpenCV Version: {cv2.__version__}")
print(f"Original Image Shape: {image.shape}")
print(f"Grayscale Image Shape: {grayscale_image.shape}")

# Example of using a contrib module (if applicable and available in this build)
# Note: Not all contrib features are guaranteed to be present or stable.
# For example, SIFT/SURF are in contrib and often patented/non-free. We'll use a simpler one.
# Example: Feature2D algorithms are common in contrib.
# This specific example might not run without a specific image for feature detection
# For simplicity, we'll stick to basic operations for quickstart.

view raw JSON →