mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge pull request #24299 from dkurt:qrcode_decode
In-house QR codes decoding #24299 ### Pull Request Readiness Checklist QR codes decoding pipeline without 3rdparty dependency (Quirc library). Implemented according to standard https://github.com/yansikeim/QR-Code/blob/master/ISO%20IEC%2018004%202015%20Standard.pdf **Merge with extra**: https://github.com/opencv/opencv_extra/pull/1124 resolves https://github.com/opencv/opencv/issues/24225 resolves https://github.com/opencv/opencv/issues/17290 resolves https://github.com/opencv/opencv/issues/24318 https://github.com/opencv/opencv/issues/24346 Resources: * https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders * https://en.wikipedia.org/wiki/Berlekamp%E2%80%93Massey_algorithm ``` Geometric mean (ms) Name of Test quirc new2 new2 vs quirc (x-factor) decode::Perf_Objdetect_Not_QRCode::("chessboard", 640x480) 9.151 9.157 1.00 decode::Perf_Objdetect_Not_QRCode::("chessboard", 1280x720) 21.609 21.609 1.00 decode::Perf_Objdetect_Not_QRCode::("chessboard", 1920x1080) 42.088 41.924 1.00 decode::Perf_Objdetect_Not_QRCode::("chessboard", 3840x2160) 169.737 169.050 1.00 decode::Perf_Objdetect_Not_QRCode::("random", 640x480) 8.552 8.611 0.99 decode::Perf_Objdetect_Not_QRCode::("random", 1280x720) 21.264 21.581 0.99 decode::Perf_Objdetect_Not_QRCode::("random", 1920x1080) 42.415 43.468 0.98 decode::Perf_Objdetect_Not_QRCode::("random", 3840x2160) 175.003 174.294 1.00 decode::Perf_Objdetect_Not_QRCode::("zero", 640x480) 8.528 8.421 1.01 decode::Perf_Objdetect_Not_QRCode::("zero", 1280x720) 21.548 21.209 1.02 decode::Perf_Objdetect_Not_QRCode::("zero", 1920x1080) 42.581 42.529 1.00 decode::Perf_Objdetect_Not_QRCode::("zero", 3840x2160) 176.231 174.410 1.01 decode::Perf_Objdetect_QRCode::"kanji.jpg" 6.105 6.072 1.01 decode::Perf_Objdetect_QRCode::"link_github_ocv.jpg" 6.069 6.076 1.00 decode::Perf_Objdetect_QRCode::"link_ocv.jpg" 6.143 6.240 0.98 decode::Perf_Objdetect_QRCode::"link_wiki_cv.jpg" 6.369 6.420 0.99 decode::Perf_Objdetect_QRCode::"russian.jpg" 6.558 6.549 1.00 decode::Perf_Objdetect_QRCode::"version_1_down.jpg" 5.634 5.621 1.00 decode::Perf_Objdetect_QRCode::"version_1_left.jpg" 5.560 5.609 0.99 decode::Perf_Objdetect_QRCode::"version_1_right.jpg" 5.539 5.631 0.98 decode::Perf_Objdetect_QRCode::"version_1_top.jpg" 5.622 5.566 1.01 decode::Perf_Objdetect_QRCode::"version_1_up.jpg" 5.569 5.534 1.01 decode::Perf_Objdetect_QRCode::"version_5_down.jpg" 6.514 6.436 1.01 decode::Perf_Objdetect_QRCode::"version_5_left.jpg" 6.668 6.479 1.03 decode::Perf_Objdetect_QRCode::"version_5_top.jpg" 6.481 6.484 1.00 decode::Perf_Objdetect_QRCode::"version_5_up.jpg" 7.011 6.513 1.08 decodeMulti::Perf_Objdetect_QRCode_Multi::("2_qrcodes.png", "aruco_based") 14.885 15.089 0.99 decodeMulti::Perf_Objdetect_QRCode_Multi::("2_qrcodes.png", "contours_based") 14.896 14.906 1.00 decodeMulti::Perf_Objdetect_QRCode_Multi::("3_close_qrcodes.png", "aruco_based") 6.661 6.663 1.00 decodeMulti::Perf_Objdetect_QRCode_Multi::("3_close_qrcodes.png", "contours_based") 6.614 6.592 1.00 decodeMulti::Perf_Objdetect_QRCode_Multi::("3_qrcodes.png", "aruco_based") 14.814 14.592 1.02 decodeMulti::Perf_Objdetect_QRCode_Multi::("3_qrcodes.png", "contours_based") 15.245 15.135 1.01 decodeMulti::Perf_Objdetect_QRCode_Multi::("4_qrcodes.png", "aruco_based") 10.923 10.881 1.00 decodeMulti::Perf_Objdetect_QRCode_Multi::("4_qrcodes.png", "contours_based") 10.680 10.128 1.05 decodeMulti::Perf_Objdetect_QRCode_Multi::("5_qrcodes.png", "contours_based") 11.788 11.576 1.02 decodeMulti::Perf_Objdetect_QRCode_Multi::("6_qrcodes.png", "aruco_based") 25.887 25.979 1.00 decodeMulti::Perf_Objdetect_QRCode_Multi::("6_qrcodes.png", "contours_based") 26.183 25.627 1.02 decodeMulti::Perf_Objdetect_QRCode_Multi::("7_qrcodes.png", "aruco_based") 32.786 32.253 1.02 decodeMulti::Perf_Objdetect_QRCode_Multi::("7_qrcodes.png", "contours_based") 24.290 24.435 0.99 decodeMulti::Perf_Objdetect_QRCode_Multi::("8_close_qrcodes.png", "aruco_based") 89.696 89.247 1.01 decodeMulti::Perf_Objdetect_QRCode_Multi::("8_close_qrcodes.png", "contours_based") 89.872 89.600 1.00 ```
This commit is contained in:
@@ -56,9 +56,8 @@ TEST(Objdetect_QRCode, generate_test_data)
|
||||
std::string decoded_info;
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
EXPECT_TRUE(detectQRCode(src, corners));
|
||||
#ifdef HAVE_QUIRC
|
||||
EXPECT_TRUE(decodeQRCode(src, corners, decoded_info, straight_barcode));
|
||||
#endif
|
||||
|
||||
file_config << "x" << "[:";
|
||||
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
||||
file_config << "]";
|
||||
@@ -95,9 +94,8 @@ TEST(Objdetect_QRCode_Close, generate_test_data)
|
||||
Size new_size(width, height);
|
||||
resize(src, barcode, new_size, 0, 0, INTER_LINEAR_EXACT);
|
||||
EXPECT_TRUE(detectQRCode(barcode, corners));
|
||||
#ifdef HAVE_QUIRC
|
||||
EXPECT_TRUE(decodeQRCode(barcode, corners, decoded_info, straight_barcode));
|
||||
#endif
|
||||
|
||||
file_config << "x" << "[:";
|
||||
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
||||
file_config << "]";
|
||||
@@ -133,9 +131,8 @@ TEST(Objdetect_QRCode_Monitor, generate_test_data)
|
||||
Size new_size(width, height);
|
||||
resize(src, barcode, new_size, 0, 0, INTER_LINEAR_EXACT);
|
||||
EXPECT_TRUE(detectQRCode(barcode, corners));
|
||||
#ifdef HAVE_QUIRC
|
||||
EXPECT_TRUE(decodeQRCode(barcode, corners, decoded_info, straight_barcode));
|
||||
#endif
|
||||
|
||||
file_config << "x" << "[:";
|
||||
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
||||
file_config << "]";
|
||||
@@ -165,9 +162,8 @@ TEST(Objdetect_QRCode_Curved, generate_test_data)
|
||||
std::string decoded_info;
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
EXPECT_TRUE(detectQRCode(src, corners));
|
||||
#ifdef HAVE_QUIRC
|
||||
EXPECT_TRUE(decodeCurvedQRCode(src, corners, decoded_info, straight_barcode));
|
||||
#endif
|
||||
|
||||
file_config << "x" << "[:";
|
||||
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
||||
file_config << "]";
|
||||
@@ -198,11 +194,10 @@ TEST(Objdetect_QRCode_Multi, generate_test_data)
|
||||
std::vector<Point> 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(qrcode.decodeMulti(src, corners, decoded_info, straight_barcode));
|
||||
#endif
|
||||
|
||||
file_config << "x" << "[:";
|
||||
for(size_t j = 0; j < corners.size(); j += 4)
|
||||
{
|
||||
@@ -256,15 +251,11 @@ TEST_P(Objdetect_QRCode, regression)
|
||||
std::vector<Point> corners;
|
||||
std::string decoded_info;
|
||||
QRCodeDetector qrcode;
|
||||
#ifdef HAVE_QUIRC
|
||||
decoded_info = qrcode.detectAndDecode(src, corners, straight_barcode);
|
||||
ASSERT_FALSE(corners.empty());
|
||||
ASSERT_FALSE(decoded_info.empty());
|
||||
int expected_barcode_type = CV_8UC1;
|
||||
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
|
||||
#else
|
||||
ASSERT_TRUE(qrcode.detect(src, corners));
|
||||
#endif
|
||||
check_qr(root, name_current_image, "test_images", corners, {decoded_info}, pixels_error);
|
||||
}
|
||||
|
||||
@@ -287,15 +278,11 @@ TEST_P(Objdetect_QRCode_Close, regression)
|
||||
std::vector<Point> corners;
|
||||
std::string decoded_info;
|
||||
QRCodeDetector qrcode;
|
||||
#ifdef HAVE_QUIRC
|
||||
decoded_info = qrcode.detectAndDecode(barcode, corners, straight_barcode);
|
||||
ASSERT_FALSE(corners.empty());
|
||||
ASSERT_FALSE(decoded_info.empty());
|
||||
int expected_barcode_type = CV_8UC1;
|
||||
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
|
||||
#else
|
||||
ASSERT_TRUE(qrcode.detect(barcode, corners));
|
||||
#endif
|
||||
check_qr(root, name_current_image, "close_images", corners, {decoded_info}, pixels_error);
|
||||
}
|
||||
|
||||
@@ -318,15 +305,11 @@ TEST_P(Objdetect_QRCode_Monitor, regression)
|
||||
std::vector<Point> corners;
|
||||
std::string decoded_info;
|
||||
QRCodeDetector qrcode;
|
||||
#ifdef HAVE_QUIRC
|
||||
decoded_info = qrcode.detectAndDecode(barcode, corners, straight_barcode);
|
||||
ASSERT_FALSE(corners.empty());
|
||||
ASSERT_FALSE(decoded_info.empty());
|
||||
int expected_barcode_type = CV_8UC1;
|
||||
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
|
||||
#else
|
||||
ASSERT_TRUE(qrcode.detect(barcode, corners));
|
||||
#endif
|
||||
check_qr(root, name_current_image, "monitor_images", corners, {decoded_info}, pixels_error);
|
||||
}
|
||||
|
||||
@@ -344,15 +327,11 @@ TEST_P(Objdetect_QRCode_Curved, regression)
|
||||
std::vector<Point> corners;
|
||||
std::string decoded_info;
|
||||
QRCodeDetector qrcode;
|
||||
#ifdef HAVE_QUIRC
|
||||
decoded_info = qrcode.detectAndDecodeCurved(src, corners, straight_barcode);
|
||||
ASSERT_FALSE(corners.empty());
|
||||
ASSERT_FALSE(decoded_info.empty());
|
||||
int expected_barcode_type = CV_8UC1;
|
||||
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
|
||||
#else
|
||||
ASSERT_TRUE(qrcode.detect(src, corners));
|
||||
#endif
|
||||
check_qr(root, name_current_image, "test_images", corners, {decoded_info}, pixels_error);
|
||||
}
|
||||
|
||||
@@ -375,7 +354,6 @@ TEST_P(Objdetect_QRCode_Multi, regression)
|
||||
}
|
||||
std::vector<Point> corners;
|
||||
std::vector<cv::String> decoded_info;
|
||||
#ifdef HAVE_QUIRC
|
||||
std::vector<Mat> straight_barcode;
|
||||
EXPECT_TRUE(qrcode.detectAndDecodeMulti(src, decoded_info, corners, straight_barcode));
|
||||
ASSERT_FALSE(corners.empty());
|
||||
@@ -383,9 +361,6 @@ TEST_P(Objdetect_QRCode_Multi, regression)
|
||||
int expected_barcode_type = CV_8UC1;
|
||||
for(size_t i = 0; i < straight_barcode.size(); i++)
|
||||
EXPECT_EQ(expected_barcode_type, straight_barcode[i].type());
|
||||
#else
|
||||
ASSERT_TRUE(qrcode.detectMulti(src, corners));
|
||||
#endif
|
||||
check_qr(root, name_current_image, "multiple_images", corners, decoded_info, pixels_error, true);
|
||||
}
|
||||
|
||||
@@ -398,7 +373,6 @@ INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Multi, testing::Combine(testing::
|
||||
|
||||
TEST(Objdetect_QRCode_decodeMulti, decode_regression_16491)
|
||||
{
|
||||
#ifdef HAVE_QUIRC
|
||||
Mat zero_image = Mat::zeros(256, 256, CV_8UC1);
|
||||
Point corners_[] = {Point(16, 16), Point(128, 16), Point(128, 128), Point(16, 128),
|
||||
Point(16, 16), Point(128, 16), Point(128, 128), Point(16, 128)};
|
||||
@@ -413,7 +387,6 @@ TEST(Objdetect_QRCode_decodeMulti, decode_regression_16491)
|
||||
Mat mat_corners(2, 4, CV_32SC2, (void*)&vec_corners[0]);
|
||||
QRCodeDetector mat_qrcode;
|
||||
EXPECT_NO_THROW(mat_qrcode.decodeMulti(zero_image, mat_corners, decoded_info, straight_barcode));
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef testing::TestWithParam<std::string> Objdetect_QRCode_detectMulti;
|
||||
@@ -449,7 +422,6 @@ TEST_P(Objdetect_QRCode_detectAndDecodeMulti, check_output_parameters_type_19363
|
||||
std::string image_path = findDataFile(root + name_current_image);
|
||||
Mat src = imread(image_path);
|
||||
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
||||
#ifdef HAVE_QUIRC
|
||||
GraphicalCodeDetector qrcode = QRCodeDetector();
|
||||
if (method == "aruco_based") {
|
||||
qrcode = QRCodeDetectorAruco();
|
||||
@@ -467,7 +439,6 @@ TEST_P(Objdetect_QRCode_detectAndDecodeMulti, check_output_parameters_type_19363
|
||||
ASSERT_FALSE(corners.empty());
|
||||
for(size_t i = 0; i < straight_barcode.size(); i++)
|
||||
EXPECT_EQ(expected_barcode_type, straight_barcode[i].type());
|
||||
#endif
|
||||
}
|
||||
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_detectAndDecodeMulti, testing::Values("contours_based", "aruco_based"));
|
||||
|
||||
@@ -487,9 +458,7 @@ TEST(Objdetect_QRCode_detect, detect_regression_20882)
|
||||
cv::String decoded_info;
|
||||
EXPECT_TRUE(qrcode.detect(src, corners));
|
||||
EXPECT_TRUE(!corners.empty());
|
||||
#ifdef HAVE_QUIRC
|
||||
EXPECT_NO_THROW(qrcode.decode(src, corners, straight_barcode));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Objdetect_QRCode_basic, not_found_qrcode)
|
||||
@@ -500,10 +469,8 @@ TEST(Objdetect_QRCode_basic, not_found_qrcode)
|
||||
Mat zero_image = Mat::zeros(256, 256, CV_8UC1);
|
||||
QRCodeDetector qrcode;
|
||||
EXPECT_FALSE(qrcode.detect(zero_image, corners));
|
||||
#ifdef HAVE_QUIRC
|
||||
corners = std::vector<Point>(4);
|
||||
EXPECT_ANY_THROW(qrcode.decode(zero_image, corners, straight_barcode));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Objdetect_QRCode_detect, detect_regression_21287)
|
||||
@@ -521,9 +488,7 @@ TEST(Objdetect_QRCode_detect, detect_regression_21287)
|
||||
cv::String decoded_info;
|
||||
EXPECT_TRUE(qrcode.detect(src, corners));
|
||||
EXPECT_TRUE(!corners.empty());
|
||||
#ifdef HAVE_QUIRC
|
||||
EXPECT_NO_THROW(qrcode.decode(src, corners, straight_barcode));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Objdetect_QRCode_detect_flipped, regression_23249)
|
||||
@@ -549,12 +514,10 @@ TEST(Objdetect_QRCode_detect_flipped, regression_23249)
|
||||
EXPECT_TRUE(qrcode.detect(src, corners));
|
||||
EXPECT_TRUE(!corners.empty());
|
||||
std::string decoded_msg;
|
||||
#ifdef HAVE_QUIRC
|
||||
const std::string &expect_msg = flipped_image.second;
|
||||
EXPECT_NO_THROW(decoded_msg = qrcode.decode(src, corners, straight_barcode));
|
||||
ASSERT_FALSE(straight_barcode.empty()) << "Can't decode qrimage.";
|
||||
EXPECT_EQ(expect_msg, decoded_msg);
|
||||
#endif
|
||||
const std::string &expect_msg = flipped_image.second;
|
||||
EXPECT_NO_THROW(decoded_msg = qrcode.decode(src, corners, straight_barcode));
|
||||
ASSERT_FALSE(straight_barcode.empty()) << "Can't decode qrimage.";
|
||||
EXPECT_EQ(expect_msg, decoded_msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,12 +540,10 @@ TEST(Objdetect_QRCode_decode, decode_regression_21929)
|
||||
|
||||
EXPECT_TRUE(qrcode.detect(src, corners));
|
||||
EXPECT_TRUE(!corners.empty());
|
||||
#ifdef HAVE_QUIRC
|
||||
cv::String decoded_msg;
|
||||
EXPECT_NO_THROW(decoded_msg = qrcode.decode(src, corners, straight_barcode));
|
||||
ASSERT_FALSE(straight_barcode.empty()) << "Can't decode qrimage.";
|
||||
EXPECT_EQ(expect_msg, decoded_msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Objdetect_QRCode_decode, decode_regression_version_25)
|
||||
@@ -603,12 +564,11 @@ TEST(Objdetect_QRCode_decode, decode_regression_version_25)
|
||||
|
||||
EXPECT_TRUE(qrcode.detect(src, corners));
|
||||
EXPECT_TRUE(!corners.empty());
|
||||
#ifdef HAVE_QUIRC
|
||||
|
||||
cv::String decoded_msg;
|
||||
EXPECT_NO_THROW(decoded_msg = qrcode.decode(src, corners, straight_barcode));
|
||||
ASSERT_FALSE(straight_barcode.empty()) << "Can't decode qrimage.";
|
||||
EXPECT_EQ(expect_msg, decoded_msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_P(Objdetect_QRCode_detectAndDecodeMulti, decode_9_qrcodes_version7)
|
||||
@@ -639,9 +599,6 @@ TEST_P(Objdetect_QRCode_detectAndDecodeMulti, decode_9_qrcodes_version7)
|
||||
|
||||
TEST(Objdetect_QRCode_detectAndDecode, utf8_output)
|
||||
{
|
||||
#ifndef HAVE_QUIRC
|
||||
throw SkipTestException("Quirc is required for decoding");
|
||||
#else
|
||||
const std::string name_current_image = "umlaut.png";
|
||||
const std::string root = "qrcode/";
|
||||
|
||||
@@ -655,7 +612,6 @@ TEST(Objdetect_QRCode_detectAndDecode, utf8_output)
|
||||
std::string decoded_info = qrcode.detectAndDecode(src, corners, straight);
|
||||
EXPECT_FALSE(decoded_info.empty());
|
||||
EXPECT_NE(decoded_info.find("M\xc3\xbcllheimstrasse"), std::string::npos);
|
||||
#endif // HAVE_QUIRC
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user