2018-07-11 01:24:09 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
2018-06-27 21:37:10 +08:00
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
2023-06-02 21:18:24 +08:00
|
|
|
#include "test_qr_utils.hpp"
|
2022-08-25 19:27:18 +08:00
|
|
|
#include "opencv2/imgproc.hpp"
|
2018-06-27 21:37:10 +08:00
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
namespace opencv_test { namespace {
|
2018-07-11 01:24:09 +08:00
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
std::string qrcode_images_name[] = {
|
2018-08-18 00:01:02 +08:00
|
|
|
"version_1_down.jpg", "version_1_left.jpg", "version_1_right.jpg", "version_1_up.jpg", "version_1_top.jpg",
|
|
|
|
"version_2_down.jpg", "version_2_left.jpg", "version_2_right.jpg", "version_2_up.jpg", "version_2_top.jpg",
|
|
|
|
"version_3_down.jpg", "version_3_left.jpg", "version_3_right.jpg", "version_3_up.jpg", "version_3_top.jpg",
|
|
|
|
"version_4_down.jpg", "version_4_left.jpg", "version_4_right.jpg", "version_4_up.jpg", "version_4_top.jpg",
|
2022-09-29 04:52:24 +08:00
|
|
|
"version_5_down.jpg", "version_5_left.jpg", /*"version_5_right.jpg",*/ "version_5_up.jpg", "version_5_top.jpg",
|
2018-08-18 00:01:02 +08:00
|
|
|
"russian.jpg", "kanji.jpg", "link_github_ocv.jpg", "link_ocv.jpg", "link_wiki_cv.jpg"
|
2022-06-04 22:33:08 +08:00
|
|
|
// version_5_right.jpg DISABLED after tile fix, PR #22025
|
2018-07-11 01:24:09 +08:00
|
|
|
};
|
|
|
|
|
2022-08-25 19:27:18 +08:00
|
|
|
// Todo: fix corner align in big QRs to enable close_5.png
|
2019-10-01 02:33:58 +08:00
|
|
|
std::string qrcode_images_close[] = {
|
2022-08-25 19:27:18 +08:00
|
|
|
"close_1.png", "close_2.png", "close_3.png", "close_4.png"//, "close_5.png"
|
2019-10-01 02:33:58 +08:00
|
|
|
};
|
|
|
|
std::string qrcode_images_monitor[] = {
|
|
|
|
"monitor_1.png", "monitor_2.png", "monitor_3.png", "monitor_4.png", "monitor_5.png"
|
|
|
|
};
|
2020-10-24 02:42:45 +08:00
|
|
|
std::string qrcode_images_curved[] = {
|
2022-06-04 22:33:08 +08:00
|
|
|
"curved_1.jpg", "curved_2.jpg", "curved_3.jpg", /*"curved_4.jpg",*/ "curved_5.jpg", /*"curved_6.jpg",*/ "curved_7.jpg", "curved_8.jpg"
|
2020-10-24 02:42:45 +08:00
|
|
|
};
|
2022-06-04 22:33:08 +08:00
|
|
|
// curved_4.jpg, curved_6.jpg DISABLED after tile fix, PR #22025
|
2020-01-27 03:18:42 +08:00
|
|
|
std::string qrcode_images_multiple[] = {
|
|
|
|
"2_qrcodes.png", "3_close_qrcodes.png", "3_qrcodes.png", "4_qrcodes.png",
|
2020-04-22 04:44:50 +08:00
|
|
|
"5_qrcodes.png", "6_qrcodes.png", "7_qrcodes.png", "8_close_qrcodes.png"
|
2020-01-27 03:18:42 +08:00
|
|
|
};
|
2022-12-15 04:56:57 +08:00
|
|
|
|
2023-06-02 21:18:24 +08:00
|
|
|
static std::set<std::pair<std::string, std::string>> disabled_samples = {{"5_qrcodes.png", "aruco_based"}};
|
|
|
|
|
2020-01-27 03:18:42 +08:00
|
|
|
//#define UPDATE_QRCODE_TEST_DATA
|
2018-07-11 01:24:09 +08:00
|
|
|
#ifdef UPDATE_QRCODE_TEST_DATA
|
|
|
|
|
|
|
|
TEST(Objdetect_QRCode, generate_test_data)
|
2018-06-27 21:37:10 +08:00
|
|
|
{
|
2018-07-24 18:08:58 +08:00
|
|
|
const std::string root = "qrcode/";
|
|
|
|
const std::string dataset_config = findDataFile(root + "dataset_config.json");
|
2018-07-11 01:24:09 +08:00
|
|
|
FileStorage file_config(dataset_config, FileStorage::WRITE);
|
|
|
|
|
|
|
|
file_config << "test_images" << "[";
|
2018-07-24 18:08:58 +08:00
|
|
|
size_t images_count = sizeof(qrcode_images_name) / sizeof(qrcode_images_name[0]);
|
2018-07-11 01:24:09 +08:00
|
|
|
for (size_t i = 0; i < images_count; i++)
|
|
|
|
{
|
|
|
|
file_config << "{:" << "image_name" << qrcode_images_name[i];
|
2018-07-24 18:08:58 +08:00
|
|
|
std::string image_path = findDataFile(root + qrcode_images_name[i]);
|
|
|
|
std::vector<Point> corners;
|
2018-08-18 00:01:02 +08:00
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
|
|
|
|
std::string decoded_info;
|
2018-07-24 18:08:58 +08:00
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
EXPECT_TRUE(detectQRCode(src, corners));
|
2018-08-18 00:01:02 +08:00
|
|
|
EXPECT_TRUE(decodeQRCode(src, corners, decoded_info, straight_barcode));
|
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
```
2023-11-24 16:35:36 +08:00
|
|
|
|
2018-07-11 01:24:09 +08:00
|
|
|
file_config << "x" << "[:";
|
2018-07-24 18:08:58 +08:00
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
2018-07-11 01:24:09 +08:00
|
|
|
file_config << "]";
|
|
|
|
file_config << "y" << "[:";
|
2018-07-24 18:08:58 +08:00
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].y; }
|
2018-08-18 00:01:02 +08:00
|
|
|
file_config << "]";
|
|
|
|
file_config << "info" << decoded_info;
|
|
|
|
file_config << "}";
|
2018-07-11 01:24:09 +08:00
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
file_config.release();
|
2018-06-27 21:37:10 +08:00
|
|
|
}
|
|
|
|
|
2019-10-01 02:33:58 +08:00
|
|
|
TEST(Objdetect_QRCode_Close, generate_test_data)
|
|
|
|
{
|
|
|
|
const std::string root = "qrcode/close/";
|
|
|
|
const std::string dataset_config = findDataFile(root + "dataset_config.json");
|
|
|
|
FileStorage file_config(dataset_config, FileStorage::WRITE);
|
|
|
|
|
|
|
|
file_config << "close_images" << "[";
|
|
|
|
size_t close_count = sizeof(qrcode_images_close) / sizeof(qrcode_images_close[0]);
|
|
|
|
for (size_t i = 0; i < close_count; i++)
|
|
|
|
{
|
|
|
|
file_config << "{:" << "image_name" << qrcode_images_close[i];
|
|
|
|
std::string image_path = findDataFile(root + qrcode_images_close[i]);
|
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE), barcode, straight_barcode;
|
|
|
|
std::string decoded_info;
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
const double min_side = std::min(src.size().width, src.size().height);
|
|
|
|
double coeff_expansion = 1024.0 / min_side;
|
|
|
|
const int width = cvRound(src.size().width * coeff_expansion);
|
|
|
|
const int height = cvRound(src.size().height * coeff_expansion);
|
|
|
|
Size new_size(width, height);
|
2022-09-29 04:52:24 +08:00
|
|
|
resize(src, barcode, new_size, 0, 0, INTER_LINEAR_EXACT);
|
2019-10-01 02:33:58 +08:00
|
|
|
EXPECT_TRUE(detectQRCode(barcode, corners));
|
|
|
|
EXPECT_TRUE(decodeQRCode(barcode, corners, decoded_info, straight_barcode));
|
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
```
2023-11-24 16:35:36 +08:00
|
|
|
|
2019-10-01 02:33:58 +08:00
|
|
|
file_config << "x" << "[:";
|
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "y" << "[:";
|
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].y; }
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "info" << decoded_info;
|
|
|
|
file_config << "}";
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
file_config.release();
|
|
|
|
}
|
|
|
|
TEST(Objdetect_QRCode_Monitor, generate_test_data)
|
|
|
|
{
|
|
|
|
const std::string root = "qrcode/monitor/";
|
|
|
|
const std::string dataset_config = findDataFile(root + "dataset_config.json");
|
|
|
|
FileStorage file_config(dataset_config, FileStorage::WRITE);
|
|
|
|
|
|
|
|
file_config << "monitor_images" << "[";
|
|
|
|
size_t monitor_count = sizeof(qrcode_images_monitor) / sizeof(qrcode_images_monitor[0]);
|
|
|
|
for (size_t i = 0; i < monitor_count; i++)
|
|
|
|
{
|
|
|
|
file_config << "{:" << "image_name" << qrcode_images_monitor[i];
|
|
|
|
std::string image_path = findDataFile(root + qrcode_images_monitor[i]);
|
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE), barcode, straight_barcode;
|
|
|
|
std::string decoded_info;
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
const double min_side = std::min(src.size().width, src.size().height);
|
|
|
|
double coeff_expansion = 1024.0 / min_side;
|
|
|
|
const int width = cvRound(src.size().width * coeff_expansion);
|
|
|
|
const int height = cvRound(src.size().height * coeff_expansion);
|
|
|
|
Size new_size(width, height);
|
2022-09-29 04:52:24 +08:00
|
|
|
resize(src, barcode, new_size, 0, 0, INTER_LINEAR_EXACT);
|
2019-10-01 02:33:58 +08:00
|
|
|
EXPECT_TRUE(detectQRCode(barcode, corners));
|
|
|
|
EXPECT_TRUE(decodeQRCode(barcode, corners, decoded_info, straight_barcode));
|
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
```
2023-11-24 16:35:36 +08:00
|
|
|
|
2019-10-01 02:33:58 +08:00
|
|
|
file_config << "x" << "[:";
|
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "y" << "[:";
|
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].y; }
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "info" << decoded_info;
|
|
|
|
file_config << "}";
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
file_config.release();
|
|
|
|
}
|
2020-10-24 02:42:45 +08:00
|
|
|
TEST(Objdetect_QRCode_Curved, generate_test_data)
|
|
|
|
{
|
|
|
|
const std::string root = "qrcode/curved/";
|
|
|
|
const std::string dataset_config = findDataFile(root + "dataset_config.json");
|
|
|
|
FileStorage file_config(dataset_config, FileStorage::WRITE);
|
2019-10-01 02:33:58 +08:00
|
|
|
|
2020-10-24 02:42:45 +08:00
|
|
|
file_config << "test_images" << "[";
|
|
|
|
size_t images_count = sizeof(qrcode_images_curved) / sizeof(qrcode_images_curved[0]);
|
|
|
|
for (size_t i = 0; i < images_count; i++)
|
|
|
|
{
|
|
|
|
file_config << "{:" << "image_name" << qrcode_images_curved[i];
|
|
|
|
std::string image_path = findDataFile(root + qrcode_images_curved[i]);
|
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
|
|
|
|
std::string decoded_info;
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
EXPECT_TRUE(detectQRCode(src, corners));
|
|
|
|
EXPECT_TRUE(decodeCurvedQRCode(src, corners, decoded_info, straight_barcode));
|
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
```
2023-11-24 16:35:36 +08:00
|
|
|
|
2020-10-24 02:42:45 +08:00
|
|
|
file_config << "x" << "[:";
|
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].x; }
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "y" << "[:";
|
|
|
|
for (size_t j = 0; j < corners.size(); j++) { file_config << corners[j].y; }
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "info" << decoded_info;
|
|
|
|
file_config << "}";
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
file_config.release();
|
|
|
|
}
|
2020-01-27 03:18:42 +08:00
|
|
|
TEST(Objdetect_QRCode_Multi, generate_test_data)
|
|
|
|
{
|
|
|
|
const std::string root = "qrcode/multiple/";
|
|
|
|
const std::string dataset_config = findDataFile(root + "dataset_config.json");
|
|
|
|
FileStorage file_config(dataset_config, FileStorage::WRITE);
|
|
|
|
|
|
|
|
file_config << "multiple_images" << "[:";
|
|
|
|
size_t multiple_count = sizeof(qrcode_images_multiple) / sizeof(qrcode_images_multiple[0]);
|
|
|
|
for (size_t i = 0; i < multiple_count; i++)
|
|
|
|
{
|
|
|
|
file_config << "{:" << "image_name" << qrcode_images_multiple[i];
|
|
|
|
std::string image_path = findDataFile(root + qrcode_images_multiple[i]);
|
|
|
|
Mat src = imread(image_path);
|
|
|
|
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
std::vector<Point> corners;
|
2020-04-22 04:44:50 +08:00
|
|
|
QRCodeDetector qrcode;
|
|
|
|
EXPECT_TRUE(qrcode.detectMulti(src, corners));
|
2020-01-27 03:18:42 +08:00
|
|
|
std::vector<cv::String> decoded_info;
|
|
|
|
std::vector<Mat> straight_barcode;
|
2020-04-22 04:44:50 +08:00
|
|
|
EXPECT_TRUE(qrcode.decodeMulti(src, corners, decoded_info, straight_barcode));
|
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
```
2023-11-24 16:35:36 +08:00
|
|
|
|
2020-01-27 03:18:42 +08:00
|
|
|
file_config << "x" << "[:";
|
|
|
|
for(size_t j = 0; j < corners.size(); j += 4)
|
|
|
|
{
|
|
|
|
file_config << "[:";
|
|
|
|
for (size_t k = 0; k < 4; k++)
|
|
|
|
{
|
|
|
|
file_config << corners[j + k].x;
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "y" << "[:";
|
|
|
|
for(size_t j = 0; j < corners.size(); j += 4)
|
|
|
|
{
|
|
|
|
file_config << "[:";
|
|
|
|
for (size_t k = 0; k < 4; k++)
|
|
|
|
{
|
|
|
|
file_config << corners[j + k].y;
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "info";
|
|
|
|
file_config << "[:";
|
|
|
|
|
|
|
|
for(size_t j = 0; j < decoded_info.size(); j++)
|
|
|
|
{
|
|
|
|
file_config << decoded_info[j];
|
|
|
|
}
|
|
|
|
file_config << "]";
|
|
|
|
file_config << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
file_config << "]";
|
|
|
|
file_config.release();
|
|
|
|
}
|
|
|
|
|
2018-07-11 01:24:09 +08:00
|
|
|
#else
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
typedef testing::TestWithParam< std::string > Objdetect_QRCode;
|
2018-07-11 01:24:09 +08:00
|
|
|
TEST_P(Objdetect_QRCode, regression)
|
|
|
|
{
|
2018-07-24 18:08:58 +08:00
|
|
|
const std::string name_current_image = GetParam();
|
|
|
|
const std::string root = "qrcode/";
|
2018-07-11 01:24:09 +08:00
|
|
|
const int pixels_error = 3;
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
2018-08-18 00:01:02 +08:00
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
|
2018-07-24 18:08:58 +08:00
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
|
|
|
|
std::vector<Point> corners;
|
2018-08-18 00:01:02 +08:00
|
|
|
std::string decoded_info;
|
2018-11-09 17:57:27 +08:00
|
|
|
QRCodeDetector qrcode;
|
|
|
|
decoded_info = qrcode.detectAndDecode(src, corners, straight_barcode);
|
|
|
|
ASSERT_FALSE(corners.empty());
|
|
|
|
ASSERT_FALSE(decoded_info.empty());
|
2021-02-06 05:24:27 +08:00
|
|
|
int expected_barcode_type = CV_8UC1;
|
|
|
|
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
|
2023-06-02 21:18:24 +08:00
|
|
|
check_qr(root, name_current_image, "test_images", corners, {decoded_info}, pixels_error);
|
2018-07-11 01:24:09 +08:00
|
|
|
}
|
|
|
|
|
2019-10-01 02:33:58 +08:00
|
|
|
typedef testing::TestWithParam< std::string > Objdetect_QRCode_Close;
|
|
|
|
TEST_P(Objdetect_QRCode_Close, regression)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = GetParam();
|
|
|
|
const std::string root = "qrcode/close/";
|
|
|
|
const int pixels_error = 3;
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE), barcode, straight_barcode;
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
const double min_side = std::min(src.size().width, src.size().height);
|
|
|
|
double coeff_expansion = 1024.0 / min_side;
|
|
|
|
const int width = cvRound(src.size().width * coeff_expansion);
|
|
|
|
const int height = cvRound(src.size().height * coeff_expansion);
|
|
|
|
Size new_size(width, height);
|
2022-08-25 19:27:18 +08:00
|
|
|
resize(src, barcode, new_size, 0, 0, INTER_LINEAR_EXACT);
|
2019-10-01 02:33:58 +08:00
|
|
|
std::vector<Point> corners;
|
|
|
|
std::string decoded_info;
|
|
|
|
QRCodeDetector qrcode;
|
|
|
|
decoded_info = qrcode.detectAndDecode(barcode, corners, straight_barcode);
|
|
|
|
ASSERT_FALSE(corners.empty());
|
|
|
|
ASSERT_FALSE(decoded_info.empty());
|
2021-02-06 05:24:27 +08:00
|
|
|
int expected_barcode_type = CV_8UC1;
|
|
|
|
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
|
2023-06-02 21:18:24 +08:00
|
|
|
check_qr(root, name_current_image, "close_images", corners, {decoded_info}, pixels_error);
|
2019-10-01 02:33:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef testing::TestWithParam< std::string > Objdetect_QRCode_Monitor;
|
|
|
|
TEST_P(Objdetect_QRCode_Monitor, regression)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = GetParam();
|
|
|
|
const std::string root = "qrcode/monitor/";
|
|
|
|
const int pixels_error = 3;
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE), barcode, straight_barcode;
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
const double min_side = std::min(src.size().width, src.size().height);
|
|
|
|
double coeff_expansion = 1024.0 / min_side;
|
|
|
|
const int width = cvRound(src.size().width * coeff_expansion);
|
|
|
|
const int height = cvRound(src.size().height * coeff_expansion);
|
|
|
|
Size new_size(width, height);
|
2022-09-29 04:52:24 +08:00
|
|
|
resize(src, barcode, new_size, 0, 0, INTER_LINEAR_EXACT);
|
2019-10-01 02:33:58 +08:00
|
|
|
std::vector<Point> corners;
|
|
|
|
std::string decoded_info;
|
|
|
|
QRCodeDetector qrcode;
|
|
|
|
decoded_info = qrcode.detectAndDecode(barcode, corners, straight_barcode);
|
|
|
|
ASSERT_FALSE(corners.empty());
|
|
|
|
ASSERT_FALSE(decoded_info.empty());
|
2021-02-06 05:24:27 +08:00
|
|
|
int expected_barcode_type = CV_8UC1;
|
|
|
|
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
|
2023-06-02 21:18:24 +08:00
|
|
|
check_qr(root, name_current_image, "monitor_images", corners, {decoded_info}, pixels_error);
|
2019-10-01 02:33:58 +08:00
|
|
|
}
|
|
|
|
|
2020-10-24 02:42:45 +08:00
|
|
|
typedef testing::TestWithParam< std::string > Objdetect_QRCode_Curved;
|
|
|
|
TEST_P(Objdetect_QRCode_Curved, regression)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = GetParam();
|
|
|
|
const std::string root = "qrcode/curved/";
|
|
|
|
const int pixels_error = 3;
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
|
|
|
|
std::vector<Point> corners;
|
|
|
|
std::string decoded_info;
|
|
|
|
QRCodeDetector qrcode;
|
|
|
|
decoded_info = qrcode.detectAndDecodeCurved(src, corners, straight_barcode);
|
|
|
|
ASSERT_FALSE(corners.empty());
|
|
|
|
ASSERT_FALSE(decoded_info.empty());
|
2021-02-06 05:24:27 +08:00
|
|
|
int expected_barcode_type = CV_8UC1;
|
|
|
|
EXPECT_EQ(expected_barcode_type, straight_barcode.type());
|
2023-06-02 21:18:24 +08:00
|
|
|
check_qr(root, name_current_image, "test_images", corners, {decoded_info}, pixels_error);
|
2020-10-24 02:42:45 +08:00
|
|
|
}
|
|
|
|
|
2023-06-02 21:18:24 +08:00
|
|
|
typedef testing::TestWithParam<std::tuple<std::string, std::string>> Objdetect_QRCode_Multi;
|
2020-01-27 03:18:42 +08:00
|
|
|
TEST_P(Objdetect_QRCode_Multi, regression)
|
|
|
|
{
|
2023-06-02 21:18:24 +08:00
|
|
|
const std::string name_current_image = get<0>(GetParam());
|
2020-01-27 03:18:42 +08:00
|
|
|
const std::string root = "qrcode/multiple/";
|
2023-06-02 21:18:24 +08:00
|
|
|
const std::string method = get<1>(GetParam());
|
2022-12-15 04:56:57 +08:00
|
|
|
const int pixels_error = 4;
|
2020-01-27 03:18:42 +08:00
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path);
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
2023-06-02 21:18:24 +08:00
|
|
|
if (disabled_samples.find({name_current_image, method}) != disabled_samples.end())
|
|
|
|
throw SkipTestException(name_current_image + " is disabled sample for method " + method);
|
2023-06-08 19:50:58 +08:00
|
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
2023-06-02 21:18:24 +08:00
|
|
|
if (method == "aruco_based") {
|
|
|
|
qrcode = QRCodeDetectorAruco();
|
|
|
|
}
|
2020-01-27 03:18:42 +08:00
|
|
|
std::vector<Point> corners;
|
|
|
|
std::vector<cv::String> decoded_info;
|
|
|
|
std::vector<Mat> straight_barcode;
|
|
|
|
EXPECT_TRUE(qrcode.detectAndDecodeMulti(src, decoded_info, corners, straight_barcode));
|
|
|
|
ASSERT_FALSE(corners.empty());
|
|
|
|
ASSERT_FALSE(decoded_info.empty());
|
2021-02-06 05:24:27 +08:00
|
|
|
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());
|
2023-06-02 21:18:24 +08:00
|
|
|
check_qr(root, name_current_image, "multiple_images", corners, decoded_info, pixels_error, true);
|
2020-01-27 03:18:42 +08:00
|
|
|
}
|
|
|
|
|
2019-10-01 02:33:58 +08:00
|
|
|
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));
|
2020-10-24 02:42:45 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Curved, testing::ValuesIn(qrcode_images_curved));
|
2023-06-02 21:18:24 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Multi, testing::Combine(testing::ValuesIn(qrcode_images_multiple),
|
|
|
|
testing::Values("contours_based", "aruco_based")));
|
2018-07-24 18:08:58 +08:00
|
|
|
|
2020-02-05 00:31:11 +08:00
|
|
|
TEST(Objdetect_QRCode_decodeMulti, decode_regression_16491)
|
|
|
|
{
|
|
|
|
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)};
|
|
|
|
std::vector<Point> vec_corners;
|
|
|
|
int array_size = 8;
|
|
|
|
vec_corners.assign(corners_, corners_ + array_size);
|
|
|
|
std::vector<cv::String> decoded_info;
|
|
|
|
std::vector<Mat> straight_barcode;
|
|
|
|
QRCodeDetector vec_qrcode;
|
|
|
|
EXPECT_NO_THROW(vec_qrcode.decodeMulti(zero_image, vec_corners, decoded_info, straight_barcode));
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2023-06-02 21:18:24 +08:00
|
|
|
typedef testing::TestWithParam<std::string> Objdetect_QRCode_detectMulti;
|
|
|
|
TEST_P(Objdetect_QRCode_detectMulti, detect_regression_16961)
|
2020-04-22 04:44:50 +08:00
|
|
|
{
|
2023-06-02 21:18:24 +08:00
|
|
|
const std::string method = GetParam();
|
2020-04-22 04:44:50 +08:00
|
|
|
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;
|
|
|
|
|
2023-06-08 19:50:58 +08:00
|
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
2023-06-02 21:18:24 +08:00
|
|
|
if (method == "aruco_based") {
|
|
|
|
qrcode = QRCodeDetectorAruco();
|
|
|
|
}
|
2020-04-22 04:44:50 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-06-02 21:18:24 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_detectMulti, testing::Values("contours_based", "aruco_based"));
|
|
|
|
typedef testing::TestWithParam<std::string> Objdetect_QRCode_detectAndDecodeMulti;
|
|
|
|
TEST_P(Objdetect_QRCode_detectAndDecodeMulti, check_output_parameters_type_19363)
|
2021-02-06 05:24:27 +08:00
|
|
|
{
|
|
|
|
const std::string name_current_image = "9_qrcodes.jpg";
|
|
|
|
const std::string root = "qrcode/multiple/";
|
2023-06-02 21:18:24 +08:00
|
|
|
const std::string method = GetParam();
|
2021-02-06 05:24:27 +08:00
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path);
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
2023-06-08 19:50:58 +08:00
|
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
2023-06-02 21:18:24 +08:00
|
|
|
if (method == "aruco_based") {
|
|
|
|
qrcode = QRCodeDetectorAruco();
|
|
|
|
}
|
2021-02-06 05:24:27 +08:00
|
|
|
std::vector<Point> corners;
|
|
|
|
std::vector<cv::String> decoded_info;
|
|
|
|
#if 0 // FIXIT: OutputArray::create() type check
|
|
|
|
std::vector<Mat2b> straight_barcode_nchannels;
|
2023-06-02 21:18:24 +08:00
|
|
|
EXPECT_ANY_THROW(qrcode->detectAndDecodeMulti(src, decoded_info, corners, straight_barcode_nchannels));
|
2021-02-06 05:24:27 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int expected_barcode_type = CV_8UC1;
|
|
|
|
std::vector<Mat1b> straight_barcode;
|
|
|
|
EXPECT_TRUE(qrcode.detectAndDecodeMulti(src, decoded_info, corners, straight_barcode));
|
|
|
|
ASSERT_FALSE(corners.empty());
|
|
|
|
for(size_t i = 0; i < straight_barcode.size(); i++)
|
|
|
|
EXPECT_EQ(expected_barcode_type, straight_barcode[i].type());
|
|
|
|
}
|
2023-06-02 21:18:24 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_detectAndDecodeMulti, testing::Values("contours_based", "aruco_based"));
|
|
|
|
|
2021-02-06 05:24:27 +08:00
|
|
|
|
2021-11-04 01:04:27 +08:00
|
|
|
TEST(Objdetect_QRCode_detect, detect_regression_20882)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = "qrcode_near_the_end.jpg";
|
|
|
|
const std::string root = "qrcode/";
|
|
|
|
|
|
|
|
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;
|
|
|
|
Mat straight_barcode;
|
|
|
|
cv::String decoded_info;
|
|
|
|
EXPECT_TRUE(qrcode.detect(src, corners));
|
|
|
|
EXPECT_TRUE(!corners.empty());
|
|
|
|
EXPECT_NO_THROW(qrcode.decode(src, corners, straight_barcode));
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
TEST(Objdetect_QRCode_basic, not_found_qrcode)
|
2018-07-11 01:24:09 +08:00
|
|
|
{
|
2018-10-16 20:27:37 +08:00
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat straight_barcode;
|
2018-08-18 00:01:02 +08:00
|
|
|
std::string decoded_info;
|
2018-07-11 01:24:09 +08:00
|
|
|
Mat zero_image = Mat::zeros(256, 256, CV_8UC1);
|
2018-11-09 17:57:27 +08:00
|
|
|
QRCodeDetector qrcode;
|
|
|
|
EXPECT_FALSE(qrcode.detect(zero_image, corners));
|
2018-08-18 00:01:02 +08:00
|
|
|
corners = std::vector<Point>(4);
|
2018-11-09 17:57:27 +08:00
|
|
|
EXPECT_ANY_THROW(qrcode.decode(zero_image, corners, straight_barcode));
|
2018-07-11 01:24:09 +08:00
|
|
|
}
|
|
|
|
|
2022-06-04 22:33:08 +08:00
|
|
|
TEST(Objdetect_QRCode_detect, detect_regression_21287)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = "issue_21287.png";
|
|
|
|
const std::string root = "qrcode/";
|
|
|
|
|
|
|
|
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;
|
|
|
|
Mat straight_barcode;
|
|
|
|
cv::String decoded_info;
|
|
|
|
EXPECT_TRUE(qrcode.detect(src, corners));
|
|
|
|
EXPECT_TRUE(!corners.empty());
|
|
|
|
EXPECT_NO_THROW(qrcode.decode(src, corners, straight_barcode));
|
|
|
|
}
|
|
|
|
|
2023-02-19 06:17:47 +08:00
|
|
|
TEST(Objdetect_QRCode_detect_flipped, regression_23249)
|
|
|
|
{
|
|
|
|
|
|
|
|
const std::vector<std::pair<std::string, std::string>> flipped_images =
|
|
|
|
// image name , expected result
|
|
|
|
{{"flipped_1.png", "The key is /qrcod_OMevpf"},
|
|
|
|
{"flipped_2.png", "A26"}};
|
|
|
|
|
|
|
|
const std::string root = "qrcode/flipped/";
|
|
|
|
|
|
|
|
for(const auto &flipped_image : flipped_images){
|
|
|
|
const std::string &image_name = flipped_image.first;
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + image_name);
|
|
|
|
Mat src = imread(image_path);
|
|
|
|
ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
|
|
|
|
QRCodeDetector qrcode;
|
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat straight_barcode;
|
|
|
|
cv::String decoded_info;
|
|
|
|
EXPECT_TRUE(qrcode.detect(src, corners));
|
|
|
|
EXPECT_TRUE(!corners.empty());
|
|
|
|
std::string decoded_msg;
|
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
```
2023-11-24 16:35:36 +08:00
|
|
|
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);
|
2023-02-19 06:17:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-04 22:33:08 +08:00
|
|
|
// @author Kumataro, https://github.com/Kumataro
|
|
|
|
TEST(Objdetect_QRCode_decode, decode_regression_21929)
|
|
|
|
{
|
|
|
|
const cv::String expect_msg = "OpenCV";
|
|
|
|
Mat qrImg;
|
|
|
|
QRCodeEncoder::Params params;
|
|
|
|
params.version = 8; // 49x49
|
|
|
|
Ptr<QRCodeEncoder> qrcode_enc = cv::QRCodeEncoder::create(params);;
|
|
|
|
qrcode_enc->encode(expect_msg, qrImg);
|
|
|
|
|
|
|
|
Mat src;
|
|
|
|
cv::resize(qrImg, src, Size(200,200), 1.0, 1.0, INTER_NEAREST);
|
|
|
|
|
|
|
|
QRCodeDetector qrcode;
|
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat straight_barcode;
|
|
|
|
|
|
|
|
EXPECT_TRUE(qrcode.detect(src, corners));
|
|
|
|
EXPECT_TRUE(!corners.empty());
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Objdetect_QRCode_decode, decode_regression_version_25)
|
|
|
|
{
|
|
|
|
const cv::String expect_msg = "OpenCV";
|
|
|
|
Mat qrImg;
|
|
|
|
QRCodeEncoder::Params params;
|
|
|
|
params.version = 25; // 117x117
|
|
|
|
Ptr<QRCodeEncoder> qrcode_enc = cv::QRCodeEncoder::create(params);;
|
|
|
|
qrcode_enc->encode(expect_msg, qrImg);
|
2018-07-11 01:24:09 +08:00
|
|
|
|
2022-06-04 22:33:08 +08:00
|
|
|
Mat src;
|
|
|
|
cv::resize(qrImg, src, qrImg.size()*3, 1.0, 1.0, INTER_NEAREST);
|
|
|
|
|
|
|
|
QRCodeDetector qrcode;
|
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat straight_barcode;
|
|
|
|
|
|
|
|
EXPECT_TRUE(qrcode.detect(src, corners));
|
|
|
|
EXPECT_TRUE(!corners.empty());
|
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
```
2023-11-24 16:35:36 +08:00
|
|
|
|
2022-06-04 22:33:08 +08:00
|
|
|
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);
|
|
|
|
}
|
2018-07-24 18:08:58 +08:00
|
|
|
|
2023-06-02 21:18:24 +08:00
|
|
|
TEST_P(Objdetect_QRCode_detectAndDecodeMulti, decode_9_qrcodes_version7)
|
2022-12-15 04:56:57 +08:00
|
|
|
{
|
|
|
|
const std::string name_current_image = "9_qrcodes_version7.jpg";
|
|
|
|
const std::string root = "qrcode/multiple/";
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat src = imread(image_path);
|
2023-06-02 21:18:24 +08:00
|
|
|
const std::string method = GetParam();
|
2023-06-08 19:50:58 +08:00
|
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
2023-06-02 21:18:24 +08:00
|
|
|
if (method == "aruco_based") {
|
|
|
|
qrcode = QRCodeDetectorAruco();
|
|
|
|
}
|
2022-12-15 04:56:57 +08:00
|
|
|
std::vector<Point> corners;
|
|
|
|
std::vector<cv::String> decoded_info;
|
|
|
|
|
|
|
|
std::vector<Mat1b> straight_barcode;
|
|
|
|
qrcode.detectAndDecodeMulti(src, decoded_info, corners, straight_barcode);
|
|
|
|
EXPECT_EQ(9ull, decoded_info.size());
|
|
|
|
const string gold_info = "I love OpenCV, QR Code version = 7, error correction = level Quartile";
|
|
|
|
for (const auto& info : decoded_info) {
|
|
|
|
EXPECT_EQ(info, gold_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
#endif // UPDATE_QRCODE_TEST_DATA
|
|
|
|
|
2023-10-12 22:39:57 +08:00
|
|
|
TEST(Objdetect_QRCode_detectAndDecode, utf8_output)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = "umlaut.png";
|
|
|
|
const std::string root = "qrcode/";
|
|
|
|
|
|
|
|
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;
|
|
|
|
Mat straight;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-02-13 01:41:40 +08:00
|
|
|
TEST_P(Objdetect_QRCode_detectAndDecodeMulti, detect_regression_24679)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = "issue_24679.png";
|
|
|
|
const std::string root = "qrcode/";
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat img = imread(image_path);
|
|
|
|
const std::string method = GetParam();
|
|
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
|
|
|
if (method == "aruco_based") {
|
|
|
|
qrcode = QRCodeDetectorAruco();
|
|
|
|
}
|
|
|
|
std::vector<cv::String> decoded_info;
|
|
|
|
ASSERT_TRUE(qrcode.detectAndDecodeMulti(img, decoded_info));
|
|
|
|
EXPECT_EQ(decoded_info.size(), 4U);
|
|
|
|
}
|
|
|
|
|
2024-02-16 21:09:04 +08:00
|
|
|
TEST_P(Objdetect_QRCode_detectAndDecodeMulti, detect_regression_24011)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = "issue_24011.jpg";
|
|
|
|
const std::string root = "qrcode/";
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat img = imread(image_path);
|
|
|
|
const std::string method = GetParam();
|
|
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
|
|
|
if (method == "aruco_based") {
|
|
|
|
qrcode = QRCodeDetectorAruco();
|
|
|
|
}
|
|
|
|
std::vector<cv::String> decoded_info;
|
|
|
|
ASSERT_TRUE(qrcode.detectAndDecodeMulti(img, decoded_info));
|
|
|
|
EXPECT_EQ(decoded_info.size(), 2U);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Objdetect_QRCode_detect, detect_regression_24450)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = "issue_24450.png";
|
|
|
|
const std::string root = "qrcode/";
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat img = imread(image_path);
|
|
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
|
|
|
std::vector<Point2f> points;
|
|
|
|
ASSERT_TRUE(qrcode.detect(img, points));
|
|
|
|
EXPECT_EQ(points.size(), 4U);
|
|
|
|
img.at<Vec3b>(img.rows - 1, 296) = {};
|
|
|
|
ASSERT_TRUE(qrcode.detect(img, points));
|
|
|
|
EXPECT_EQ(points.size(), 4U);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Objdetect_QRCode_detect, detect_regression_22892)
|
|
|
|
{
|
|
|
|
const std::string name_current_image = "issue_22892.png";
|
|
|
|
const std::string root = "qrcode/";
|
|
|
|
|
|
|
|
std::string image_path = findDataFile(root + name_current_image);
|
|
|
|
Mat img = imread(image_path);
|
|
|
|
|
|
|
|
QRCodeDetector qrcode;
|
|
|
|
std::vector<Point> corners;
|
|
|
|
Mat straight_code;
|
|
|
|
qrcode.detectAndDecodeCurved(img, corners, straight_code);
|
|
|
|
EXPECT_EQ(corners.size(), 4U);
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:08:58 +08:00
|
|
|
}} // namespace
|