Clone
3
OpenCV 5.1
Om Navin Rope edited this page 2026-11-24 13:39:13 +05:30

This page describes new features and other notable changes in OpenCV 5.1, the first feature update of the 5.x series, released in November 2026.

The complete list of changes, with a link to every pull request, is in the change log.


What changed from 5.0 to 5.1

OpenCV 5.1 completes the transition of the DNN module to the new engine: the classic engine has been removed, and the new engine runs on NVIDIA GPUs as well as on CPU. The core module adds a broadcasting element-wise engine and a complete set of N-D array operations, text rendering supports complex scripts, and new 3D functionality ranges from an OpenGL visualizer to monocular visual odometry.

Most code written for 5.0 builds and runs on 5.1 unchanged. The exceptions are listed under Cleanup and in the "Migration notes" part of the change log.


Release highlights

General changes

  • One DNN engine, on CPU and GPU. ONNX and TFLite models are loaded by the new engine, which now has a CUDA backend. See Updated DNN module.
  • Consistent saturation. cvRound, cvFloor, cvCeil and saturate_cast now saturate out-of-range values on every platform. Previously the result depended on the CPU: x86 returned INT_MIN, while 64-bit ARM and RISC-V wrapped around. 32-bit integer add and subtract saturate as well.
  • IPP moved into HAL. Intel IPP calls in imgproc and in core math functions now go through the HAL interface, the same way other vendor libraries plug into OpenCV. cv::ipp::useIPP() switches all of them on and off at runtime.
  • More functions accept CV_Bool: distanceTransform, connectedComponents, morphological operations, matchTemplate masks, SIFT masks, inpaint masks, boundingRect, findTransformECC masks and imwrite.
  • Behavior changes:
    • Net::forward() keeps the output type of the model. Models that declare FP16 or BF16 outputs now return FP16 or BF16 Mats; the high-level Model classes still return float.
    • cv::bitwise_not and operator~ now invert CV_Bool arrays element by element, so true becomes false and false becomes true. Previously they flipped every bit of each byte, which turned all elements into true.
    • In Python, an int64 NumPy array becomes CV_32S only when all its values fit into int32; otherwise it becomes CV_64S. Previously it was always truncated to CV_32S.
    • In Python, a Mat with a zero-length dimension comes back as an empty array of that shape instead of None.
    • WITH_UNIFONT is now OFF by default, so the CJK font is no longer built in. See Updated Imgproc module.
  • Third-party updates: IPP 2026.1.0, KleidiCV 26.09, libtiff 4.7.2, and FFmpeg 9.0.2 in the Windows build.

Cleanup

  • The classic DNN engine has been removed. cv::dnn::EngineType now has three values: ENGINE_AUTO (0, default), ENGINE_OPENCV (1) and ENGINE_ORT (2). Code that passes ENGINE_CLASSIC or ENGINE_NEW has to switch to one of these. The numbers changed too, so if you set OPENCV_FORCE_DNN_ENGINE in your environment, check it: 1 now selects the OpenCV engine and 2 selects ONNX Runtime.
  • The TensorFlow importer has been removed. readNetFromTensorflow() is gone; convert TensorFlow models to ONNX, for example with tf2onnx. ONNX and TFLite remain supported. The dnn_superres module in opencv_contrib now loads ONNX models only. Leftover Caffe protobuf code was removed as well.
  • Core API. The Mat_ << a, b, c comma initializer has been removed, and transposeND is deprecated in favor of the N-D cv::transpose.
  • Calibration flags. CALIB_DISABLE_SCHUR_COMPLEMENT has a new value, because the old one collided with CALIB_TILTED_MODEL. Numeric fisheye flag values saved by 4.x are now rejected with an error.
  • Headers. Public geometry headers no longer include logger.hpp.

Updated Core module

  • Broadcasting element-wise engine. Arithmetic, comparison and math functions broadcast operands NumPy-style, for mismatched shapes as well as channel counts. The new cv::texpr evaluates an element-wise expression written as a string, for example cv.texpr("clamp({0} - {1}, 0, 10)", [a, b]), in one fused pass, so intermediate results stay in cache instead of being stored as temporary matrices. The DNN element-wise layers run on the same engine.

  • FP8 data types. Two FP8 depths were added, CV_8F_E4M3FN and CV_8F_E4M3FNUZ, with SIMD conversions and support in common core functions such as split/merge, LUT, norm, minMaxLoc, countNonZero and FileStorage.

  • N-D array API. cv::concat, cv::split, cv::slice, cv::repeat, cv::reshape and cv::transpose (with an arbitrary axis order) work on N-dimensional arrays, and cv::squeeze, cv::unsqueeze and cv::flatten were added. cv::reduce works on N-D arrays through ReduceParams and gained REDUCE_PROD, REDUCE_L1, REDUCE_L2, REDUCE_LOG_SUM and REDUCE_LOG_SUM_EXP.

  • CUDA-backed UMat. cv::cuda::getCudaAllocator() gives UMat a CUDA memory allocator with explicit host-device transfers.

  • Performance.

    • DFT and DCT were rewritten with universal intrinsics and parallelized, and matchTemplate was parallelized too.
    • norm, batchDistance and Hamming distance are vectorized, which speeds up ORB and BRISK matching.
    • findNonZero on 8-bit input is up to 15x faster on sparse masks.
    • sum, minMaxLoc and countNonZero have AVX-512 paths, and sort runs in parallel.

