mirror of
https://github.com/opencv/opencv.git
synced 2026-07-25 13:23:02 +04:00
Merge pull request #24548 from dkurt:qrcode_struct_append_decode
QR codes Structured Append decoding mode #24548 ### Pull Request Readiness Checklist resolves https://github.com/opencv/opencv/issues/23245 Merge after https://github.com/opencv/opencv/pull/24299 Current proposal is to use `detectAndDecodeMulti` or `decodeMulti` for structured append mode decoding. 0-th QR code in a sequence gets a full message while the rest of codes will correspond to empty strings. See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -349,7 +349,7 @@ TEST(Objdetect_QRCode_Encode_Kanji, regression)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Objdetect_QRCode_Encode_Decode_Structured_Append, DISABLED_regression)
|
||||
TEST(Objdetect_QRCode_Encode_Decode_Structured_Append, regression)
|
||||
{
|
||||
// disabled since QR decoder probably doesn't support structured append mode qr codes
|
||||
const std::string root = "qrcode/decode_encode";
|
||||
@@ -385,35 +385,43 @@ TEST(Objdetect_QRCode_Encode_Decode_Structured_Append, DISABLED_regression)
|
||||
vector<Mat> qrcodes;
|
||||
encoder->encodeStructuredAppend(input_info, qrcodes);
|
||||
EXPECT_TRUE(!qrcodes.empty()) << "Can't generate this QR images";
|
||||
CV_CheckEQ(qrcodes.size(), (size_t)j, "Number of QR codes");
|
||||
|
||||
std::string output_info = "";
|
||||
std::vector<Point2f> corners(4 * qrcodes.size());
|
||||
for (size_t k = 0; k < qrcodes.size(); k++)
|
||||
{
|
||||
Mat qrcode = qrcodes[k];
|
||||
corners[4 * k] = Point2f(border_width, border_width);
|
||||
corners[4 * k + 1] = Point2f(qrcode.cols * 1.0f - border_width, border_width);
|
||||
corners[4 * k + 2] = Point2f(qrcode.cols * 1.0f - border_width, qrcode.rows * 1.0f - border_width);
|
||||
corners[4 * k + 3] = Point2f(border_width, qrcode.rows * 1.0f - border_width);
|
||||
|
||||
std::vector<Point2f> corners(4);
|
||||
corners[0] = Point2f(border_width, border_width);
|
||||
corners[1] = Point2f(qrcode.cols * 1.0f - border_width, border_width);
|
||||
corners[2] = Point2f(qrcode.cols * 1.0f - border_width, qrcode.rows * 1.0f - border_width);
|
||||
corners[3] = Point2f(border_width, qrcode.rows * 1.0f - border_width);
|
||||
float width_ratio = fixed_size.width * 1.0f / qrcode.cols;
|
||||
float height_ratio = fixed_size.height * 1.0f / qrcode.rows;
|
||||
resize(qrcode, qrcodes[k], fixed_size, 0, 0, INTER_AREA);
|
||||
|
||||
Mat resized_src;
|
||||
resize(qrcode, resized_src, fixed_size, 0, 0, INTER_AREA);
|
||||
float width_ratio = resized_src.cols * 1.0f / qrcode.cols;
|
||||
float height_ratio = resized_src.rows * 1.0f / qrcode.rows;
|
||||
for(size_t m = 0; m < corners.size(); m++)
|
||||
for (size_t ki = 0; ki < 4; ki++)
|
||||
{
|
||||
corners[m].x = corners[m].x * width_ratio;
|
||||
corners[m].y = corners[m].y * height_ratio;
|
||||
corners[4 * k + ki].x = corners[4 * k + ki].x * width_ratio + fixed_size.width * k;
|
||||
corners[4 * k + ki].y = corners[4 * k + ki].y * height_ratio;
|
||||
}
|
||||
|
||||
Mat straight_barcode;
|
||||
std::string decoded_info = QRCodeDetector().decode(resized_src, corners, straight_barcode);
|
||||
EXPECT_FALSE(decoded_info.empty())
|
||||
<< "The generated QRcode cannot be decoded." << " Mode: " << modes[i]
|
||||
<< " structures number: " << k << "/" << j;
|
||||
output_info += decoded_info;
|
||||
}
|
||||
|
||||
Mat resized_src;
|
||||
hconcat(qrcodes, resized_src);
|
||||
|
||||
std::vector<cv::String> decoded_info;
|
||||
cv::String output_info;
|
||||
EXPECT_TRUE(QRCodeDetector().decodeMulti(resized_src, corners, decoded_info));
|
||||
for (size_t k = 0; k < decoded_info.size(); ++k)
|
||||
{
|
||||
if (!decoded_info[k].empty())
|
||||
output_info = decoded_info[k];
|
||||
}
|
||||
EXPECT_FALSE(output_info.empty())
|
||||
<< "The generated QRcode cannot be decoded." << " Mode: " << modes[i]
|
||||
<< " structures number: " << j;
|
||||
|
||||
EXPECT_EQ(input_info, output_info) << "The generated QRcode is not same as test data." << " Mode: " << mode <<
|
||||
" structures number: " << j;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user