Merge pull request #22030 from Kumataro:3.4-fix22029

* objdetect: qrcode_encoder: fix to missing timing pattern

* objdetect: qrcode_encoder: Add SCOPED_TRACE() and replace CV_Assert() to ASSERT_EQ().

- Add SCOPED_TRACE() for version loop.

- Replace CV_Assert() to ASSERT_EQ().

- Rename expect_msg to msg.
This commit is contained in:
Kumataro 2022-05-31 19:58:17 +09:00 committed by GitHub
parent 8d51ef0f35
commit 1a24e316d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 1 deletions

View File

@ -975,7 +975,7 @@ void QRCodeEncoderImpl::writeReservedArea()
original.at<uint8_t>(x, y) = INVALID_REGION_VALUE;
if (version_level >= 7)
{
for (int i = 0; i <= 6; i++)
for (int i = 0; i <= 5; i++)
{
for (int j = version_size - 11; j <= version_size - 8; j++)
{

View File

@ -430,4 +430,82 @@ TEST(Objdetect_QRCode_Encode_Decode_Structured_Append, DISABLED_regression)
#endif // UPDATE_QRCODE_TEST_DATA
TEST(Objdetect_QRCode_Encode_Decode, regression_issue22029)
{
const cv::String msg = "OpenCV";
const int min_version = 1;
const int max_version = 40;
for ( int v = min_version ; v <= max_version ; v++ )
{
SCOPED_TRACE(cv::format("version=%d",v));
Mat qrimg;
QRCodeEncoder::Params params;
params.version = v;
Ptr<QRCodeEncoder> qrcode_enc = cv::QRCodeEncoder::create(params);
qrcode_enc->encode(msg, qrimg);
const int white_margin = 2;
const int finder_width = 7;
const int timing_pos = white_margin + 6;
int i;
// Horizontal Check
// (1) White margin(Left)
for(i = 0; i < white_margin ; i++ )
{
ASSERT_EQ((uint8_t)255, qrimg.at<uint8_t>(i, timing_pos)) << "i=" << i;
}
// (2) Finder pattern(Left)
for( ; i < white_margin + finder_width ; i++ )
{
ASSERT_EQ((uint8_t)0, qrimg.at<uint8_t>(i, timing_pos)) << "i=" << i;
}
// (3) Timing pattern
for( ; i < qrimg.rows - finder_width - white_margin; i++ )
{
ASSERT_EQ((uint8_t)(i % 2 == 0)?0:255, qrimg.at<uint8_t>(i, timing_pos)) << "i=" << i;
}
// (4) Finder pattern(Right)
for( ; i < qrimg.rows - white_margin; i++ )
{
ASSERT_EQ((uint8_t)0, qrimg.at<uint8_t>(i, timing_pos)) << "i=" << i;
}
// (5) White margin(Right)
for( ; i < qrimg.rows ; i++ )
{
ASSERT_EQ((uint8_t)255, qrimg.at<uint8_t>(i, timing_pos)) << "i=" << i;
}
// Vertical Check
// (1) White margin(Top)
for(i = 0; i < white_margin ; i++ )
{
ASSERT_EQ((uint8_t)255, qrimg.at<uint8_t>(timing_pos, i)) << "i=" << i;
}
// (2) Finder pattern(Top)
for( ; i < white_margin + finder_width ; i++ )
{
ASSERT_EQ((uint8_t)0, qrimg.at<uint8_t>(timing_pos, i)) << "i=" << i;
}
// (3) Timing pattern
for( ; i < qrimg.rows - finder_width - white_margin; i++ )
{
ASSERT_EQ((uint8_t)(i % 2 == 0)?0:255, qrimg.at<uint8_t>(timing_pos, i)) << "i=" << i;
}
// (4) Finder pattern(Bottom)
for( ; i < qrimg.rows - white_margin; i++ )
{
ASSERT_EQ((uint8_t)0, qrimg.at<uint8_t>(timing_pos, i)) << "i=" << i;
}
// (5) White margin(Bottom)
for( ; i < qrimg.rows ; i++ )
{
ASSERT_EQ((uint8_t)255, qrimg.at<uint8_t>(timing_pos, i)) << "i=" << i;
}
}
}
}} // namespace