OpenCV 5 drops June 8th (pip version) with a DNN engine rewrite that jumps ONNX operator coverage from ~22% to over 80%. The new graph-based engine understands dynamic shapes, fuses attention patterns, and runs LLMs like Qwen 2.5 directly inside the library.

Three Engines, One API

OpenCV 5 keeps the old engine for backward compatibility. You pick at load time via the EngineType enum:

import cv2 as cv
# Default: new engine first, fallback to classic
net = cv.dnn.readNetFromONNX("model.onnx")
# Force new engine
net = cv.dnn.readNetFromONNX("model.onnx", engine=cv.dnn.ENGINE_NEW)

The classic engine (ENGINE_CLASSIC) supports non-CPU backends like CUDA and OpenVINO. The new engine (ENGINE_NEW) runs on CPU only for now but delivers fusions like FlashAttention-style attention collapsing. ENGINE_ORT wraps ONNX Runtime if built with WITH_ONNXRUNTIME=ON.

Speed Benchmarks

On an Intel Core i9-14900KS (Ubuntu 24.04), OpenCV 5's new engine beats ONNX Runtime on several models:

ModelOpenCV 5 DNN (ms)ONNX Runtime (ms)Difference
XFeat6.568.6131.25% faster
YOLOv8n10.912.1511.5% faster
YOLOX-S23.4625.167.24% faster
DINOv2 small23.7829.5824.4% faster
RF-DETR102.01106.494.4% faster
OWLv21,0901,48936.6% faster
BiRefNet7,1789,50332.4% faster

LLMs and VLMs Inside OpenCV

OpenCV 5 ships a native tokenizer and KV-cache for autoregressive decoding. Models like Qwen 2.5, Gemma 3, PaliGemma, and GPT-2/4 run through the same Net API as YOLO. In tests, Qwen 2.5 output matched ONNX Runtime token-for-token.

Other Improvements

  • Core modernization: Retired legacy C API, added native FP16/BF16, proper 0D/1D tensors, and real logging.
  • Hardware acceleration: Cleaner layer for vendor-specific kernels.
  • 3D vision: ChArUco boards, multi-camera calibration, and better visualization.
  • Documentation: Completely revamped, easier to navigate.
  • Models validated: YOLOv8, YOLOv9, YOLOv10, DINOv2, SAM, CLIP, RT-DETR, LaMa inpainting, and more.

What's Next

GPU support in the new DNN engine and a non-CPU HAL for accelerated pre/post-processing are planned. The OpenCV team invites community testing and contributions.

Get the pip version on June 8th. For now, build from the GitHub master branch.