opencv/modules/calib3d
chengolivia 250b5003ee
Merge pull request #27305 from chengolivia:add-check-sgbm-nondeterminism
Add image dimension check to avoid StereoSGBM non-determinism #27305 
 
Addresses #25828 

Users noticed that StereoSGBM would occasionally give non-deterministic results for `.compute(imgL, imgR)`.

I and others traced the cause to out-of-bounds access that was not being caught when the input images were not wide enough for the input block size and number of disparities to StereoSGBM. The specific math and logic can be found in the above issue's discussion.

This PR adds a CV_Check to make sure images are wider than 1/2 of the block size + the max disparity the algorithm will search.

The check was only added to the regular `compute` method for StereoSGBM and not to the other modes, as I did not observe the non-deterministic behavior with the other compute modes like HH.

In addition, this PR adds a test case to Calib3d to make sure the check is being thrown in the problem case and that the results are deterministic in the good case.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2025-05-17 10:19:09 +03:00
..
doc Add additional information about homogeneous transformations. Add quick formulas for conversions between physical focal length, sensor size, fov and camera intrinsic params. 2025-04-13 22:28:11 +02:00
include/opencv2 Add additional information about homogeneous transformations. Add quick formulas for conversions between physical focal length, sensor size, fov and camera intrinsic params. 2025-04-13 22:28:11 +02:00
misc Fix assertion in cv2.sampsonDistance 2025-02-15 04:47:01 +00:00
perf Merge pull request #23109 from seanm:misc-warnings 2023-10-06 13:33:21 +03:00
src Merge pull request #27305 from chengolivia:add-check-sgbm-nondeterminism 2025-05-17 10:19:09 +03:00
test Merge pull request #27305 from chengolivia:add-check-sgbm-nondeterminism 2025-05-17 10:19:09 +03:00
CMakeLists.txt Revert "suppress warning on GCC 7 and later" 2022-08-07 15:43:10 +03:00