Updated Imgproc module

  • Text rendering based on HarfBuzz. Text is now shaped with HarfBuzz, so scripts that need complex shaping, such as Arabic and Devanagari, render correctly and font ligatures work. To keep the library small, only the Rubik font is built in by default. The italic and CJK fonts are optional (WITH_ITALICFONT, WITH_UNIFONT), and cv::FontFace::setBuiltinFont can load them from a font file at runtime.

  • cv::alphaComposite blends images with the Porter-Duff compositing operators.

  • Oklab color space. cvtColor converts between RGB/BGR and Oklab.

  • IPP through HAL. resize, cvtColor, boxFilter, filter2D, Sobel, Scharr, Canny, distanceTransform, matchTemplate, threshold, bilateralFilter and getRectSubPix reach IPP through the HAL interface instead of calling it directly.

  • Faster on platforms without IPP, such as Windows on ARM: the Laplacian column filter, pyrUp, pyrDown, adaptiveThreshold, calcHist, boxFilter and blur have new vectorized code paths.


Updated DNN module

  • CUDA backend. In 5.0 the new engine was CPU-only; in 5.1 it also runs on NVIDIA GPUs. The CUDA backend executes the graph layer by layer on UMat device buffers, covers transformer layers and can replay the whole network as a CUDA Graph. cuDNN's graph API with runtime-compiled kernels is available through the WITH_CUDNNJIT CMake option. ResNet-50 runs in 0.80 ms on an RTX PRO 6000 Blackwell (FP32 with TF32), against 0.88 ms for the ONNX Runtime 1.31 CUDA execution provider.

  • ONNX coverage. New layers include Scan, LpPool, CumProd, CausalConvWithState, BitCast, inverse real DFT, ImageDecoder and Compress. Many existing ones, including Resize, GridSample, GRU, LSTM, Attention, PRelu and Softmax, were fixed or extended to follow the specification.

  • Better LLM and VLM support.

    • Net::reserveKVCache() pre-allocates the attention KV cache, which makes token generation up to 4.95x faster.
    • Attention gained past/present KV cache inputs, LinearAttention and FlexAttention were added, and GroupQueryAttention supports rotary embeddings, which Granite-Docling and PaddleOCR-VL need.
    • cv::dnn::Tokenizer supports the WordPiece and Unigram methods, which adds BERT and ALBERT tokenization.
    • Quantized models: com.microsoft MatMulNBits, DynamicQuantizeLinear, ConvInteger and MatMulInteger. Cast and CastLike support FP8, FP4, INT4/UINT4 and E8M0, and FP8 models can be loaded.
    • External weights are memory-mapped instead of copied, which reduces memory use when loading large ONNX models.
  • Faster CPU inference. A few representative numbers:

    • Graph fusion was rewritten into one backend-agnostic pass: MPHand is 2.27x faster, EfficientNet 1.96x.
    • More operations stay in the blocked memory layout: RAFT 1.40x, DenseNet121 1.44x faster.
    • Convolution work is split between threads according to its size: MPPose 1.64x, MPPalm 1.45x, YuNet 1.33x faster.
    • LSTM was reworked: CRNN went from 17.5 ms to 2.8 ms.
    • ConvTranspose now uses MLAS GEMM: the SAM2 decoder went from 68.5 ms to 36.8 ms on one thread.
    • int8 inference: DenseNet121 int8 is 7.4x faster, with AVX-VNNI depthwise convolution and multi-threaded MatMul.
  • Other changes.

    • The TFLite importer runs more models on the new engine, including YOLO.
    • blobFromImage, blobFromImages and Image2BlobParams take an interpolation parameter; pass INTER_LINEAR_EXACT for bit-exact preprocessing.

Performance

The numbers below are inference time in milliseconds (lower is better). ONNX Runtime (1.31.0) is the official Python package with the CPU execution provider. Both runtimes use all logical CPUs of the machine. A representative selection is shown here; see the complete benchmark tables for every model, the test setup and output checks.

Intel i9

Model OpenCV ONNX Runtime (1.31.0)
MobileNetv2 1.24 1.16
ResNet_50_v1 7.13 14.69
YOLOv8 10.00 24.43
VIT_Base_Patch16_224 32.61 43.18
SAM2 ENCODER 1693 2308

Intel i7

Model OpenCV ONNX Runtime (1.31.0)
MobileNetv2 3.66 2.21
ResNet_50_v1 18.60 17.43
YOLOv8 25.42 24.76
VIT_Base_Patch16_224 74.25 73.94
SAM2 ENCODER 5158 6070

