# OpenCV

> 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

- Category: Multimodal Generation / Vision & Understanding
- Language: C++
- Licence: Apache-2.0
- Repository: https://github.com/opencv/opencv
- Website: https://opencv.org
- Canonical page: https://ai-tldr.dev/tools/opencv/
- Updated: 2026-06-08

## In short

OpenCV is the reference open-source library for computer vision. It sits in the Vision & Understanding category of the Multimodal Generation tools and is open-source, written in C++ and licensed Apache-2.0. To get started: install the Python bindings.

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

1. Install the Python bindings

   The official prebuilt wheels are published on PyPI as opencv-python.

```bash
pip install opencv-python
```

2. Read 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>().

```python
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)
```

3. 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.

```python
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)
```

4. 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.

```bash
git clone https://github.com/opencv/opencv.git
cmake -S opencv -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
cmake --install build
```

5. Check 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.

```text
https://github.com/opencv/opencv/wiki/OpenCV-4-to-5-migration
```

## 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

## Version history

- 2026-06-08 5.0.0: OpenCV 5.0 shipped a rewritten graph-based DNN engine with much wider ONNX coverage, in-library LLM and VLM inference with embedded tokenizers and a KV-cache, and an ONNX-only model zoo on Hugging Face. C++17 and Python 3+ are now required, the C API was removed, and calib3d was split into geometry, calib, stereo and ptcloud.
