Skip to content

Commit 4476b9b

Browse files
author
AleksandrPanov
committed
remove upscale, add tiny qr test
1 parent 971685c commit 4476b9b

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

modules/wechat_qrcode/src/wechat_qrcode.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int WeChatQRCode::Impl::applyDetector(const Mat& img, vector<Mat>& points) {
197197

198198
const float targetArea = 400.f * 400.f;
199199
// hard code input size
200-
const float tmpScaleFactor = scaleFactor == -1.f ? sqrt(targetArea / (img_w * img_h)) : scaleFactor;
200+
const float tmpScaleFactor = scaleFactor == -1.f ? min(1.f, sqrt(targetArea / (img_w * img_h))) : scaleFactor;
201201
int detect_width = img_w * tmpScaleFactor;
202202
int detect_height = img_h * tmpScaleFactor;
203203

modules/wechat_qrcode/test/test_qrcode.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,35 @@ TEST(Objdetect_QRCode_Big, regression) {
376376
ASSERT_EQ(expect_msg, decoded_info[0]);
377377
}
378378

379+
TEST(Objdetect_QRCode_Tiny, regression) {
380+
string path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel;
381+
string model_version = "_2021-01";
382+
path_detect_prototxt = findDataFile("dnn/wechat"+model_version+"/detect.prototxt", false);
383+
path_detect_caffemodel = findDataFile("dnn/wechat"+model_version+"/detect.caffemodel", false);
384+
path_sr_prototxt = findDataFile("dnn/wechat"+model_version+"/sr.prototxt", false);
385+
path_sr_caffemodel = findDataFile("dnn/wechat"+model_version+"/sr.caffemodel", false);
386+
387+
auto detector = wechat_qrcode::WeChatQRCode(path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt,
388+
path_sr_caffemodel);
389+
390+
const cv::String expect_msg = "OpenCV";
391+
QRCodeEncoder::Params params;
392+
params.version = 4; // 33x33
393+
Ptr<QRCodeEncoder> qrcode_enc = cv::QRCodeEncoder::create(params);
394+
Mat qrImage;
395+
qrcode_enc->encode(expect_msg, qrImage);
396+
Mat tinyImage(80, 80, CV_8UC1);
397+
const int pixInBlob = 2;
398+
Size qrSize = Size((21+(params.version-1)*4)*pixInBlob,(21+(params.version-1)*4)*pixInBlob);
399+
Mat roiImage = tinyImage(Rect((tinyImage.cols - qrSize.width)/2, (tinyImage.rows - qrSize.height)/2,
400+
qrSize.width, qrSize.height));
401+
cv::resize(qrImage, roiImage, qrSize, 1., 1., INTER_NEAREST);
402+
403+
vector<Mat> points;
404+
auto decoded_info = detector.detectAndDecode(tinyImage, points);
405+
ASSERT_EQ(1ull, decoded_info.size());
406+
ASSERT_EQ(expect_msg, decoded_info[0]);
407+
}
379408

380409
} // namespace
381410
} // namespace opencv_test

0 commit comments

Comments
 (0)