Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrPanov committed Aug 8, 2022
1 parent ee9ef17 commit 97a44dc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/wechat_qrcode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(the_description "WeChat QR code Detector")
ocv_define_module(wechat_qrcode opencv_core opencv_imgproc opencv_dnn WRAP java objc python js)
ocv_define_module(wechat_qrcode opencv_core opencv_imgproc opencv_objdetect opencv_dnn WRAP java objc python js)

# iconv support isn't automatic on some systems
if(CMAKE_VERSION VERSION_GREATER "3.11")
Expand Down
33 changes: 33 additions & 0 deletions modules/wechat_qrcode/test/test_qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.

#include "test_precomp.hpp"
#include "opencv2/objdetect.hpp"

namespace opencv_test {
namespace {
Expand Down Expand Up @@ -289,5 +290,37 @@ INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Monitor, testing::ValuesIn(qrcode
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Curved, testing::ValuesIn(qrcode_images_curved));
// INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Multi, testing::ValuesIn(qrcode_images_multiple));

TEST(Objdetect_QRCode_Big, regression) {
string path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel;
string model_version = "_2021-01";
path_detect_prototxt = findDataFile("../dnn/wechat"+model_version+"/detect.prototxt", false);
path_detect_caffemodel = findDataFile("../dnn/wechat"+model_version+"/detect.caffemodel", false);
path_sr_prototxt = findDataFile("../dnn/wechat"+model_version+"/sr.prototxt", false);
path_sr_caffemodel = findDataFile("../dnn/wechat"+model_version+"/sr.caffemodel", false);

auto detector = wechat_qrcode::WeChatQRCode(path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt,
path_sr_caffemodel);

const cv::String expect_msg = "OpenCV";
QRCodeEncoder::Params params;
params.version = 4; // 33x33
Ptr<QRCodeEncoder> qrcode_enc = cv::QRCodeEncoder::create(params);
Mat qrImage;
qrcode_enc->encode(expect_msg, qrImage);
Mat largeImage(4032, 3024, CV_8UC1);
const int pixInBlob = 4;
Size qrSize = Size((21+(params.version-1)*4)*pixInBlob,(21+(params.version-1)*4)*pixInBlob);
Mat roiImage = largeImage(Rect((largeImage.cols - qrSize.width)/2, (largeImage.rows - qrSize.height)/2,
qrSize.width, qrSize.height));
cv::resize(qrImage, roiImage, qrSize, 1., 1., INTER_NEAREST);

vector<Mat> points;
detector.setScaleFactor(0.25f);
auto decoded_info = detector.detectAndDecode(largeImage, points);
ASSERT_EQ(1ull, decoded_info.size());
ASSERT_EQ(expect_msg, decoded_info[0]);
}


} // namespace
} // namespace opencv_test

0 comments on commit 97a44dc

Please sign in to comment.