Skip to content

Move to OpenCV 5.1; wrap ArUco and more modules - #105

Open
ViralBShah wants to merge 4 commits into
masterfrom
vs/opencv-5
Open

ViralBShah wants to merge 4 commits into
masterfrom
vs/opencv-5

Conversation

@ViralBShah

@ViralBShah ViralBShah commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Moves OpenCV.jl to OpenCV 5.1 (released 2026-11-06) as version 5.0.0, and wraps ArUco/ChArUco (closes #42) along with many more modules.

Needs OpenCV_jll / OpenCV_CUDA_jll 5.1.0 from JuliaPackaging/Yggdrasil#15577, which builds libopencv_julia from this branch's gen/. CI here will fail until those are registered.

What's wrapped

1,679 Julia functions, up from 602.

  • ArUco/ChArUco (OpenCV.aruco): dictionaries, DetectorParameters, ArucoDetector, boards, CharucoDetector, drawing and marker generation.
  • Built but not wrapped before: video (optical flow, trackers), stitching, and the rest of objdetect (QR, barcode, FaceDetectorYN, MCC).
  • New modules: photo, ml, ximgproc, xphoto, tracking, optflow, and xfeatures2d. AKAZE, KAZE, BRISK and Agast moved to xfeatures2d in 5.x.
  • New in 5.1: dnn.Tokenizer (Hugging Face BPE tokenizers), Net KV-cache control, and the XFeat/DISK/ALIKED/LightGlue learned features.

Breaking

  • DNN importers: OpenCV 5 removed the TensorFlow, Caffe, Darknet and Torch importers; only ONNX and TFLite remain. logPolar, linearPolar and convertFp16 are gone too.
  • Module moves: calib3d is split into calib/geometry/stereo, and features2d is renamed features. Functions keep their names; AKAZE and friends are now OpenCV.xfeatures2d.*.
  • Mat type encoding: OpenCV 5 changed it (CV_CN_SHIFT 3 → 5, at most 128 channels). Mats also gain Float16, Bool, UInt32, UInt64 and Int64 element types.

Generator

OpenCV 5 needed generator changes, and several fix bugs that predate 5.x. Details are in gen/PROVENANCE.md:

  • Module table: gen_all.py maps each module to the headers it parses, from both opencv and opencv_contrib. regenerate.jl now fetches contrib too.
  • Default values: every non-literal default resolves. Unmapped defaults used to become () or Int64(), or drop the keyword method altogether.
  • Writable properties: setproperty! now works for CV_PROP_RW fields. It used to cover only the read-only ones, calling setters that don't exist.
  • cv::Ptr classes: classes handed out by cv::Ptr factories (Stitcher, the trackers, ml::TrainData) are now held by Ptr, and Algorithm constructors return cv::Ptr. Factory results and constructed objects now work with every method.
  • Nested types: nested types and namespaced bases resolve.
  • Compiler limit: the C++ module body is split into ~250-line functions. As one function, it made GCC 10 run out of memory.
  • MatShape and small Mats: cv::MatShape is now a class, so the four dnn::Net methods that take it are wrapped by hand. 0-D and 1-D Mats convert correctly.

Testing

All of this was done locally on Linux x86_64 with OpenCV_jll/OpenCV_CUDA_jll 5.1.0 built and deployed from that recipe:

  • Julia 1.13 (CPU): 802 tests pass, 2 skipped (model-heavy learned features).
  • Julia 1.10 (CPU): same result.
  • Julia 1.13 with OpenCV_CUDA_jll: same result, with OpenCV bound to the CUDA build.
  • Doctests and the docs @repl block pass.
  • Regeneration produces identical output across Python hash seeds.

CUDA caveat. OpenCV 5.1's DNN only has the new engine. It runs a graph on the GPU only if every op has a CUDA kernel, and it inserts its own TransformLayout op, which has none. As a result, YuNet and ResNet-50 run entirely on the CPU even with DNN_BACKEND_CUDA; the log says "has no CUDA exec; running the whole graph on CPU". The CUDA build loads, finds CUDA 13 and cuDNN 9.28, and gives identical results, but the ~5× GPU speedup we had with 4.14 is gone. This is an upstream limitation. ENGINE_ORT (ONNX Runtime) could be a later path to GPU inference.

Not covered: macOS, Windows and aarch64 builds; the Yggdrasil CI will be the first to build them. The new modules have smoke tests only.

🤖 Generated with Claude Code

ViralBShah and others added 3 commits November 11, 2026 18:25
OpenCV 5 split calib3d into calib/geometry/stereo, renamed features2d to
features, moved CascadeClassifier/HOGDescriptor and ml to opencv_contrib, and
turned cv::MatShape into a class. Adapt the generator, and fix problems that
predate 5.x:

- gen_all.py maps each module to the headers it parses and searches main and
  contrib module roots; regenerate.jl fetches opencv_contrib too.
- Non-literal defaults get C++ functions evaluated in their namespaces, and the
  Julia side calls them unless defval.txt maps them (unmapped defaults used to
  become `()`/`Int64()` or drop the keyword method).
- Nested types are qualified and their flattened spellings declared; bases
  resolve through enclosing namespaces.
- Classes handed out by cv::Ptr factories are held by Ptr, and constructors of
  Ptr-held classes return cv::Ptr, so both work with every method.
- setproperty! covers CV_PROP_RW fields (it covered the read-only ones).
- The module body is split into ~250-line functions; one function made GCC 10
  run out of memory.
- The dnn::Net methods taking MatShape, and 0-D/1-D Mats, are handled by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wrap ArUco/ChArUco (#42), the rest of objdetect, video, stitching, photo, ml,
ximgproc, xphoto, tracking, optflow and xfeatures2d, plus the API new in 5.1
(dnn Tokenizer and KV cache, XFeat/DISK/ALIKED/LightGlue). Drop APIs removed
in 5.x (TensorFlow/Caffe/Darknet/Torch importers, logPolar, convertFp16).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Mat type encoding: CV_CN_SHIFT 5 and CV_CN_MAX 128; Float16, Bool, UInt32,
  UInt64 and Int64 element types.
- Version 5.0.0, compat OpenCV_jll/OpenCV_CUDA_jll 5.1.
- Tests: YuNet (ONNX) replaces the TensorFlow face detector; new ArUco/ChArUco,
  per-module smoke, tracker, optical flow, QR, tokenizer and Mat round-trip
  tests.
- Docs and README describe OpenCV 5.1 and the wrapped modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The single cv_core.cpp object exceeded the PE/COFF section limit on Windows
("cv_core.cpp.obj: file too big", on both i686 and x86_64 despite -mbig-obj).
Write each registration chunk to its own cv_core_partNN.cpp and compile all
cv_core*.cpp; cv_core.cpp calls the parts in order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Adding the ArUco module

1 participant