|
|
|
@ -284,6 +284,58 @@ TEST_P(Objdetect_QRCode_Multi, regression) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(Objdetect_QRCode_points_position, rotate45) { |
|
|
|
|
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 = 5; // 37x37
|
|
|
|
|
Ptr<QRCodeEncoder> qrcode_enc = cv::QRCodeEncoder::create(params); |
|
|
|
|
Mat qrImage; |
|
|
|
|
qrcode_enc->encode(expect_msg, qrImage); |
|
|
|
|
Mat image(800, 800, CV_8UC1); |
|
|
|
|
const int pixInBlob = 4; |
|
|
|
|
Size qrSize = Size((21+(params.version-1)*4)*pixInBlob,(21+(params.version-1)*4)*pixInBlob); |
|
|
|
|
Rect2f rec((image.cols - qrSize.width)/2, (image.rows - qrSize.height)/2, qrSize.width, qrSize.height); |
|
|
|
|
vector<float> goldCorners = {rec.x, rec.y, |
|
|
|
|
rec.x+rec.width, rec.y, |
|
|
|
|
rec.x+rec.width, rec.y+rec.height, |
|
|
|
|
rec.x, rec.y+rec.height}; |
|
|
|
|
Mat roiImage = image(rec); |
|
|
|
|
cv::resize(qrImage, roiImage, qrSize, 1., 1., INTER_NEAREST); |
|
|
|
|
|
|
|
|
|
vector<Mat> points1; |
|
|
|
|
auto decoded_info1 = detector.detectAndDecode(image, points1); |
|
|
|
|
ASSERT_EQ(1ull, decoded_info1.size()); |
|
|
|
|
ASSERT_EQ(expect_msg, decoded_info1[0]); |
|
|
|
|
EXPECT_NEAR(0, cvtest::norm(Mat(goldCorners), points1[0].reshape(1, 8), NORM_INF), 8.); |
|
|
|
|
|
|
|
|
|
const double angle = 45; |
|
|
|
|
Point2f pc(image.cols/2.f, image.rows/2.f); |
|
|
|
|
Mat rot = getRotationMatrix2D(pc, angle, 1.); |
|
|
|
|
warpAffine(image, image, rot, image.size()); |
|
|
|
|
vector<float> rotateGoldCorners; |
|
|
|
|
for (int i = 0; i < static_cast<int>(goldCorners.size()); i+= 2) { |
|
|
|
|
rotateGoldCorners.push_back(rot.at<double>(0, 0) * goldCorners[i] + |
|
|
|
|
rot.at<double>(0, 1) * goldCorners[i+1] + rot.at<double>(0, 2)); |
|
|
|
|
rotateGoldCorners.push_back(rot.at<double>(1, 0) * goldCorners[i] + |
|
|
|
|
rot.at<double>(1, 1) * goldCorners[i+1] + rot.at<double>(1, 2)); |
|
|
|
|
} |
|
|
|
|
vector<Mat> points2; |
|
|
|
|
auto decoded_info2 = detector.detectAndDecode(image, points2); |
|
|
|
|
ASSERT_EQ(1ull, decoded_info2.size()); |
|
|
|
|
ASSERT_EQ(expect_msg, decoded_info2[0]); |
|
|
|
|
EXPECT_NEAR(0, cvtest::norm(Mat(rotateGoldCorners), points2[0].reshape(1, 8), NORM_INF), 11.); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode, testing::ValuesIn(qrcode_images_name)); |
|
|
|
|
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Close, testing::ValuesIn(qrcode_images_close)); |
|
|
|
|
INSTANTIATE_TEST_CASE_P(/**/, Objdetect_QRCode_Monitor, testing::ValuesIn(qrcode_images_monitor)); |
|
|
|
|