Apple M5

Model OpenCV ONNX Runtime (1.31.0)
MobileNetv2 4.74 4.54
ResNet_50_v1 20.76 35.16
YOLOv8 24.36 43.03
VIT_Base_Patch16_224 83.44 86.29
SAM2 ENCODER 5780 4243

AMD Ryzen 9 9950X

Model OpenCV ONNX Runtime (1.31.0)
MobileNetv2 2.15 1.73
ResNet_50_v1 7.94 6.41
YOLOv8 12.06 15.09
VIT_Base_Patch16_224 23.15 25.86
SAM2 ENCODER 1523 2200

View complete benchmark tables →


Updated Features module

  • cv::XFeat, a DNN-based feature detector and descriptor.
  • SIFT on OpenCL. SIFT detection and description on UMat input run on OpenCL, up to 1.87x faster than the CPU path at 1080p.
  • LightGlue with DISK. LightGlueMatcher works with DISK features (LG_DISK) as well as ALIKED, and setKeypointNormalization() with LG_NORM_MAX_SIDE matches the keypoint normalization of the reference LightGlue implementation.

Updated Calibration and Geometry modules

  • calibrateHandEye and calibrateRobotWorldHandEye are available from Python.
  • calibrateCamera, stereoCalibrate, initCameraMatrix2D and registerCameras accept float64 points.
  • The Schur complement calibration solver is now deterministic and 1.45x faster with 32 threads.
  • Fisheye extrinsic refinement uses Levenberg-Marquardt and handles ill-conditioned views better.

Updated Video I/O and Image codecs

  • Camera enumeration. cv::videoio_registry::enumerateDevices() lists the cameras that the V4L2, MSMF, DirectShow, AVFoundation and Aravis backends can open, and the new opencv_camera_enumerate tool prints the list from the command line.
  • Encoder controls in VideoWriter. With the FFmpeg and GStreamer backends you can set bitrate, CRF, preset, GOP size and pixel format.
  • FFmpeg 9.0 is supported, and the Windows FFmpeg build was updated to 9.0.2, which also fixes slow AV1 decoding.
  • AVIF and TIFF. 16-bit AVIF images can be read and written (libavif 1.4.0 or newer), and the AVIF alpha plane has its own quality setting (IMWRITE_AVIF_ALPHA_QUALITY). IMWRITE_TIFF_COMPRESSION_LEVEL sets the compression level for DEFLATE, LZMA, ZSTD and WebP compression in TIFF.

Updated Python bindings

  • Exact NumPy dtypes for bfloat16 and float8. By default, CV_16BF and FP8 outputs reach Python as float32 arrays. After import ml_dtypes and cv.setUseExactNumpyDtypes(True), they keep their exact bfloat16 and float8 dtypes.
  • Typing stubs are more accurate for optional outputs, scalar operands and NumPy input to UMat.

Platform support

  • Windows on ARM.
    • parallel_for_ no longer skips work with the default PPL backend, so building with OpenMP is no longer needed as a workaround.
    • An ArmPL HAL backend accelerates gemm, SVD and invert.
    • The vendored MLAS library is used by DNN with MSVC, and OpenCV can be built with clang-cl together with the KleidiCV HAL.
  • RISC-V. RVV code paths were added across core, imgproc, video and DNN: convolution (including Winograd), GEMM, int8 convolution, normalization layers, optical flow and more.

New in OpenCV 5.1

  • Linear assignment solver. cv::linearAssignment() solves rectangular assignment problems with the Jonker-Volgenant algorithm, for example matching tracks to detections in a multi-object tracker.
  • 3D visualizer. cv::viz3d is a new OpenGL-based viewer for meshes, point clouds, RGB-D frames and camera trajectories.
  • 3D Gaussian Splatting. cv::loadGaussianSplats loads splat scenes, and viz3d renders them.
  • Monocular visual odometry. cv::slam::VisualOdometry is the first step toward SLAM in OpenCV.
  • Point cloud processing: statistical and radius outlier removal, normal orientation, Ball-Pivoting meshing and 3D bounding boxes.
  • ColorHashTSDF, a TSDF volume type that combines hashed storage with color.

Revised samples

  • The object detection samples use a Darknet-converted ONNX model for YOLOv3, which gives better results.
  • A new Qwen3-TTS text-to-speech sample, in C++ and Python, shows the new MatMulNBits support.
  • The Python HoughLines/HoughLinesP and odometry samples were updated for 5.x, and the OpenGL samples were fixed to build again.

Updated documentation

  • New tutorials cover using pre-built binaries and convex hull, new pages describe the HAL and the DNN engine, and the universal intrinsics tutorial was extended.
  • The core documentation explains the bit layout of Mat::type() and the 1D Mat vector constructor, and has a module introduction for 5.1.

The full list of changes is in the change log. For migration from OpenCV 4.x, see the Migration Guide.