Overview
OpenCV is the reference open-source library for computer vision. It provides the primitives almost every vision pipeline is built from — reading and writing images and video, colour conversion, filtering, feature detection, camera calibration, stereo matching, optical flow, object detection — with a C++ core and first-class Python and Java bindings. It is Apache-2.0 licensed and has been developed in the open since 2012 on GitHub, with extra and experimental algorithms living in the separate `opencv_contrib` repository.
Version 5.0, tagged in June 2026, is the first major release in a decade and reworks the deep-learning path. A new inference engine runs alongside the classic one and covers far more of the ONNX specification — the project's own OpenCV 5 wiki page puts the new engine at over 64% of the spec against under 13% for the 4.x engine — with much better handling of dynamic shapes. The engine is selected automatically and falls back to the classic one when a model cannot be loaded, so existing code keeps working; you can force a choice with the `engine=` argument to `readNetFromONNX` or the `OPENCV_FORCE_DNN_ENGINE` environment variable.
The same release makes vision-language models runnable end to end inside OpenCV: attention layers, decoding blocks, post-processing and a KV-cache are implemented in the library, and tokenizers are embedded in the inference pipeline so no external dependency is needed. The model zoo moved to Hugging Face and now ships ONNX only. The 5.x line also tightens the platform: C++17 and Python 3.6+ are required, the old C API is gone, Darknet and Caffe importers were removed in favour of ONNX, `calib3d` was split into `geometry` / `calib` / `stereo` / `ptcloud`, and `features2d` became `features`.
What it does
- Comprehensive classical vision: image and video I/O, filtering, transforms, feature detection, calibration, stereo, tracking and optical flow
- New DNN inference engine in 5.x with far wider ONNX coverage and proper dynamic-shape support, with automatic fallback to the classic engine
- LLM and VLM inference in-library — attention layers, decoding blocks, post-processing, KV-cache and embedded tokenizers
- ONNX-only model zoo hosted on Hugging Face; Darknet and Caffe importers removed in 5.x
- GPU acceleration for the DNN path through ONNX Runtime execution providers; the native new engine is CPU-only for now
- C++ core with Python and Java bindings, Apache-2.0 licensed, with extra algorithms in the opencv_contrib repository
Getting started
For Python the prebuilt wheel is the fastest route; C++ users build from source with CMake.
Install the Python bindings
The official prebuilt wheels are published on PyPI as opencv-python.
pip install opencv-pythonRead and transform an image
The Python module is imported as cv2 regardless of the 5.x module restructuring — every function is still reachable as cv2.<funcname>().
import cv2
img = cv2.imread("photo.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 100, 200)
cv2.imwrite("edges.png", edges)Run an ONNX model through the DNN module
In 5.x the new engine is used by default and falls back to the classic engine if a model cannot be loaded. Pass engine= to force one explicitly.
import cv2
# default: new engine, with automatic fallback
net = cv2.dnn.readNetFromONNX("model.onnx")
# force the classic engine
net = cv2.dnn.readNetFromONNX("model.onnx", engine=cv2.dnn.ENGINE_CLASSIC)Build the C++ library from source
OpenCV 5 requires C++17 and at least GCC 8, Clang 9 or MSVC 2017. Add opencv_contrib on the module path if you need SURF, ml, gapi or the Haar cascades, which moved there in 5.x.
git clone https://github.com/opencv/opencv.git
cmake -S opencv -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
cmake --install buildCheck the migration notes before upgrading from 4.x
The project maintains a 4→5 migration guide covering the module splits, the removed C API, the new CV_16BF / CV_32U / CV_64U / CV_64S / CV_Bool types, 1D array semantics (use .total() rather than .rows), and the changed resize and warp numerics.
https://github.com/opencv/opencv/wiki/OpenCV-4-to-5-migrationCommands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Build a classical vision pipeline — preprocessing, detection, calibration, tracking — in C++ or Python
- Run an ONNX detection, segmentation or vision-language model without adding a separate inference runtime
- Preprocess frames feeding a deep-learning model, where OpenCV's decode and resize path is usually the bottleneck
- Ship vision code to constrained targets, using the C++17 core with no Python runtime present
How OpenCV compares
OpenCV alongside other open-source vision & understanding tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| OpenCV | ★ 90.9k | The long-standing open-source computer-vision library — image and video processing, camera geometry and, since version 5, a rewritten neural-network engine that runs ONNX models including VLMs |
| PaddleOCR | ★ 89.8k | A toolkit for detecting and recognizing text in images across many languages, plus document parsing. |
| Ultralytics YOLO | ★ 61.8k | A framework for training and running YOLO models for real-time object detection, segmentation, and tracking. |
| Supervision | ★ 50.9k | A Python toolkit for processing, annotating, and visualizing detections and segmentations from many vision models. |
| MediaPipe | ★ 37k | Google's on-device ML framework: ready-to-run vision, text and audio tasks with one cross-platform API for Android, iOS, web, desktop and edge. |
| MMDetection | ★ 32.9k | An OpenMMLab toolbox with many object detection and instance segmentation algorithms for research and production. |
| vit-pytorch | ★ 25.5k | A single pip package with readable PyTorch implementations of the Vision Transformer and dozens of its research variants, for training image models from scratch. |
| Segment Anything 2 (SAM 2) | ★ 19.9k | Meta's model for segmenting and tracking any object across images and video frames from clicks or boxes. |