From d00a96315e74245afd28be0a11f671be60c74d4a Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Mon, 22 May 2023 11:34:30 +0100 Subject: [PATCH] Merge pull request #23612 from cpoerschke:3.4-issue-21532 QRCodeDetector: don't floodFill with outside-of-image seedPoint #23612 Fixes #21532. ### 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/objdetect/src/qrcode.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/objdetect/src/qrcode.cpp b/modules/objdetect/src/qrcode.cpp index 0a4ac5a80c..debdb4ca24 100644 --- a/modules/objdetect/src/qrcode.cpp +++ b/modules/objdetect/src/qrcode.cpp @@ -570,10 +570,11 @@ bool QRDetect::computeTransformationPoints() { Mat mask = Mat::zeros(bin_barcode.rows + 2, bin_barcode.cols + 2, CV_8UC1); uint8_t next_pixel, future_pixel = 255; - int count_test_lines = 0, index = cvRound(localization_points[i].x); - for (; index < bin_barcode.cols - 1; index++) + int count_test_lines = 0, index_c = max(0, min(cvRound(localization_points[i].x), bin_barcode.cols - 1)); + const int index_r = max(0, min(cvRound(localization_points[i].y), bin_barcode.rows - 1)); + for (; index_c < bin_barcode.cols - 1; index_c++) { - next_pixel = bin_barcode.ptr(cvRound(localization_points[i].y))[index + 1]; + next_pixel = bin_barcode.ptr(index_r)[index_c + 1]; if (next_pixel == future_pixel) { future_pixel = static_cast(~future_pixel); @@ -581,7 +582,7 @@ bool QRDetect::computeTransformationPoints() if (count_test_lines == 2) { floodFill(bin_barcode, mask, - Point(index + 1, cvRound(localization_points[i].y)), 255, + Point(index_c + 1, index_r), 255, 0, Scalar(), Scalar(), FLOODFILL_MASK_ONLY); break; }