@@ -284,6 +284,58 @@ TEST_P(Objdetect_QRCode_Multi, regression) {
284
284
}
285
285
}
286
286
287
+ TEST (Objdetect_QRCode_points_position, rotate45) {
288
+ string path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt, path_sr_caffemodel;
289
+ string model_version = " _2021-01" ;
290
+ path_detect_prototxt = findDataFile (" dnn/wechat" +model_version+" /detect.prototxt" , false );
291
+ path_detect_caffemodel = findDataFile (" dnn/wechat" +model_version+" /detect.caffemodel" , false );
292
+ path_sr_prototxt = findDataFile (" dnn/wechat" +model_version+" /sr.prototxt" , false );
293
+ path_sr_caffemodel = findDataFile (" dnn/wechat" +model_version+" /sr.caffemodel" , false );
294
+
295
+ auto detector = wechat_qrcode::WeChatQRCode (path_detect_prototxt, path_detect_caffemodel, path_sr_prototxt,
296
+ path_sr_caffemodel);
297
+
298
+ const cv::String expect_msg = " OpenCV" ;
299
+ QRCodeEncoder::Params params;
300
+ params.version = 5 ; // 37x37
301
+ Ptr<QRCodeEncoder> qrcode_enc = cv::QRCodeEncoder::create (params);
302
+ Mat qrImage;
303
+ qrcode_enc->encode (expect_msg, qrImage);
304
+ Mat image (800 , 800 , CV_8UC1);
305
+ const int pixInBlob = 4 ;
306
+ Size qrSize = Size ((21 +(params.version -1 )*4 )*pixInBlob,(21 +(params.version -1 )*4 )*pixInBlob);
307
+ Rect2f rec ((image.cols - qrSize.width )/2 , (image.rows - qrSize.height )/2 , qrSize.width , qrSize.height );
308
+ vector<float > goldCorners = {rec.x , rec.y ,
309
+ rec.x +rec.width , rec.y ,
310
+ rec.x +rec.width , rec.y +rec.height ,
311
+ rec.x , rec.y +rec.height };
312
+ Mat roiImage = image (rec);
313
+ cv::resize (qrImage, roiImage, qrSize, 1 ., 1 ., INTER_NEAREST);
314
+
315
+ vector<Mat> points1;
316
+ auto decoded_info1 = detector.detectAndDecode (image, points1);
317
+ ASSERT_EQ (1ull , decoded_info1.size ());
318
+ ASSERT_EQ (expect_msg, decoded_info1[0 ]);
319
+ EXPECT_NEAR (0 , cvtest::norm (Mat (goldCorners), points1[0 ].reshape (1 , 8 ), NORM_INF), 8 .);
320
+
321
+ const double angle = 45 ;
322
+ Point2f pc (image.cols /2 .f , image.rows /2 .f );
323
+ Mat rot = getRotationMatrix2D (pc, angle, 1 .);
324
+ warpAffine (image, image, rot, image.size ());
325
+ vector<float > rotateGoldCorners;
326
+ for (int i = 0 ; i < static_cast <int >(goldCorners.size ()); i+= 2 ) {
327
+ rotateGoldCorners.push_back (rot.at <double >(0 , 0 ) * goldCorners[i] +
328
+ rot.at <double >(0 , 1 ) * goldCorners[i+1 ] + rot.at <double >(0 , 2 ));
329
+ rotateGoldCorners.push_back (rot.at <double >(1 , 0 ) * goldCorners[i] +
330
+ rot.at <double >(1 , 1 ) * goldCorners[i+1 ] + rot.at <double >(1 , 2 ));
331
+ }
332
+ vector<Mat> points2;
333
+ auto decoded_info2 = detector.detectAndDecode (image, points2);
334
+ ASSERT_EQ (1ull , decoded_info2.size ());
335
+ ASSERT_EQ (expect_msg, decoded_info2[0 ]);
336
+ EXPECT_NEAR (0 , cvtest::norm (Mat (rotateGoldCorners), points2[0 ].reshape (1 , 8 ), NORM_INF), 11 .);
337
+ }
338
+
287
339
INSTANTIATE_TEST_CASE_P (/* */ , Objdetect_QRCode, testing::ValuesIn(qrcode_images_name));
288
340
INSTANTIATE_TEST_CASE_P (/* */ , Objdetect_QRCode_Close, testing::ValuesIn(qrcode_images_close));
289
341
INSTANTIATE_TEST_CASE_P (/* */ , Objdetect_QRCode_Monitor, testing::ValuesIn(qrcode_images_monitor));
0 commit comments