Skip to content

Commit

Permalink
Merge pull request opencv#16961 from rayonnant14:objdetect_different_…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
rayonnant14 authored Apr 21, 2020
1 parent 8badf7f commit 40973be
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion modules/objdetect/perf/perf_qrcode_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
);

Expand Down
20 changes: 11 additions & 9 deletions modules/objdetect/src/qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,23 +1952,25 @@ bool QRDetectMulti::checkSets(vector<vector<Point2f> >& true_points_group, vecto
vector<int> 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]);
int cur_cluster = 0;
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++)
Expand Down
26 changes: 21 additions & 5 deletions modules/objdetect/test/test_qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/";
Expand All @@ -155,11 +154,12 @@ TEST(Objdetect_QRCode_Multi, generate_test_data)

ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
std::vector<Point> corners;
EXPECT_TRUE(detectQRCodeMulti(src, corners));
QRCodeDetector qrcode;
EXPECT_TRUE(qrcode.detectMulti(src, corners));
#ifdef HAVE_QUIRC
std::vector<cv::String> decoded_info;
std::vector<Mat> 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)
Expand Down Expand Up @@ -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));
Expand All @@ -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<Point> 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<Point> corners;
Expand Down

0 comments on commit 40973be

Please sign in to comment.