Skip to content

Fix reflection correction in 2D RANSAC alignment - #118

Closed
dddd-jh wants to merge 1 commit into
PRBonn:mainfrom
dddd-jh:fix/proper-2d-ransac-rotation
Closed

dddd-jh wants to merge 1 commit into
PRBonn:mainfrom
dddd-jh:fix/proper-2d-ransac-rotation

Conversation

@dddd-jh

@dddd-jh dddd-jh commented Oct 5, 2026

Copy link
Copy Markdown

The 2D Kabsch fit can return a reflection, or reject valid correspondences and return a NaN pose. -R does not correct a reflection in two dimensions: det(-R) == det(R). The translation also uses the original matrix rather than the matrix assigned to the transform.

For example, reference points (4, 7) and (6, 7), transformed by a 180-degree rotation and translation (2, -3), produce zero inliers and a NaN translation on the current implementation in my local build. A mirrored narrow rectangle centered at the origin produces four inliers but a final rotation determinant of -1.

This changes the SVD fit to V * diag(1, sign(det(V * U.transpose()))) * U.transpose(), correcting the smaller singular direction. Both rotation and translation use this corrected matrix.

Adds nine regression cases through the public RansacAlignment2D API: translated two-point fits at six angles, a noncollinear fit, and reflected rectangles at zero and nonzero reference centroids. They check finite output, all expected inliers, orthogonality, determinant +1, the centroid mapping and the expected proper rigid fit. Checks use explicit failure returns so they remain active in Release builds. The reflected rectangles are small enough that every sampled proper fit includes all four points under the existing inlier threshold.

The tests are opt-in via -DBUILD_TESTS=ON, use no additional test framework dependency, and run via CTest in both existing C++ CI jobs.

Validation:

  • Compiled the actual alignment source with Clang 18.1.6 / Eigen 3.4.0 on Windows. Five of the nine new cases fail with the original source; all nine pass after the fix.
  • Built a standalone Release CMake target using the actual source and the submitted CTest registration block; all nine cases pass, including five consecutive runs per case.
  • clang-format 14, cmake-format and whitespace/YAML checks pass.

I have not built the full OpenCV/Sophus-dependent library or run the complete map-closure pipeline locally. The updated upstream CI covers the full library build on its existing platform matrix.

@saurabh1002

Copy link
Copy Markdown
Member

AI-Bots based users do not go on the contributor list. The issue will be fixed as a separate PR.

@saurabh1002 saurabh1002 mentioned this pull request Oct 6, 2026
saurabh1002 added a commit that referenced this pull request Oct 6, 2026
* remove redundant move

* Fix refelction bug in Kabsch-Umeyama as suggested in #118
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.

2 participants