From 1f47f5ba973a4d4dc116c56dba3dff34883c567d Mon Sep 17 00:00:00 2001 From: Nechama Krashinski Date: Thu, 22 Jan 2026 15:13:21 +0200 Subject: [PATCH] Merge pull request #28404 from NechamaKrashinski:imgproc-cornersubpix-error-handling imgproc: replace assertion in cornerSubPix with descriptive error #28404 Replace CV_Assert with explicit bounds check for initial corners in cornerSubPix. This provides a descriptive runtime error instead of abrupt termination, improving error handling for Python and C++ users. No algorithmic or behavioral change for valid inputs. Fixes #25139 (Related to #7276). ### 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 - [ ] 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 --- modules/imgproc/src/cornersubpix.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/cornersubpix.cpp b/modules/imgproc/src/cornersubpix.cpp index af5bd999dc..fa4380e368 100644 --- a/modules/imgproc/src/cornersubpix.cpp +++ b/modules/imgproc/src/cornersubpix.cpp @@ -96,7 +96,11 @@ void cv::cornerSubPix( InputArray _image, InputOutputArray _corners, for( int pt_i = 0; pt_i < count; pt_i++ ) { Point2f cT = corners[pt_i], cI = cT; - CV_Assert( Rect(0, 0, src.cols, src.rows).contains(cT) ); + if (!Rect(0, 0, src.cols, src.rows).contains(cT)) + { + CV_Error(Error::StsOutOfRange, + "cornerSubPix: initial corner is outside the image."); + } int iter = 0; double err = 0;