Skip to content

OpenCV 5

Abhishek Gola edited this page Jun 5, 2026 · 30 revisions

This page describes new features and other notable changes in OpenCV 5.0.

A note on 4.x and 5.x branches

OpenCV maintains two active development branches: the previous stable 4.x branch and 5.x branch (now also stable) where most of the latest functionality will be put to. Many improvements — performance optimizations, new codec support, SIMD and HAL work — have been developed in 4.x and continuously backported to 5.x.

OpenCV 5.0 takes the best and most commonly used parts of OpenCV 4.x, adds new features, removes obsolete functionality and introduces a few (not many) of API changes. If you are migrating an existing project, see the Migration Guide for a full list of breaking changes and recommended upgrade paths.


Release highlights

General changes

  • C++17 is now the minimum required C++ standard. OpenCV is built with C++17 by default; it should be compatible with the newer standards as well.
  • Python 2 support has been removed. OpenCV now requires Python 3.6 or later, and only Python 3 bindings are built and distributed.

Big OpenCV cleanup

A large-scale cleanup was carried out to shed technical debt accumulated over the years:

  • C API removed. All C functions (cvCreateMat(), cvFindContours(), etc.) and C structures (CvMat and friends) have been removed. Some CV_ macros such as CV_8U are still in use. This closes the book on the OpenCV 1.x API era.
  • OpenVX support removed. We are still (2026 June) working on non-CPU HAL (#25025) that could be used by vendors to integrate custom acceleration, including OpenVX-based acceleration, into OpenCV.
  • Graph API (G-API) module has been moved to opencv_contrib.
  • Classic ML module has been moved to opencv_contrib. Python users looking for a maintained alternative are encouraged to use scikit-learn.
  • Features2D module renamed to Features. Its scope has been extended to handle feature vectors produced by modern deep networks. Several obsolete detectors and descriptors have been moved to opencv_contrib; SIFT, ORB, FAST, GoodFeaturesToTrack and MSER remain in the main repository. Deep learning-based local features have been added, including ALIKED and DISK, together with the LightGlue feature matcher.
  • Annoy-based ANN search has been added to the Features module as a modern replacement for FLANN-based approximate nearest neighbor search.
  • Objdetect module cleanup. Haar-based and HOG-based detectors have been moved to opencv_contrib (xobjdetect). Modern deep learning-based detectors are both faster and more accurate.
  • Calib3d module split into four modules:
    • geometry — classic 2D, 3D, nD geometry algorithms
    • calib — camera calibration
    • stereo — depth map estimation via stereo correspondence
    • ptcloud — high-level 3D algorithms (visual odometry, TSDF (volume integration), etc.)
  • Samples cleanup. About 50% of C++ samples and a small number of Python samples that were outdated or redundant have been removed. The remaining samples have been substantially revised.

See also #25007


Updated Core module

  • Extended set of data types. In addition to the types available in OpenCV 4.x (CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F, CV_16F), OpenCV 5.x introduces:

    • CV_16BFcv::bfloat
    • CV_32Uuint32_t
    • CV_64Uuint64_t
    • CV_64Sint64_t
    • CV_Boolbool (1 byte per value; any non-zero byte is true)

    cv::Mat of type CV_Bool can be used as a mask wherever a uchar (uint8_t) or schar (int8_t) mask was previously accepted. Basic arithmetic operations on cv::hfloat and cv::bfloat are always available, even on hardware without native support. The new types are supported across cv::Mat, cv::UMat, cv::GpuMat, InputArray/OutputArray, core module operations, DNN, imgproc, FileStorage, and language bindings.

  • 1D and 0D arrays. OpenCV now supports arrays of fewer than 2 dimensions. A std::vector<T> wrapped into Mat or InputArray/OutputArray is now a true 1D array rather than the 2D Nx1 or 1xN representation used in 4.x. For 1D arrays: Mat::dims == Mat::rows == 1, Mat::cols == Mat::total() == N. For 0D arrays (scalars): Mat::dims == 0, Mat::rows == Mat::cols == Mat::total() == 1. Use mat.empty() to distinguish between an empty matrix and a scalar.

  • Improved N-dimensional array support. MatShape replaces MatSize (an alias is provided for compatibility). It carries shape and data layout information and is embedded directly into Mat, UMat and GpuMat without extra dynamic memory allocation. MatShape can be used as a standalone structure (unlike MatSize) and it is used extensively as such in the DNN module for shape inference.

  • Lapack always available. OpenCV now always has access to Lapack for SVD, eigenvalue/eigenvector decomposition and the USAC framework. When no external Lapack is installed, OpenCV builds and uses an internal minimal subset.


Updated Imgproc module

  • Computational geometry algorithms from imgproc — convex hull, Delaunay triangulation and related — have been moved to the geometry module. C++ users may need to add an extra #include "opencv2/geometry.hpp"; Python users are unaffected since all functions remain accessible as cv2.<funcname>(). Java and other language binding users will need to add an import and use Geometry.<funcname>() instead of Imgproc.<funcname>(). The API itself is unchanged.

  • Accelerated image warping. warpAffine, warpPerspective and remap have been substantially revised. Bilinear and bicubic interpolation no longer use table-based approximations, resulting in both higher accuracy (smoother gradients) and better performance. Speed improvements range from 10% to over 300% depending on platform, image size, type and operation flags.

  • Nearest-neighbor resize now follows the Pillow algorithm and produces results fully compatible with it.

  • Improved text rendering. The text rendering engine has been replaced with an STB-based TrueType renderer backed by an embedded variable TrueType font (Rubik). Users can also load custom fonts. Unicode symbols are now broadly supported, with a few caveats: scripts requiring complex shaping (Arabic, Devanagari, etc.) are not yet rendered correctly — Harfbuzz integration is needed for that — and color emoji are not supported by the STB engine.

  • Faster TRUCO contour extraction algorithm. The new 'Threaded Raster Unrestricted Contour Ownership' algorithm has been contributed by the algorithm author, prof. Salinas #28773. It's several times faster than the previous cv::findContours() implementation. cv::findContours() uses TRUCO automatically whenever possible.


Radically revised DNN module

The DNN module has seen the largest set of changes since OpenCV 4.x.

  • New inference engine. A new engine now coexists with the classic one. It provides much better support for dynamic shapes, subgraphs and other modern ONNX features, covering over 80% of the ONNX specification — a substantial improvement over OpenCV 4.x, which covers less than 23%.

  • Engine selection. cv::dnn::readNet(), cv::dnn::readNetFromONNX() etc. accept a new int engine = ENGINE_AUTO parameter. By default the new engine is tried first, with automatic fallback to the classic engine if the model cannot be loaded. The engine can also be controlled via the OPENCV_FORCE_DNN_ENGINE environment variable:

    • 1 — always use the classic engine
    • 2 — always use the new engine; fail if the model cannot be loaded
    • 3 — auto (default)
    • 4 — use ONNX Runtime (ORT)

    Note that the engine cannot be switched after a model has been loaded, since the two engines use different internal representations.

  • ONNX Runtime integration. OpenCV can now be built with ORT linked in. OpenCV uses its own ONNX parser to construct the ORT graph internally, so only ORT itself is required — not the full ONNX package — keeping binary size small. To enable ORT, pass -DWITH_ONNXRUNTIME=ON -DDOWNLOAD_ONNXRUNTIME=ON to CMake. For NVIDIA GPU execution providers, use -DWITH_ONNXRUNTIME=ON -DDOWNLOAD_ONNXRUNTIME_GPU=ON.

  • GPU support. The new engine currently runs on CPU only. GPU support will be added in subsequent releases. In the meantime, users who need GPU acceleration can either force the classic engine or build OpenCV with ORT and NVIDIA execution providers.

  • Removed parsers. The Darknet and Caffe parsers have been removed; the vast majority of models have been converted to ONNX. TFLite is still supported via the classic engine; migration to the new engine is planned.

  • Vision-language model support. The new engine includes the tokenizers and all necessary components: attention layers, decoding blocks, post-processing, KV-cache, to run VLMs end-to-end. See the VLM inference sample for a complete runnable example.

    Given this input image:

    VLM demo input

    the model produces: "the best football players in the world".

  • Performance. The new engine delivers competitive CPU inference performance, matching or beating ONNX Runtime on many models. The numbers below are inference time in milliseconds (lower is better); ONNX Runtime (1.25.1) is the official binaries published on the project's GitHub releases page. A representative selection is shown here — see the complete benchmark tables for every model on each device.

    Intel i9

Model OpenCV ONNX Runtime (1.25.1)
MobileNetv2 1.35 1.06
ResNet_50_v1 7.28 6.78
YOLOv8 12.42 12.98
VIT_Base_Patch16_224 38.2 35.68
SAM2 ENCODER 2350.57 2280.78

Intel i7

Model OpenCV ONNX Runtime (1.25.1)
MobileNetv2 3.51 2.11
ResNet_50_v1 18.51 13.28
YOLOv8 28.82 25.54
VIT_Base_Patch16_224 76 69.1
SAM2 ENCODER 5669.38 7261.39

Apple M1

Model OpenCV ONNX Runtime (1.25.1)
MobileNetv2 5.61 6.16
ResNet_50_v1 27.58 37.19
YOLOv8 41.13 54.71
VIT_Base_Patch16_224 126.94 143.61
SAM2 ENCODER 7454.963 8555.085

Apple M5

Model OpenCV ONNX Runtime (1.25.1)
MobileNetv2 4.96 4.91
ResNet_50_v1 16.05 16.07
YOLOv8 24.25 24.91
VIT_Base_Patch16_224 76.68 76.86
SAM2 ENCODER 3900.4 4072.64

AMD

Model OpenCV ONNX Runtime (1.25.1)
MobileNetv2 2.13 3.48
ResNet_50_v1 8.1 6.73
YOLOv8 14.65 21.95
VIT_Base_Patch16_224 27.69 55.4
SAM2 ENCODER 1813.17 2331.81

View complete benchmark tables →


New Geometry module and updated Camera Calibration

All internals have been fully migrated to the C++ API following the removal of the legacy C API. The former calib3d module has been split into geometry, calib and stereo as described above.

  • USAC framework is now the default backend for all robust estimation algorithms: homography, essential and fundamental matrix estimation, PnP solvers and more. Compared to classic RANSAC, USAC delivers significantly better results on noisy datasets thanks to the advanced set of components it puts together into the robust pipelines:

    • flexible sampling strategies (PROSAC, NAPSAC, Progressive-NAPSAC),
    • scoring methods (MSAC, MAGSAC++, LMeds)
    • local optimization (LO-RANSAC, GC-RANSAC)
    • and early termination via SPRT verification.

    Parallel execution across multiple threads is also supported. See the USAC tutorial for details.

  • Multi-view camera calibration pipeline has been added to the calib module. It handles simultaneous calibration of N cameras in three stages: per-camera intrinsics, pairwise extrinsics, and a final global optimization over all cameras. Both pinhole and fisheye models are supported, including mixed rigs. The pipeline accepts checkerboard, ChArUco and circle grid patterns; partial observations — where not all cameras see the full pattern in every frame — are handled correctly, which matters for rigs with limited field-of-view overlap.

    Multi-view calibration setup

    See the multi-view calibration tutorial for a full walkthrough.

  • 3D data processing. Initial support for mesh and point cloud algorithms (TSDF, ICP) has been added, along with importers and exporters for .ply and .obj formats.


Revised samples

  • Many samples have been substantially revised; outdated samples have been removed and new ones added. All deep learning samples use a shared model collection that can be downloaded with:
    cd <opencv>/samples/dnn && python3 download_models.py
    
  • Experimental samples for vision-language models (VLMs) and latent diffusion models (LDM) have been added.

Updated documentation

OpenCV's documentation has been modernized for improved readability and accessibility: a responsive theme with a persistent section-navigation sidebar, an "on this page" table of contents, instant search (Ctrl+K), light/dark mode and cleanly rendered math.

New OpenCV 5.x documentation site

Browse it at docs.opencv.org.


For migration guidance from OpenCV 4.x to 5.x, see Migration Guide.

Clone this wiki locally