perf_qrcode_pipeline.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "perf_precomp.hpp"
  5. #include "../test/test_qr_utils.hpp"
  6. namespace opencv_test
  7. {
  8. namespace
  9. {
  10. typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode;
  11. PERF_TEST_P_(Perf_Objdetect_QRCode, detect)
  12. {
  13. const std::string name_current_image = GetParam();
  14. const std::string root = "cv/qrcode/";
  15. std::string image_path = findDataFile(root + name_current_image);
  16. Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
  17. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  18. std::vector< Point > corners;
  19. QRCodeDetector qrcode;
  20. TEST_CYCLE() ASSERT_TRUE(qrcode.detect(src, corners));
  21. const int pixels_error = 3;
  22. check_qr(root, name_current_image, "test_images", corners, {}, pixels_error);
  23. SANITY_CHECK_NOTHING();
  24. }
  25. PERF_TEST_P_(Perf_Objdetect_QRCode, decode)
  26. {
  27. const std::string name_current_image = GetParam();
  28. const std::string root = "cv/qrcode/";
  29. std::string image_path = findDataFile(root + name_current_image);
  30. Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
  31. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  32. std::vector< Point > corners;
  33. std::string decoded_info;
  34. QRCodeDetector qrcode;
  35. ASSERT_TRUE(qrcode.detect(src, corners));
  36. TEST_CYCLE()
  37. {
  38. decoded_info = qrcode.decode(src, corners, straight_barcode);
  39. ASSERT_FALSE(decoded_info.empty());
  40. }
  41. const int pixels_error = 3;
  42. check_qr(root, name_current_image, "test_images", corners, {decoded_info}, pixels_error);
  43. SANITY_CHECK_NOTHING();
  44. }
  45. typedef ::perf::TestBaseWithParam<std::tuple<std::string, std::string>> Perf_Objdetect_QRCode_Multi;
  46. static std::set<std::pair<std::string, std::string>> disabled_samples = {{"5_qrcodes.png", "aruco_based"}};
  47. PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, detectMulti)
  48. {
  49. const std::string name_current_image = get<0>(GetParam());
  50. const std::string method = get<1>(GetParam());
  51. const std::string root = "cv/qrcode/multiple/";
  52. std::string image_path = findDataFile(root + name_current_image);
  53. Mat src = imread(image_path);
  54. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  55. std::vector<Point> corners;
  56. GraphicalCodeDetector qrcode = QRCodeDetector();
  57. if (method == "aruco_based") {
  58. qrcode = QRCodeDetectorAruco();
  59. }
  60. TEST_CYCLE() ASSERT_TRUE(qrcode.detectMulti(src, corners));
  61. const int pixels_error = 7;
  62. check_qr(root, name_current_image, "multiple_images", corners, {}, pixels_error, true);
  63. SANITY_CHECK_NOTHING();
  64. }
  65. PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, decodeMulti)
  66. {
  67. const std::string name_current_image = get<0>(GetParam());
  68. std::string method = get<1>(GetParam());
  69. const std::string root = "cv/qrcode/multiple/";
  70. std::string image_path = findDataFile(root + name_current_image);
  71. Mat src = imread(image_path);
  72. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  73. if (disabled_samples.find({name_current_image, method}) != disabled_samples.end()) {
  74. throw SkipTestException(name_current_image + " is disabled sample for method " + method);
  75. }
  76. GraphicalCodeDetector qrcode = QRCodeDetector();
  77. if (method == "aruco_based") {
  78. qrcode = QRCodeDetectorAruco();
  79. }
  80. std::vector<Point2f> corners;
  81. ASSERT_TRUE(qrcode.detectMulti(src, corners));
  82. std::vector<Mat> straight_barcode;
  83. std::vector< cv::String > decoded_info;
  84. TEST_CYCLE()
  85. {
  86. ASSERT_TRUE(qrcode.decodeMulti(src, corners, decoded_info, straight_barcode));
  87. }
  88. ASSERT_TRUE(decoded_info.size() > 0ull);
  89. for(size_t i = 0; i < decoded_info.size(); i++) {
  90. ASSERT_FALSE(decoded_info[i].empty());
  91. }
  92. ASSERT_EQ(decoded_info.size(), straight_barcode.size());
  93. vector<Point> corners_result(corners.size());
  94. for (size_t i = 0ull; i < corners_result.size(); i++) {
  95. corners_result[i] = corners[i];
  96. }
  97. const int pixels_error = 7;
  98. check_qr(root, name_current_image, "multiple_images", corners_result, decoded_info, pixels_error, true);
  99. SANITY_CHECK_NOTHING();
  100. }
  101. INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode,
  102. ::testing::Values(
  103. "version_1_down.jpg", "version_1_left.jpg", "version_1_right.jpg", "version_1_up.jpg", "version_1_top.jpg",
  104. "version_5_down.jpg", "version_5_left.jpg",/*version_5_right.jpg*/ "version_5_up.jpg", "version_5_top.jpg",
  105. "russian.jpg", "kanji.jpg", "link_github_ocv.jpg", "link_ocv.jpg", "link_wiki_cv.jpg"
  106. )
  107. );
  108. // version_5_right.jpg DISABLED after tile fix, PR #22025
  109. INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode_Multi,
  110. testing::Combine(testing::Values("2_qrcodes.png", "3_close_qrcodes.png", "3_qrcodes.png", "4_qrcodes.png",
  111. "5_qrcodes.png", "6_qrcodes.png", "7_qrcodes.png", "8_close_qrcodes.png"),
  112. testing::Values("contours_based", "aruco_based")));
  113. typedef ::perf::TestBaseWithParam< tuple< std::string, Size > > Perf_Objdetect_Not_QRCode;
  114. PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect)
  115. {
  116. std::vector<Point> corners;
  117. std::string type_gen = get<0>(GetParam());
  118. Size resolution = get<1>(GetParam());
  119. Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
  120. if (type_gen == "random")
  121. {
  122. RNG rng;
  123. rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
  124. }
  125. if (type_gen == "chessboard")
  126. {
  127. uint8_t next_pixel = 0;
  128. for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
  129. {
  130. int i = r / not_qr_code.cols;
  131. int j = r % not_qr_code.cols;
  132. not_qr_code.ptr<uchar>(i)[j] = next_pixel;
  133. next_pixel = 255 - next_pixel;
  134. }
  135. }
  136. QRCodeDetector qrcode;
  137. TEST_CYCLE() ASSERT_FALSE(qrcode.detect(not_qr_code, corners));
  138. SANITY_CHECK_NOTHING();
  139. }
  140. PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode)
  141. {
  142. Mat straight_barcode;
  143. std::vector< Point > corners;
  144. corners.push_back(Point( 0, 0)); corners.push_back(Point( 0, 5));
  145. corners.push_back(Point(10, 0)); corners.push_back(Point(15, 15));
  146. std::string type_gen = get<0>(GetParam());
  147. Size resolution = get<1>(GetParam());
  148. Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
  149. if (type_gen == "random")
  150. {
  151. RNG rng;
  152. rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
  153. }
  154. if (type_gen == "chessboard")
  155. {
  156. uint8_t next_pixel = 0;
  157. for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
  158. {
  159. int i = r / not_qr_code.cols;
  160. int j = r % not_qr_code.cols;
  161. not_qr_code.ptr<uchar>(i)[j] = next_pixel;
  162. next_pixel = 255 - next_pixel;
  163. }
  164. }
  165. QRCodeDetector qrcode;
  166. TEST_CYCLE() ASSERT_TRUE(qrcode.decode(not_qr_code, corners, straight_barcode).empty());
  167. SANITY_CHECK_NOTHING();
  168. }
  169. INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode,
  170. ::testing::Combine(
  171. ::testing::Values("zero", "random", "chessboard"),
  172. ::testing::Values(Size(640, 480), Size(1280, 720),
  173. Size(1920, 1080), Size(3840, 2160))
  174. ));
  175. }
  176. } // namespace