From 40973bea3191df606b2ce354b9d576ed63a51e39 Mon Sep 17 00:00:00 2001 From: Polina Smolnikova <43805563+rayonnant14@users.noreply.github.com> Date: Tue, 21 Apr 2020 23:44:50 +0300 Subject: [PATCH] Merge pull request #16961 from rayonnant14:objdetect_different_return_value_issue QRDetectMulti : different return value bug fix * QRDetectMulti : bug fix * added tests * changed test image due to large size of previous test image --- .../objdetect/perf/perf_qrcode_pipeline.cpp | 2 +- modules/objdetect/src/qrcode.cpp | 20 +++++++------- modules/objdetect/test/test_qrcode.cpp | 26 +++++++++++++++---- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/modules/objdetect/perf/perf_qrcode_pipeline.cpp b/modules/objdetect/perf/perf_qrcode_pipeline.cpp index 44ab54f4b2..716eb2d779 100644 --- a/modules/objdetect/perf/perf_qrcode_pipeline.cpp +++ b/modules/objdetect/perf/perf_qrcode_pipeline.cpp @@ -114,7 +114,7 @@ INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode, INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode_Multi, ::testing::Values( "2_qrcodes.png", "3_close_qrcodes.png", "3_qrcodes.png", "4_qrcodes.png", - "5_qrcodes.png", "6_qrcodes.png", "7_qrcodes.png", "8_close_qrcodes.png" + "5_qrcodes.png", "6_qrcodes.png", "7_qrcodes.png", "8_close_qrcodes.png" ) ); diff --git a/modules/objdetect/src/qrcode.cpp b/modules/objdetect/src/qrcode.cpp index aa8a9d22b2..98d4286f0d 100644 --- a/modules/objdetect/src/qrcode.cpp +++ b/modules/objdetect/src/qrcode.cpp @@ -1952,8 +1952,9 @@ bool QRDetectMulti::checkSets(vector >& true_points_group, vecto vector set_size(true_points_group.size()); for (size_t i = 0; i < true_points_group.size(); i++) { - set_size[i] = int(0.5 * (true_points_group[i].size() - 2 ) * (true_points_group[i].size() - 1)); + set_size[i] = int( (true_points_group[i].size() - 2 ) * (true_points_group[i].size() - 1) * true_points_group[i].size()) / 6; } + vector< vector< Vec3i > > all_points(true_points_group.size()); for (size_t i = 0; i < true_points_group.size(); i++) all_points[i].resize(set_size[i]); @@ -1961,14 +1962,15 @@ bool QRDetectMulti::checkSets(vector >& true_points_group, vecto for (size_t i = 0; i < true_points_group.size(); i++) { cur_cluster = 0; - for (size_t j = 1; j < true_points_group[i].size() - 1; j++) - for (size_t k = j + 1; k < true_points_group[i].size(); k++) - { - all_points[i][cur_cluster][0] = 0; - all_points[i][cur_cluster][1] = int(j); - all_points[i][cur_cluster][2] = int(k); - cur_cluster++; - } + for (size_t l = 0; l < true_points_group[i].size() - 2; l++) + for (size_t j = l + 1; j < true_points_group[i].size() - 1; j++) + for (size_t k = j + 1; k < true_points_group[i].size(); k++) + { + all_points[i][cur_cluster][0] = int(l); + all_points[i][cur_cluster][1] = int(j); + all_points[i][cur_cluster][2] = int(k); + cur_cluster++; + } } for (size_t i = 0; i < true_points_group.size(); i++) diff --git a/modules/objdetect/test/test_qrcode.cpp b/modules/objdetect/test/test_qrcode.cpp index 79a060db0e..a716c837ee 100644 --- a/modules/objdetect/test/test_qrcode.cpp +++ b/modules/objdetect/test/test_qrcode.cpp @@ -23,7 +23,7 @@ std::string qrcode_images_monitor[] = { }; std::string qrcode_images_multiple[] = { "2_qrcodes.png", "3_close_qrcodes.png", "3_qrcodes.png", "4_qrcodes.png", - "5_qrcodes.png", "6_qrcodes.png", "7_qrcodes.png", "8_close_qrcodes.png" + "5_qrcodes.png", "6_qrcodes.png", "7_qrcodes.png", "8_close_qrcodes.png" }; //#define UPDATE_QRCODE_TEST_DATA #ifdef UPDATE_QRCODE_TEST_DATA @@ -138,7 +138,6 @@ TEST(Objdetect_QRCode_Monitor, generate_test_data) file_config.release(); } - TEST(Objdetect_QRCode_Multi, generate_test_data) { const std::string root = "qrcode/multiple/"; @@ -155,11 +154,12 @@ TEST(Objdetect_QRCode_Multi, generate_test_data) ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path; std::vector corners; - EXPECT_TRUE(detectQRCodeMulti(src, corners)); + QRCodeDetector qrcode; + EXPECT_TRUE(qrcode.detectMulti(src, corners)); #ifdef HAVE_QUIRC std::vector decoded_info; std::vector straight_barcode; - EXPECT_TRUE(decodeQRCodeMulti(src, corners, decoded_info, straight_barcode)); + EXPECT_TRUE(qrcode.decodeMulti(src, corners, decoded_info, straight_barcode)); #endif file_config << "x" << "[:"; for(size_t j = 0; j < corners.size(); j += 4) @@ -475,7 +475,6 @@ TEST_P(Objdetect_QRCode_Multi, regression) } } - INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode, testing::ValuesIn(qrcode_images_name)); INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Close, testing::ValuesIn(qrcode_images_close)); INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Monitor, testing::ValuesIn(qrcode_images_monitor)); @@ -501,6 +500,23 @@ TEST(Objdetect_QRCode_decodeMulti, decode_regression_16491) #endif } +TEST(Objdetect_QRCode_detectMulti, detect_regression_16961) +{ + 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; + + QRCodeDetector qrcode; + std::vector corners; + EXPECT_TRUE(qrcode.detectMulti(src, corners)); + ASSERT_FALSE(corners.empty()); + size_t expect_corners_size = 36; + EXPECT_EQ(corners.size(), expect_corners_size); +} + TEST(Objdetect_QRCode_basic, not_found_qrcode) { std::vector corners;