Skip to content

Add a cv::dnn binding (Net class: readNet / setInput / forward)#102

Open
TroyHernandez wants to merge 1 commit into
swarm-lab:developfrom
cornball-ai:dnn-binding
Open

Add a cv::dnn binding (Net class: readNet / setInput / forward)#102
TroyHernandez wants to merge 1 commit into
swarm-lab:developfrom
cornball-ai:dnn-binding

Conversation

@TroyHernandez

Copy link
Copy Markdown

Adds a binding for OpenCV's dnn module, as discussed in #101 (PR 1 of 2: dnn first, YuNet face detection to follow).

What

A Net class wrapping cv::dnn::Net:

  • readNet(model, config = "", framework = "") loads a model (ONNX, Caffe, TF, Darknet, ...).
  • net$setInput(image, scalefactor, size, mean, swapRB, crop, name) preprocesses an Image via blobFromImage and sets it as input.
  • net$forward(name) runs a forward pass and returns the output tensor as a numeric array, with OpenCV's row-major layout converted to a correctly-shaped column-major R array of arbitrary dimensionality.
  • net$getLayerNames(), net$empty(), and an isNet() helper round it out.

Notes

  • No build change. dnn is already in ROpenCVLite's default module list, so this compiles against what's already there (no BUILD_LIST change, no contrib module, no new system dependency).
  • Follows the existing conventions: one header per module (src/dnn.h), an RCPP_MODULE, and an R wrapper (R/dnn.R), mirroring the Image/Video classes.
  • Tested locally against OpenCV 4.13: loads ONNX and TFLite models, runs forward, and returns correctly-shaped arrays.

Targets develop. Happy to adjust the API/conventions however you prefer.

🤖 Generated with Claude Code

Exposes OpenCV's dnn module through a Net class: readNet() loads a model
(ONNX, Caffe, TF, etc.), setInput() preprocesses an Image with blobFromImage,
and forward() runs inference. Output tensors are converted from OpenCV's
row-major layout to correctly-shaped column-major R arrays of arbitrary
dimensionality. No build-list change (dnn is already compiled).

Refs swarm-lab#101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant