Skip to content

Normalize cvTry lambda body indentation across OpenCvSharpExtern - #2003

Merged
shimat merged 7 commits into
mainfrom
fix/cvtry-indentation-2002
Jul 5, 2026
Merged

Normalize cvTry lambda body indentation across OpenCvSharpExtern#2003
shimat merged 7 commits into
mainfrom
fix/cvtry-indentation-2002

Conversation

@shimat

@shimat shimat commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Closes OpenCvSharpExtern: cvTry([&] { ... }) lambda body indentation is inconsistent #2002. Indents the body of every multi-line cvTry([&] { ... }); block one level deeper than the enclosing return statement, across all of src/OpenCvSharpExtern. Roughly half of the ~2900 multi-line blocks already followed this convention (see the fix applied to the newly-added geometry.h code in Add missing OpenCV 5 geometry APIs; fix stale readNet doc #2000); the rest had accumulated at the same indentation as return cvTry( over time, presumably added by different contributors/scripts without a consistent formatter for this specific pattern.
  • #ifdef/#else/#endif lines inside a block are left at column 0, matching this codebase's existing convention of always putting preprocessor directives at column 0 regardless of the surrounding C++ indentation.
  • Pure whitespace change - no behavior, ABI, or API difference. 108 files, all insertions/deletions balanced (4347/4347).

Test plan

  • Native build: cmake --build src/build --config Release --target OpenCvSharpExtern succeeds with no errors (only pre-existing, unrelated code-page warnings).
  • Managed build: dotnet build test/OpenCvSharp.Tests/OpenCvSharp.Tests.csproj -c Release succeeds, 0 warnings/errors.
  • Full test suite: dotnet test test/OpenCvSharp.Tests/OpenCvSharp.Tests.csproj -c Release --no-build - 1259 passed, 0 failed, 27 skipped (pre-existing, environment-dependent).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Standardized formatting and indentation across a wide range of vision, image processing, machine learning, and DNN wrapper APIs to improve readability and consistency, without changing public APIs or expected behavior.
  • Bug Fixes

    • Improved HOGDescriptor model saving by refining how the optional output name is converted/handled, resulting in more consistent filename/object-name processing.

…tern

Indent the body of every multi-line cvTry([&] { ... }); block one
level deeper than the enclosing return statement, across all of
OpenCvSharpExtern. About half of the ~2900 multi-line blocks already
followed this convention; the rest had accumulated at the same
indentation as the return statement over time. Preprocessor directives
(#ifdef/#else/#endif) inside a block are left at column 0, matching
this codebase's existing convention for them. Pure whitespace change,
no behavior difference.

Follow-up to #2000's ad hoc fix of this in geometry.h; see #2002.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@shimat shimat self-assigned this Jul 5, 2026
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The pull request reformats wrapper implementations across many src/OpenCvSharpExtern headers. It normalizes cvTry lambda bodies, call wrapping, and indentation, while preserving wrapper signatures and observable OpenCV call behavior. A few localized logic changes remain in the same wrapper areas.

Changes

Core and calibration wrappers

Layer / File(s) Summary
Core and calibration wrappers
src/OpenCvSharpExtern/barcode.h, src/OpenCvSharpExtern/bgsegm.h, src/OpenCvSharpExtern/calib*.h, src/OpenCvSharpExtern/core*.h
Most changes in these headers reformat cvTry bodies, wrap long calls, and standardize statement layout across core, calibration, file, array, matrix, and storage wrappers.

DNN, features, flann, img_hash, geometry

Layer / File(s) Summary
DNN, features, flann, img_hash, geometry
src/OpenCvSharpExtern/dnn*.h, src/OpenCvSharpExtern/features*.h, src/OpenCvSharpExtern/flann*.h, src/OpenCvSharpExtern/img_hash.h, src/OpenCvSharpExtern/geometry.h
These wrapper headers were reformatted across model loading, feature detectors/matchers, FLANN index helpers, image hash APIs, and geometry routines, with a few explicit conversion and temporary-variable updates in the same call paths.

HighGUI and imgproc family

Layer / File(s) Summary
HighGUI and imgproc family
src/OpenCvSharpExtern/highgui.h, src/OpenCvSharpExtern/imgcodecs.h, src/OpenCvSharpExtern/imgproc*.h, src/OpenCvSharpExtern/line_descriptor.h
HighGUI, image codec, imgproc, CLAHE, font face, generalized Hough, line iterator, line segment detector, segmentation, Subdiv2D, undistort, and line descriptor wrappers were reformatted; line_descriptor_LSDDetector_detect2 also changes its multi-image/mask sizing flow.

ML, objdetect, optflow, and photo wrappers

Layer / File(s) Summary
ML, objdetect, optflow, and photo wrappers
src/OpenCvSharpExtern/ml*.h, src/OpenCvSharpExtern/objdetect*.h, src/OpenCvSharpExtern/optflow*.h, src/OpenCvSharpExtern/photo*.h
ML model wrappers, objdetect wrappers, optical-flow wrappers, and photo/HDR/tonemap wrappers were reformatted across their lambda bodies and call sites; objdetect_HOGDescriptor_save changes objName handling from std::string to cv::String when non-null.

Ptcloud, saliency, shape, stereo, and stitching wrappers

Layer / File(s) Summary
Ptcloud, saliency, shape, stereo, and stitching wrappers
src/OpenCvSharpExtern/ptcloud*.h, src/OpenCvSharpExtern/saliency*.h, src/OpenCvSharpExtern/quality.h, src/OpenCvSharpExtern/shape*.h, src/OpenCvSharpExtern/stereo*.h, src/OpenCvSharpExtern/stitching*.h
Point-cloud, saliency, quality, shape, stereo, and stitching wrappers were reformatted throughout their cvTry blocks, with the same object lifecycle, conversion, and output-population behavior preserved.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • shimat/opencvsharp#1828 — Touches the same objdetect_FaceDetectorYN_* wrapper implementations that are reformatted here.
  • shimat/opencvsharp#1832 — Overlaps with the same FaceDetectorYN native binding wrappers updated in this PR.
  • shimat/opencvsharp#1996 — Touches the same line_descriptor_LSDDetector_detect2 wrapper and its mask/image sizing logic.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the whitespace-only indentation normalization across OpenCvSharpExtern and matches the main change set.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cvtry-indentation-2002

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/OpenCvSharpExtern/geometry.h (1)

493-507: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Call cv::convertPointsToHomogeneous in these branches.
The 2→3 and 3→4 array overloads still call cv::convertPointsFromHomogeneous, so they produce the wrong transform and corrupt the output.

🤖 Prompt for 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.

In `@src/OpenCvSharpExtern/geometry.h` around lines 493 - 507, The array overloads
in geometry_convertPointsToHomogeneous_array2 are calling the wrong OpenCV
conversion routine, so update the 2→3 and 3→4 branches to use
cv::convertPointsToHomogeneous instead of cv::convertPointsFromHomogeneous. Keep
the existing srcMat/dstMat setup in geometry.h, and make sure the function name
geometry_convertPointsToHomogeneous_array2 matches the conversion being invoked
in both branches.
🤖 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/calib.h`:
- Around line 22-30: The copy loop for imagePointsVec is using the wrong bound,
so it may iterate past imagePoints when the lengths differ. Update the loop in
initCameraMatrix2D handling to use imagePointsLength for populating
imagePointsVec, keeping the objectPointsVec loop unchanged and matching each
vector to its own input count.

In `@src/OpenCvSharpExtern/face_FaceRecognizer.h`:
- Around line 351-361: The histogram population in
face_LBPHFaceRecognizer_getHistograms clears dst and only calls reserve(), then
indexes dst->at(i) on an empty vector. Fix this by resizing or assigning dst to
match result.size() before the loop, then copy the Mats into the pre-sized
container; use the existing face_LBPHFaceRecognizer_getHistograms symbol to
locate the change.

In `@src/OpenCvSharpExtern/features_Feature2D.h`:
- Around line 32-45: The vector construction in detect_Mat2 and compute2 is
wrong because imageVec is initialized with a fixed size and then filled with
push_back, which leaves default Mat entries at the front. Change the code to
build imageVec with reserve(imageLength) and append only the actual input mats,
matching the existing maskVec pattern, so detector->detect and the corresponding
compute call receive correctly populated vectors from features_Feature2D.h.

In `@src/OpenCvSharpExtern/geometry.h`:
- Around line 706-715: The correctMatches wrapper is reshaping the wrong
matrices for the output buffers, so the destination values are written into
points1M and points2M instead of newPoints1M and newPoints2M. Update the
reshaping in geometry.h so the newPoints1MM and newPoints2MM variables are
created from newPoints1M and newPoints2M, then keep cv::correctMatches using
those corrected destination matrices.

In `@src/OpenCvSharpExtern/photo_HDR.h`:
- Around line 49-59: The CalibrateDebevec samples bindings are wired to the
wrong property and type, since photo_CalibrateDebevec_getSamples and
photo_CalibrateDebevec_setSamples still delegate to getLambda/setLambda with a
float. Update these externs in photo_HDR.h to call the CalibrateDebevec samples
accessors instead, and change the setter/getter parameter and return types to
int so the native binding matches getSamples/setSamples(int).

In `@src/OpenCvSharpExtern/stitching_detail_Matchers.h`:
- Around line 127-137: The Matchers conversion is creating extra empty entries
because `featuresVec` is pre-sized and then appended to in the loop. Update the
logic in the `(*obj)(...)` path that builds `featuresVec` so it starts empty,
reserves capacity if needed, and only adds each `cv::detail::ImageFeatures` once
via `push_back` in the loop.

---

Outside diff comments:
In `@src/OpenCvSharpExtern/geometry.h`:
- Around line 493-507: The array overloads in
geometry_convertPointsToHomogeneous_array2 are calling the wrong OpenCV
conversion routine, so update the 2→3 and 3→4 branches to use
cv::convertPointsToHomogeneous instead of cv::convertPointsFromHomogeneous. Keep
the existing srcMat/dstMat setup in geometry.h, and make sure the function name
geometry_convertPointsToHomogeneous_array2 matches the conversion being invoked
in both branches.
🪄 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: 00f64de4-3440-4fa2-bdf9-d0ac70088e5e

📥 Commits

Reviewing files that changed from the base of the PR and between ea2987c and 3bd02c8.

📒 Files selected for processing (108)
  • src/OpenCvSharpExtern/barcode.h
  • src/OpenCvSharpExtern/bgsegm.h
  • src/OpenCvSharpExtern/calib.h
  • src/OpenCvSharpExtern/calib_fisheye.h
  • src/OpenCvSharpExtern/calib_multiview.h
  • src/OpenCvSharpExtern/core.h
  • src/OpenCvSharpExtern/core_Algorithm.h
  • src/OpenCvSharpExtern/core_FileNode.h
  • src/OpenCvSharpExtern/core_FileStorage.h
  • src/OpenCvSharpExtern/core_InputArray.h
  • src/OpenCvSharpExtern/core_LDA.h
  • src/OpenCvSharpExtern/core_Mat.h
  • src/OpenCvSharpExtern/core_MatExpr.h
  • src/OpenCvSharpExtern/core_OutputArray.h
  • src/OpenCvSharpExtern/core_PCA.h
  • src/OpenCvSharpExtern/core_SVD.h
  • src/OpenCvSharpExtern/core_SparseMat.h
  • src/OpenCvSharpExtern/core_UMat.h
  • src/OpenCvSharpExtern/dnn.h
  • src/OpenCvSharpExtern/dnn_Model.h
  • src/OpenCvSharpExtern/dnn_Net.h
  • src/OpenCvSharpExtern/dnn_TextModel.h
  • src/OpenCvSharpExtern/dnn_Tokenizer.h
  • src/OpenCvSharpExtern/dnn_superres.h
  • src/OpenCvSharpExtern/face_FaceRecognizer.h
  • src/OpenCvSharpExtern/face_Facemark.h
  • src/OpenCvSharpExtern/features.h
  • src/OpenCvSharpExtern/features_ANNIndex.h
  • src/OpenCvSharpExtern/features_DescriptorMatcher.h
  • src/OpenCvSharpExtern/features_Feature2D.h
  • src/OpenCvSharpExtern/flann.h
  • src/OpenCvSharpExtern/flann_IndexParams.h
  • src/OpenCvSharpExtern/geometry.h
  • src/OpenCvSharpExtern/highgui.h
  • src/OpenCvSharpExtern/img_hash.h
  • src/OpenCvSharpExtern/imgcodecs.h
  • src/OpenCvSharpExtern/imgproc.h
  • src/OpenCvSharpExtern/imgproc_CLAHE.h
  • src/OpenCvSharpExtern/imgproc_FontFace.h
  • src/OpenCvSharpExtern/imgproc_GeneralizedHough.h
  • src/OpenCvSharpExtern/imgproc_LineIterator.h
  • src/OpenCvSharpExtern/imgproc_LineSegmentDetector.h
  • src/OpenCvSharpExtern/imgproc_Segmentation.h
  • src/OpenCvSharpExtern/imgproc_Subdiv2D.h
  • src/OpenCvSharpExtern/imgproc_undistort.h
  • src/OpenCvSharpExtern/line_descriptor.h
  • src/OpenCvSharpExtern/ml_ANN_MLP.h
  • src/OpenCvSharpExtern/ml_Boost.h
  • src/OpenCvSharpExtern/ml_DTrees.h
  • src/OpenCvSharpExtern/ml_EM.h
  • src/OpenCvSharpExtern/ml_KNearest.h
  • src/OpenCvSharpExtern/ml_LogisticRegression.h
  • src/OpenCvSharpExtern/ml_NormalBayesClassifier.h
  • src/OpenCvSharpExtern/ml_RTrees.h
  • src/OpenCvSharpExtern/ml_SVM.h
  • src/OpenCvSharpExtern/ml_StatModel.h
  • src/OpenCvSharpExtern/objdetect.h
  • src/OpenCvSharpExtern/objdetect_FaceDetectorYN.h
  • src/OpenCvSharpExtern/objdetect_HOGDescriptor.h
  • src/OpenCvSharpExtern/objdetect_QRCodeDetector.h
  • src/OpenCvSharpExtern/objdetect_chessboard.h
  • src/OpenCvSharpExtern/optflow.h
  • src/OpenCvSharpExtern/optflow_motempl.h
  • src/OpenCvSharpExtern/photo.h
  • src/OpenCvSharpExtern/photo_HDR.h
  • src/OpenCvSharpExtern/photo_Tonemap.h
  • src/OpenCvSharpExtern/ptcloud_Odometry.h
  • src/OpenCvSharpExtern/ptcloud_OdometryFrame.h
  • src/OpenCvSharpExtern/ptcloud_OdometrySettings.h
  • src/OpenCvSharpExtern/ptcloud_RgbdNormals.h
  • src/OpenCvSharpExtern/ptcloud_Volume.h
  • src/OpenCvSharpExtern/ptcloud_VolumeSettings.h
  • src/OpenCvSharpExtern/ptcloud_depth.h
  • src/OpenCvSharpExtern/ptcloud_io.h
  • src/OpenCvSharpExtern/quality.h
  • src/OpenCvSharpExtern/saliency_MotionSaliencyBinWangApr2014.h
  • src/OpenCvSharpExtern/saliency_ObjectnessBING.h
  • src/OpenCvSharpExtern/saliency_StaticSaliencyFineGrained.h
  • src/OpenCvSharpExtern/saliency_StaticSaliencySpectralResidual.h
  • src/OpenCvSharpExtern/shape_HistogramCostExtractor.h
  • src/OpenCvSharpExtern/shape_ShapeDistanceExtractor.h
  • src/OpenCvSharpExtern/shape_ShapeTransformer.h
  • src/OpenCvSharpExtern/stereo.h
  • src/OpenCvSharpExtern/stereo_StereoMatcher.h
  • src/OpenCvSharpExtern/stitching.h
  • src/OpenCvSharpExtern/stitching_detail_Matchers.h
  • src/OpenCvSharpExtern/superres.h
  • src/OpenCvSharpExtern/text.h
  • src/OpenCvSharpExtern/text_TextDetector.h
  • src/OpenCvSharpExtern/tracking.h
  • src/OpenCvSharpExtern/tracking_UnscentedKalmanFilter.h
  • src/OpenCvSharpExtern/video_background_segm.h
  • src/OpenCvSharpExtern/video_tracking.h
  • src/OpenCvSharpExtern/videoio.h
  • src/OpenCvSharpExtern/wechat_qrcode.h
  • src/OpenCvSharpExtern/xfeatures2d.h
  • src/OpenCvSharpExtern/xfeatures2d_BOW.h
  • src/OpenCvSharpExtern/xfeatures2d_FeatureDetectors.h
  • src/OpenCvSharpExtern/ximgproc.h
  • src/OpenCvSharpExtern/ximgproc_EdgeBoxes.h
  • src/OpenCvSharpExtern/ximgproc_EdgeDrawing.h
  • src/OpenCvSharpExtern/ximgproc_EdgeFilter.h
  • src/OpenCvSharpExtern/ximgproc_FastLineDetector.h
  • src/OpenCvSharpExtern/ximgproc_RidgeDetectionFilter.h
  • src/OpenCvSharpExtern/ximgproc_Segmentation.h
  • src/OpenCvSharpExtern/ximgproc_StructuredEdgeDetection.h
  • src/OpenCvSharpExtern/ximgproc_SuperPixel.h
  • src/OpenCvSharpExtern/xphoto.h

Comment thread src/OpenCvSharpExtern/calib.h
Comment thread src/OpenCvSharpExtern/face_FaceRecognizer.h
Comment thread src/OpenCvSharpExtern/features_Feature2D.h Outdated
Comment thread src/OpenCvSharpExtern/geometry.h Outdated
Comment thread src/OpenCvSharpExtern/photo_HDR.h Outdated
Comment thread src/OpenCvSharpExtern/stitching_detail_Matchers.h Outdated
shimat and others added 6 commits July 5, 2026 10:27
CodeRabbit review comment on PR #2003: the loop populating
imagePointsVec reused objectPointsLength instead of imagePointsLength,
causing an out-of-bounds read of imagePoints (or leaving trailing
default-constructed Mats) whenever the two lengths differ.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
CodeRabbit review comment on PR #2003: reserve() only changes vector
capacity, not size, so dst stayed empty and dst->at(i) threw
std::out_of_range on the first iteration whenever getHistograms()
returned any element. Assign the result directly instead.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…compute

CodeRabbit review comment on PR #2003: imageVec (and, in compute2,
descriptorsVec) were constructed with a fixed size and then filled via
push_back, leaving imageLength/descriptorsLength default-constructed
Mat entries in front of the real ones. detector->detect/compute then
ran over twice as many (half garbage) images. Build both vectors with
reserve() instead, matching the existing maskVec pattern.

Also fixes a second bug in compute2 uncovered while adding a
regression test: detector->compute() writes into the local
descriptorsVec copy, so its results never reached the caller-owned
Mat objects. Copy the computed descriptors back into *descriptors[i]
after the call.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
CodeRabbit review comment on PR #2003: newPoints1MM/newPoints2MM were
reshaped from the input matrices (points1M/points2M) instead of the
output matrices (newPoints1M/newPoints2M), so cv::correctMatches wrote
its results back into the caller's input points instead of the
dedicated output arrays.

While fixing this, found that the underlying Mat_<Point2d>::reshape(2)
calls were also broken independent of that mixup: Mat_<_Tp>::reshape
only takes a row count, not a channel count, so "2" was being
interpreted as the new row count rather than requesting a 2-channel
view. Replaced the whole Mat_/reshape dance with direct cv::Mat(rows,
1, CV_64FC2, ptr) construction, matching the pattern already used by
sibling wrappers like geometry_findHomography_vector. Added a
regression test that exercises this array-based overload end to end
(the existing CorrectMatches test only covered the Mat-based overload,
which uses a separate, unaffected code path).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
CodeRabbit review comment on PR #2003: photo_CalibrateDebevec_getSamples
and _setSamples called getLambda/setLambda instead of
getSamples/setSamples, so the Samples property actually read/wrote
Lambda. Wire the native accessors to the correct CalibrateDebevec
methods, and change the float signature to int (native
getSamples()/setSamples(int) return/take an int) on the extern
declaration and the public C# property. This is a breaking change to
CalibrateDebevec.Samples's type, but the previous float type never
worked correctly anyway.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
CodeRabbit review comment on PR #2003: featuresVec was constructed
with a fixed size and then filled via push_back, leaving featuresSize
default-constructed ImageFeatures entries in front of the real ones.
(*obj)(featuresVec, ...) then matched over twice as many (half empty)
images, producing a pairwise-matches matrix with bogus image indices.
Build the vector with reserve() instead, matching the already-correct
sibling wrappers in stitching_detail_Matchers.h.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@shimat
shimat merged commit c9fc176 into main Jul 5, 2026
14 checks passed
@shimat
shimat deleted the fix/cvtry-indentation-2002 branch July 5, 2026 02:23
@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.

OpenCvSharpExtern: cvTry([&] { ... }) lambda body indentation is inconsistent

1 participant