Files
opencv-MIRROR/modules/geometry
Parchuri Poojith Kumar 851cc5baa5 geometry: reject degenerate minimal samples in estimateAffine2D / estimateAffinePartial2D (#30829)
* geometry: reject degenerate minimal samples in estimateAffine2D/estimateAffinePartial2D

RANSACPointSetRegistrator::run() has a fast path used whenever exactly
the minimum number of points is supplied (3 for affine, 2 for
similarity). That path skips checkSubset() and trusts the kernel's
return value, but Affine2DEstimatorCallback::runKernel() and
AffinePartial2DEstimatorCallback::runKernel() always returned success,
even when dividing by a zero or near-zero denominator (collinear or
duplicate points). The result was a matrix full of inf/nan with every
point reported as an inlier, instead of a clean failure.

Both kernels now check the denominator against a threshold scaled by
the square of the point coordinates (matching how far float32 input
can drift from true collinearity/coincidence) and return 0 when it is
degenerate. The existing "<= 0" checks in the fast path and the general
RANSAC loop already handle this correctly.

The general RANSAC loop (more than the minimum points) is unaffected,
since a NaN/Inf model already fails computeError's inlier count.

Add test3CollinearPoints and test2DuplicatePoints, matching the
existing test file style.

* geometry: make the degeneracy tolerance independent of coordinate offset

The tolerance used absolute coordinates, so valid points far from the origin were rejected. estimateAffine2D now measures it against the triangle edges, and estimateAffinePartial2D only rejects coincident points. Add large-offset regression tests.

* geometry: tidy the comment in the similarity kernel

* geometry: test points that are collinear only up to float rounding
2026-11-19 15:33:53 +05:30
..