Skip to content

Commit

Permalink
remove upscale, add tiny qr test
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrPanov committed Sep 12, 2022
1 parent 971685c commit 4476b9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/wechat_qrcode/src/wechat_qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int WeChatQRCode::Impl::applyDetector(const Mat& img, vector<Mat>& points) {

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

Expand Down
29 changes: 29 additions & 0 deletions modules/wechat_qrcode/test/test_qrcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,35 @@ TEST(Objdetect_QRCode_Big, regression) {
ASSERT_EQ(expect_msg, decoded_info[0]);
}

TEST(Objdetect_QRCode_Tiny, 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 tinyImage(80, 80, CV_8UC1);
const int pixInBlob = 2;
Size qrSize = Size((21+(params.version-1)*4)*pixInBlob,(21+(params.version-1)*4)*pixInBlob);
Mat roiImage = tinyImage(Rect((tinyImage.cols - qrSize.width)/2, (tinyImage.rows - qrSize.height)/2,
qrSize.width, qrSize.height));
cv::resize(qrImage, roiImage, qrSize, 1., 1., INTER_NEAREST);

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

} // namespace
} // namespace opencv_test

0 comments on commit 4476b9b

Please sign in to comment.