Merge pull request #27787 from Kumataro:fix27783

objdetect: enable setEpsY() for QRDetectMulti
This commit is contained in:
Alexander Smorkalov 2025-09-19 17:57:12 +03:00 committed by GitHub
commit 89e767b0d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 4 deletions

View File

@ -3454,8 +3454,10 @@ int QRDetectMulti::findNumberLocalizationPoints(vector<Point2f>& tmp_localizatio
Mat tmp_shrinking = bin_barcode;
int tmp_num_points = 0;
int num_points = -1;
for (eps_horizontal = 0.1; eps_horizontal < 0.4; eps_horizontal += 0.1)
double eps = 0.0;
for (int epsCoeff = 1; epsCoeff <= 3; epsCoeff++)
{
eps = eps_horizontal * static_cast<double>(epsCoeff);
tmp_num_points = 0;
num_points = -1;
if (purpose == SHRINKING)
@ -3480,7 +3482,7 @@ int QRDetectMulti::findNumberLocalizationPoints(vector<Point2f>& tmp_localizatio
else
break;
}
vector<Point2f> list_lines_y = extractVerticalLines(list_lines_x, eps_horizontal);
vector<Point2f> list_lines_y = extractVerticalLines(list_lines_x, eps);
if (list_lines_y.size() < 3)
{
if (k == 0)
@ -3490,7 +3492,7 @@ int QRDetectMulti::findNumberLocalizationPoints(vector<Point2f>& tmp_localizatio
list_lines_x = searchHorizontalLines();
if (list_lines_x.empty())
break;
list_lines_y = extractVerticalLines(list_lines_x, eps_horizontal);
list_lines_y = extractVerticalLines(list_lines_x, eps);
if (list_lines_y.size() < 3)
break;
}
@ -3568,7 +3570,7 @@ int QRDetectMulti::findNumberLocalizationPoints(vector<Point2f>& tmp_localizatio
vector<Vec3d> list_lines_x = searchHorizontalLines();
if (list_lines_x.empty())
return num_points;
vector<Point2f> list_lines_y = extractVerticalLines(list_lines_x, eps_horizontal);
vector<Point2f> list_lines_y = extractVerticalLines(list_lines_x, eps);
if (list_lines_y.size() < 3)
return num_points;
if (num_points < 3)

View File

@ -679,4 +679,40 @@ TEST(Objdetect_QRCode_detect, detect_regression_22892)
EXPECT_EQ(corners.size(), 4U);
}
// See https://github.com/opencv/opencv/issues/27783
TEST(Objdetect_QRCode_detect, detect_regression_27783)
{
const std::string name_current_image = "9_qrcodes.jpg";
const std::string root = "qrcode/multiple/";
std::string image_path = findDataFile(root + name_current_image);
Mat src = imread(image_path);
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
std::vector<std::string> info;
std::vector<Point> corners;
{
// If default, we can decode 9 QRs.
QRCodeDetector qrcode;
EXPECT_TRUE(qrcode.detectAndDecodeMulti(src, info, corners));
ASSERT_EQ(info.size(), 9UL);
ASSERT_EQ(corners.size(), 36UL);
}
{
// If setEpsX is too small, we can decode no QRs.
QRCodeDetector qrcode;
qrcode.setEpsX(0.01);
EXPECT_FALSE(qrcode.detectAndDecodeMulti(src, info, corners));
}
{
// If setEpsY is too small, we can decode no QRs.
QRCodeDetector qrcode;
qrcode.setEpsY(0.01);
EXPECT_FALSE(qrcode.detectAndDecodeMulti(src, info, corners));
}
}
}} // namespace