Skip to content

Add DNN engine selection (EngineType) and sync Backend/Target enums - #1925

Merged
shimat merged 1 commit into
5.xfrom
feature/dnn-engine-selection
Jun 24, 2026
Merged

shimat merged 1 commit into
5.xfrom
feature/dnn-engine-selection

Conversation

@shimat

@shimat shimat commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Summary

First item from #1924 (OpenCV 5 API coverage): expose DNN inference engine selection and re-sync the Backend / Target enums with OpenCV 5.

Engine selection

  • New EngineType enum (Classic=1 / New=2 / Auto=3 / Ort=4), matching cv::dnn::EngineType.
  • Added an EngineType engine = EngineType.Auto parameter to the read APIs on Net and CvDnn: ReadNet, ReadNetFromONNX, ReadNetFromTensorflow, ReadNetFromTFLite (string / byte[] / ReadOnlySpan<byte> / Stream overloads).
  • Native bridge (dnn.h) and P/Invoke signatures threaded through the int engine argument. The string-path ONNX/TFLite calls are wrapped in cv::String(...) to disambiguate from the (const char*, size_t, int) buffer overloads.

Backend / Target enum sync

  • Backend: added WEBNN / TIMVX / CANN. HALIDE was removed in OpenCV 5; its value 1 is kept as a gap (marked [Obsolete]) so the remaining members keep their OpenCV-matching numeric values.
  • Target: added NPU / CPU_FP16.

Test

  • New EngineSelectionTest: verifies the enum numeric values match OpenCV 5 and that ReadNetFromTensorflow loads the committed MNIST model with Classic and Auto engines.
  • Rebuilt OpenCvSharpExtern locally; full dnn suite green (45 passed, 4 network-dependent skips).

Refs #1924.

🤖 Generated with Claude Code

OpenCV 5 lets readNet* pick an inference engine via an `int engine`
parameter (EngineType: Classic/New/Auto/Ort). Expose it through the
native bridge and the managed Net / CvDnn read APIs, defaulting to Auto.

Also re-sync the Backend and Target enums with OpenCV 5: add Backend
WEBNN/TIMVX/CANN (Halide removed but its value 1 kept as a gap so the
remaining values stay correct) and Target NPU/CPU_FP16.

Refs #1924.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shimat shimat self-assigned this Jun 24, 2026
@shimat
shimat merged commit d17ea2e into 5.x Jun 24, 2026
11 checks passed
@shimat
shimat deleted the feature/dnn-engine-selection branch June 24, 2026 07:31
@shimat shimat added the enhancement New feature or improvement to OpenCvSharp label Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or improvement to OpenCvSharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant