OpenCV 4 vs 5: What Changed in 2026
OpenCV 5 isn't a feature update — it's a rearchitecture. The DNN module gets a ground-up rewrite (22% → 80%+ ONNX coverage), LLM/VLM inference ships built-in, and the C API is finally gone. But GPU users should stay on OpenCV 4 for now — the new engine is CPU-only.
Side-by-Side Comparison
| Dimension | OpenCV 4 | OpenCV 5 |
|---|---|---|
| DNN Engine | Classic engine — 22% ONNX coverage, no dynamic shapes, opaque errors | New graph-based engine — 80%+ ONNX coverage, shape inference, attention fusion NEW |
| GPU / CUDA | Supported — CUDA, OpenVINO, OpenCL backends | Classic engine still supports GPU ENGINE_CLASSIC; new engine CPU-only (GPU "coming later") |
| LLM / VLM | Not supported — need PyTorch + ONNX Runtime + separate tokenizer | Native support — VLM inference sample ships with the library NEW |
| Python Bindings | Positional arguments — cv2.resize(img, dsize, fx, fy, interpolation) |
Named arguments — cv2.resize(img, dsize=(640,480), interpolation=cv2.INTER_LINEAR) NEW |
| C API | Available — CvMat, IplImage |
Removed — must use C++ API; C++17 required |
| DNN Model Support | ONNX, Caffe, Darknet, TensorFlow, Torch | ONNX only — Caffe, Darknet, TF, Torch parsers removed; convert to ONNX first |
| Module Structure | calib3d, features2d, objdetect, ml, gapi — all in main | calib3d → geometry+calib+stereo+ptcloud; features2d → features; Haar/HOG/ML/G-API → opencv_contrib |
| Data Types | CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F | All of v4's types + CV_16BF (bfloat16), CV_32U, CV_64U, CV_64S, CV_Bool NEW |
| RANSAC Default | Classic RANSAC | USAC (Universal SAC) — better results on noisy data; default for all RANSAC-based algorithms |
| Image Warping | Standard performance | 10–300% faster — warpAffine, warpPerspective, remap; NN resize matches Pillow exactly |
| Documentation | Static, hard to navigate | Responsive theme, Ctrl+K search, light/dark mode, cleaner math rendering |
| DNN Performance (vs ONNX Runtime) | Generally slower than ORT | Competitive — 11–31% faster on some models, slightly behind on others. Self-reported benchmarks — no third-party verification yet. |
| C++ Standard | C++11 minimum | C++17 required — affects custom build systems and embedded toolchains |
DNN Engine: The Real Difference
OpenCV 4 DNN — Coin Flip (frustrating)
Export to ONNX, point cv2.dnn.readNet() at it, and hope. 78% of ONNX operators were unsupported. Dynamic shapes broke everything. Error messages were opaque. Developers on HN have been complaining about this for years — one commenter reported rewriting OpenCV inference code into hand-rolled kernels and getting 5x performance.
OpenCV 5 DNN — Graph Engine (modernized)
New graph-based engine with shape inference, operator fusion, and FlashAttention-style attention fusion. ONNX operator coverage jumps from 22% to 80%+. Dynamic shapes and variable batch sizes work correctly. The engine defaults to ENGINE_AUTO — tries new engine first, falls back to classic silently. But it's CPU-only, and the 2.3x YOLOv8 headline is self-reported with no independent verification.
Migration Difficulty by Scenario
| Scenario | 4 → 5 Effort | Key Actions |
|---|---|---|
| Python, classical CV only | Minimal — 5 minutes | pip install opencv-python>=5.0.0, re-run tests |
| Python, DNN on CPU | Low — 15 minutes | Re-test models; old ONNX models auto-fallback to classic engine |
| Python, DNN on GPU | Skip for now — wait | Pin ENGINE_CLASSIC; no benefit from upgrading yet |
| C++, basic usage | Medium — 1 hour | Update includes, C++17 flag, test new data types in switch statements |
| C++, with contrib modules | Medium — 2 hours | Rebuild with opencv_contrib; migrate Haar→FaceDetectorYN; ML→scikit-learn |
| Legacy C code | High — rewrite | C API fully removed; port to C++ or use Python bindings |
| Darknet/Caffe models | Medium — convert | Convert to ONNX first; no more direct parsers in v5 |
Decision Guide
Stay on OpenCV 4 if...
- You rely on GPU inference (CUDA/OpenVINO) — the new DNN engine is CPU-only with no timeline
- Your production pipeline uses Darknet or Caffe models directly — parsers are gone in v5
- You have legacy C code — the C API was fully removed; porting is a real project
- You're in the middle of a critical release — don't change CV libraries mid-sprint
Upgrade to OpenCV 5 now if...
- You do DNN inference on CPU — the new engine is a genuine improvement, old models auto-fallback
- You want LLM/VLM inference without PyTorch — native support eliminates dependency bloat
- You value modern Python ergonomics — named arguments, better docs, cleaner API
- You're starting a new project — no reason to start on v4 in mid-2026
Upgrade later (but prepare now) if...
- You use contrib modules (cv2.ml, Haar, SURF, G-API) — test the migration path first
- Your C++ code has type switches on Mat depth — new data types need new cases
- You publish native addons — C++17 requirement may break older toolchains
FAQ
Is OpenCV 5 faster than OpenCV 4?
It depends on what you measure. The new DNN engine is 11–31% faster than ONNX Runtime on some models (YOLOv8n, XFeat, DINOv2) but slightly behind on others. Image warping (warpAffine, warpPerspective, remap) is 10–300% faster. Contour finding (findContours) is faster via the new TRUCO algorithm. But these are all self-reported benchmarks — no independent third-party verification yet. Classical CV operations (imread, cvtColor, threshold) should perform identically.
Will OpenCV 5 support GPU/CUDA for the new DNN engine?
Yes, "in subsequent releases" — but the OpenCV team has not committed to a specific version or date. The classic engine still supports CUDA and OpenVINO in v5, so GPU inference is unchanged. The new engine's CPU-only status is the biggest reason many production users are waiting.
Can I install OpenCV 5 and OpenCV 4 side by side?
In Python: not easily via pip. pip install opencv-python==4.10.0 and pip install opencv-python>=5.0.0 will conflict. Use separate conda environments or Docker containers. In C++: use different install prefixes (-DCMAKE_INSTALL_PREFIX=/usr/local/opencv4 and /usr/local/opencv5) and set CMAKE_PREFIX_PATH accordingly.
What about opencv-contrib-python? Does it work with v5?
Yes — pip install opencv-contrib-python>=5.0.0. But some modules that were in main v4 moved to contrib in v5 (cv2.ml, Haar cascades, HOG, SURF, G-API). If you were installing opencv-python before and using these, you'll need to switch to opencv-contrib-python.
How long should I wait before upgrading?
For CPU-based Python developers: now. The API is backward-compatible and the DNN engine is a genuine upgrade. For GPU users: wait for GPU support in the new engine (no timeline). For large C++ codebases: budget 1–2 hours for the migration, then upgrade. For legacy C code users: start planning the C++ port now; the C API isn't coming back.