Migrate ArUco API to OpenCV 4.7+ detector-class design#1873
Conversation
Replace deprecated free functions (detectMarkers, estimatePoseSingleMarkers, detectCharucoDiamond, interpolateCornersCharuco, detectCharucoBoard) with the new ArucoDetector and CharucoDetector class wrappers. Add CharucoBoard class. Update DetectorParameters struct with minGroupDistance and relativeCornerRefinmentWinSize fields. Add RefineParameters struct. Update tests to use the new API. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… ids is null Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…tor, RefineParameters Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughMigrates ArUco bindings from static OpenCV functions to object-oriented wrappers (ArucoDetector, CharucoBoard, CharucoDetector); adds RefineParameters, extends DetectorParameters, updates C API exports and P/Invoke routing, and expands tests to exercise the new APIs. ChangesArUco API Modernization
Sequence DiagramsequenceDiagram
participant Managed as ArucoDetector
participant PInvoke as NativeMethods
participant CApi as OpenCvSharpExtern
participant OpenCV as cv::aruco
Managed->>PInvoke: aruco_ArucoDetector_create(dictionary, params, refine)
PInvoke->>CApi: aruco_ArucoDetector_create(...)
CApi->>OpenCV: new cv::aruco::ArucoDetector(...)
OpenCV-->>CApi: detector ptr
CApi-->>PInvoke: ptr
PInvoke-->>Managed: native handle
Managed->>PInvoke: aruco_ArucoDetector_detectMarkers(handle,image,...)
PInvoke->>CApi: aruco_ArucoDetector_detectMarkers(...)
CApi->>OpenCV: detector->detectMarkers(...)
OpenCV-->>CApi: corners, ids, rejected
CApi-->>PInvoke: marshaled vectors
PInvoke-->>Managed: results (marshaled to arrays)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/OpenCvSharpExtern/aruco.h`:
- Around line 308-323: The build fails because
aruco_ArucoDetector_refineDetectedMarkers declares recoveredIdxs as
std::vector<int>* but entity() only accepts cv::_InputArray*/cv::_OutputArray*;
change the recoveredIdxs parameter to cv::_OutputArray* (in the
aruco_ArucoDetector_refineDetectedMarkers signature) and update the call to use
entity(recoveredIdxs) (add a null check if other callers may pass nullptr) so
the call becomes detector->refineDetectedMarkers(..., entity(cameraMatrix),
entity(distCoeffs), entity(recoveredIdxs)).
- Around line 262-272: In aruco_drawDetectedCornersCharuco the ternary mixes
cv::_InputArray and cv::_InputOutputArray causing a type error; change the
idArray declaration to consistently use cv::_InputArray like in
aruco_drawDetectedDiamonds, e.g. construct idArray as cv::_InputArray idArray =
(ids != nullptr) ? cv::_InputArray(*ids) : cv::_InputArray(cv::noArray()); so
the ternary returns the same type before calling
cv::aruco::drawDetectedCornersCharuco.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 72feac1b-57d8-478f-a5c8-403902a61ae1
📒 Files selected for processing (10)
src/OpenCvSharp/Internal/PInvoke/NativeMethods/NativeMethods_aruco.cssrc/OpenCvSharp/Modules/aruco/ArucoDetector.cssrc/OpenCvSharp/Modules/aruco/CharucoBoard.cssrc/OpenCvSharp/Modules/aruco/CharucoDetector.cssrc/OpenCvSharp/Modules/aruco/CvAruco.cssrc/OpenCvSharp/Modules/aruco/DetectorParameters.cssrc/OpenCvSharp/Modules/aruco/RefineParameters.cssrc/OpenCvSharpExtern/aruco.htest/OpenCvSharp.Tests/aruco/ArucoTest.cstest/OpenCvSharp.Tests/system/ExceptionTest.cs
- aruco_drawDetectedCornersCharuco: avoid ternary between _InputArray and _InputOutputArray (noArray()); use if-assignment instead - aruco_ArucoDetector_refineDetectedMarkers: entity() does not accept std::vector<int>*; use _OutputArray + if-assignment for recoveredIdxs Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Summary
detectMarkers,estimatePoseSingleMarkers,detectCharucoDiamond,detectCharucoBoard,interpolateCornersCharuco) that no longer exist as non-deprecated API since OpenCV 4.7ArucoDetectorclass wrappingcv::aruco::ArucoDetectorCharucoBoardclass wrappingcv::aruco::CharucoBoardCharucoDetectorclass wrappingcv::aruco::CharucoDetectorRefineParametersstruct wrappingcv::aruco::RefineParametersDetectorParameterswith two new fields:MinGroupDistanceandRelativeCornerRefinmentWinSizearuco_drawDetectedCornersCharucowhenidsis nullBreaking changes
This PR intentionally breaks the existing C# API to align with OpenCV's own breaking change introduced in 4.7.
CvAruco.DetectMarkers(...)new ArucoDetector(dict).DetectMarkers(...)CvAruco.EstimatePoseSingleMarkers(...)Board.MatchImagePoints+Cv2.SolvePnPCvAruco.DetectCharucoDiamond(...)new CharucoDetector(board).DetectDiamonds(...)CvAruco.DetectCharucoBoard(...)new CharucoDetector(board).DetectBoard(...)CvAruco.InterpolateCornersCharuco(...)new CharucoDetector(board).DetectBoard(...)Test plan
ArucoDetector: create (default / custom params),DetectMarkerson real image, disposeCharucoBoard: create, properties,LegacyPattern,GenerateImage,CheckCharucoCornersCollinear, disposeCharucoDetector: create,DetectBoardon generated image, empty image, disposeRefineParameters: default and custom constructorsDetectorParameters: new fields verifiedDrawDetectedCornersCharucowith and without idsCloses #1796
Summary by CodeRabbit
New Features
Improvements
Tests