mirror of
https://github.com/opencv/opencv.git
synced 2024-12-12 15:19:11 +08:00
d296d29a1c
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 ```
203 lines
7.2 KiB
C++
203 lines
7.2 KiB
C++
// 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.
|
|
|
|
#include "perf_precomp.hpp"
|
|
#include "../test/test_qr_utils.hpp"
|
|
|
|
namespace opencv_test
|
|
{
|
|
namespace
|
|
{
|
|
|
|
typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode;
|
|
|
|
PERF_TEST_P_(Perf_Objdetect_QRCode, detect)
|
|
{
|
|
const std::string name_current_image = GetParam();
|
|
const std::string root = "cv/qrcode/";
|
|
|
|
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;
|
|
QRCodeDetector qrcode;
|
|
TEST_CYCLE() ASSERT_TRUE(qrcode.detect(src, corners));
|
|
const int pixels_error = 3;
|
|
check_qr(root, name_current_image, "test_images", corners, {}, pixels_error);
|
|
SANITY_CHECK_NOTHING();
|
|
}
|
|
|
|
PERF_TEST_P_(Perf_Objdetect_QRCode, decode)
|
|
{
|
|
const std::string name_current_image = GetParam();
|
|
const std::string root = "cv/qrcode/";
|
|
|
|
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;
|
|
ASSERT_TRUE(qrcode.detect(src, corners));
|
|
TEST_CYCLE()
|
|
{
|
|
decoded_info = qrcode.decode(src, corners, straight_barcode);
|
|
ASSERT_FALSE(decoded_info.empty());
|
|
}
|
|
const int pixels_error = 3;
|
|
check_qr(root, name_current_image, "test_images", corners, {decoded_info}, pixels_error);
|
|
SANITY_CHECK_NOTHING();
|
|
}
|
|
|
|
typedef ::perf::TestBaseWithParam<std::tuple<std::string, std::string>> Perf_Objdetect_QRCode_Multi;
|
|
|
|
static std::set<std::pair<std::string, std::string>> disabled_samples = {{"5_qrcodes.png", "aruco_based"}};
|
|
|
|
PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, detectMulti)
|
|
{
|
|
const std::string name_current_image = get<0>(GetParam());
|
|
const std::string method = get<1>(GetParam());
|
|
const std::string root = "cv/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<Point> corners;
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
|
if (method == "aruco_based") {
|
|
qrcode = QRCodeDetectorAruco();
|
|
}
|
|
TEST_CYCLE() ASSERT_TRUE(qrcode.detectMulti(src, corners));
|
|
const int pixels_error = 7;
|
|
check_qr(root, name_current_image, "multiple_images", corners, {}, pixels_error, true);
|
|
SANITY_CHECK_NOTHING();
|
|
}
|
|
|
|
PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, decodeMulti)
|
|
{
|
|
const std::string name_current_image = get<0>(GetParam());
|
|
std::string method = get<1>(GetParam());
|
|
const std::string root = "cv/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;
|
|
if (disabled_samples.find({name_current_image, method}) != disabled_samples.end()) {
|
|
throw SkipTestException(name_current_image + " is disabled sample for method " + method);
|
|
}
|
|
GraphicalCodeDetector qrcode = QRCodeDetector();
|
|
if (method == "aruco_based") {
|
|
qrcode = QRCodeDetectorAruco();
|
|
}
|
|
std::vector<Point2f> corners;
|
|
ASSERT_TRUE(qrcode.detectMulti(src, corners));
|
|
std::vector<Mat> straight_barcode;
|
|
std::vector< cv::String > decoded_info;
|
|
TEST_CYCLE()
|
|
{
|
|
ASSERT_TRUE(qrcode.decodeMulti(src, corners, decoded_info, straight_barcode));
|
|
}
|
|
ASSERT_TRUE(decoded_info.size() > 0ull);
|
|
for(size_t i = 0; i < decoded_info.size(); i++) {
|
|
ASSERT_FALSE(decoded_info[i].empty());
|
|
}
|
|
ASSERT_EQ(decoded_info.size(), straight_barcode.size());
|
|
vector<Point> corners_result(corners.size());
|
|
for (size_t i = 0ull; i < corners_result.size(); i++) {
|
|
corners_result[i] = corners[i];
|
|
}
|
|
|
|
const int pixels_error = 7;
|
|
check_qr(root, name_current_image, "multiple_images", corners_result, decoded_info, pixels_error, true);
|
|
SANITY_CHECK_NOTHING();
|
|
}
|
|
|
|
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode,
|
|
::testing::Values(
|
|
"version_1_down.jpg", "version_1_left.jpg", "version_1_right.jpg", "version_1_up.jpg", "version_1_top.jpg",
|
|
"version_5_down.jpg", "version_5_left.jpg",/*version_5_right.jpg*/ "version_5_up.jpg", "version_5_top.jpg",
|
|
"russian.jpg", "kanji.jpg", "link_github_ocv.jpg", "link_ocv.jpg", "link_wiki_cv.jpg"
|
|
)
|
|
);
|
|
// version_5_right.jpg DISABLED after tile fix, PR #22025
|
|
|
|
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode_Multi,
|
|
testing::Combine(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"),
|
|
testing::Values("contours_based", "aruco_based")));
|
|
|
|
|
|
typedef ::perf::TestBaseWithParam< tuple< std::string, Size > > Perf_Objdetect_Not_QRCode;
|
|
|
|
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect)
|
|
{
|
|
std::vector<Point> corners;
|
|
std::string type_gen = get<0>(GetParam());
|
|
Size resolution = get<1>(GetParam());
|
|
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
|
|
if (type_gen == "random")
|
|
{
|
|
RNG rng;
|
|
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
|
|
}
|
|
if (type_gen == "chessboard")
|
|
{
|
|
uint8_t next_pixel = 0;
|
|
for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
|
|
{
|
|
int i = r / not_qr_code.cols;
|
|
int j = r % not_qr_code.cols;
|
|
not_qr_code.ptr<uchar>(i)[j] = next_pixel;
|
|
next_pixel = 255 - next_pixel;
|
|
}
|
|
}
|
|
|
|
QRCodeDetector qrcode;
|
|
TEST_CYCLE() ASSERT_FALSE(qrcode.detect(not_qr_code, corners));
|
|
SANITY_CHECK_NOTHING();
|
|
}
|
|
|
|
PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode)
|
|
{
|
|
Mat straight_barcode;
|
|
std::vector< Point > corners;
|
|
corners.push_back(Point( 0, 0)); corners.push_back(Point( 0, 5));
|
|
corners.push_back(Point(10, 0)); corners.push_back(Point(15, 15));
|
|
|
|
std::string type_gen = get<0>(GetParam());
|
|
Size resolution = get<1>(GetParam());
|
|
Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
|
|
if (type_gen == "random")
|
|
{
|
|
RNG rng;
|
|
rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
|
|
}
|
|
if (type_gen == "chessboard")
|
|
{
|
|
uint8_t next_pixel = 0;
|
|
for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
|
|
{
|
|
int i = r / not_qr_code.cols;
|
|
int j = r % not_qr_code.cols;
|
|
not_qr_code.ptr<uchar>(i)[j] = next_pixel;
|
|
next_pixel = 255 - next_pixel;
|
|
}
|
|
}
|
|
|
|
QRCodeDetector qrcode;
|
|
TEST_CYCLE() ASSERT_TRUE(qrcode.decode(not_qr_code, corners, straight_barcode).empty());
|
|
SANITY_CHECK_NOTHING();
|
|
}
|
|
|
|
INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode,
|
|
::testing::Combine(
|
|
::testing::Values("zero", "random", "chessboard"),
|
|
::testing::Values(Size(640, 480), Size(1280, 720),
|
|
Size(1920, 1080), Size(3840, 2160))
|
|
));
|
|
|
|
}
|
|
} // namespace
|