Skip to content

Commit cfcfd5f

Browse files
author
AleksandrPanov
committed
add multi detect test
1 parent 14157b1 commit cfcfd5f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

modules/wechat_qrcode/test/test_qrcode.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,5 +408,52 @@ TEST(Objdetect_QRCode_Tiny, regression) {
408408
ASSERT_EQ(expect_msg, decoded_info[0]);
409409
}
410410

411+
412+
typedef testing::TestWithParam<std::string> Objdetect_QRCode_Easy_Multi;
413+
TEST_P(Objdetect_QRCode_Easy_Multi, regression) {
414+
string path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel;
415+
string model_path = GetParam();
416+
417+
if (!model_path.empty()) {
418+
path_detect_prototxt = findDataFile(model_path + "/detect.prototxt", false);
419+
path_detect_caffemodel = findDataFile(model_path + "/detect.caffemodel", false);
420+
path_sr_prototxt = findDataFile(model_path + "/sr.prototxt", false);
421+
path_sr_caffemodel = findDataFile(model_path + "/sr.caffemodel", false);
422+
}
423+
424+
auto detector = wechat_qrcode::WeChatQRCode(path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt,
425+
path_sr_caffemodel);
426+
427+
const cv::String expect_msg1 = "OpenCV1", expect_msg2 = "OpenCV2";
428+
QRCodeEncoder::Params params;
429+
params.version = 4; // 33x33
430+
Ptr<QRCodeEncoder> qrcode_enc = cv::QRCodeEncoder::create(params);
431+
Mat qrImage1, qrImage2;
432+
qrcode_enc->encode(expect_msg1, qrImage1);
433+
qrcode_enc->encode(expect_msg2, qrImage2);
434+
const int pixInBlob = 2;
435+
const int offset = 14;
436+
const int qr_size = (params.version - 1) * 4 + 21;
437+
Mat tinyImage = Mat::zeros(qr_size*pixInBlob+offset, (qr_size*pixInBlob+offset)*2, CV_8UC1);
438+
Size qrSize = Size(qrImage1.cols, qrImage1.rows);
439+
440+
Mat roiImage = tinyImage(Rect((tinyImage.cols/2 - qrSize.width)/2, (tinyImage.rows - qrSize.height)/2,
441+
qrSize.width, qrSize.height));
442+
cv::resize(qrImage1, roiImage, qrSize, 1., 1., INTER_NEAREST);
443+
444+
roiImage = tinyImage(Rect((tinyImage.cols/2 - qrSize.width)/2+tinyImage.cols/2, (tinyImage.rows - qrSize.height)/2,
445+
qrSize.width, qrSize.height));
446+
cv::resize(qrImage2, roiImage, qrSize, 1., 1., INTER_NEAREST);
447+
448+
vector<Mat> points;
449+
auto decoded_info = detector.detectAndDecode(tinyImage, points);
450+
ASSERT_EQ(2ull, decoded_info.size());
451+
ASSERT_TRUE((expect_msg1 == decoded_info[0] && expect_msg2 == decoded_info[1]) ||
452+
(expect_msg1 == decoded_info[1] && expect_msg2 == decoded_info[0]));
453+
}
454+
455+
std::string qrcode_model_path[] = {"", "dnn/wechat_2021-01"};
456+
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Easy_Multi, testing::ValuesIn(qrcode_model_path));
457+
411458
} // namespace
412459
} // namespace opencv_test

0 commit comments

Comments
 (0)