perf_qrcode_pipeline.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. namespace opencv_test
  6. {
  7. namespace
  8. {
  9. typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode;
  10. PERF_TEST_P_(Perf_Objdetect_QRCode, detect)
  11. {
  12. const std::string name_current_image = GetParam();
  13. const std::string root = "cv/qrcode/";
  14. std::string image_path = findDataFile(root + name_current_image);
  15. Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
  16. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  17. std::vector< Point > corners;
  18. QRCodeDetector qrcode;
  19. TEST_CYCLE() ASSERT_TRUE(qrcode.detect(src, corners));
  20. SANITY_CHECK(corners);
  21. }
  22. #ifdef HAVE_QUIRC
  23. PERF_TEST_P_(Perf_Objdetect_QRCode, decode)
  24. {
  25. const std::string name_current_image = GetParam();
  26. const std::string root = "cv/qrcode/";
  27. std::string image_path = findDataFile(root + name_current_image);
  28. Mat src = imread(image_path, IMREAD_GRAYSCALE), straight_barcode;
  29. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  30. std::vector< Point > corners;
  31. std::string decoded_info;
  32. QRCodeDetector qrcode;
  33. ASSERT_TRUE(qrcode.detect(src, corners));
  34. TEST_CYCLE()
  35. {
  36. decoded_info = qrcode.decode(src, corners, straight_barcode);
  37. ASSERT_FALSE(decoded_info.empty());
  38. }
  39. std::vector<uint8_t> decoded_info_uint8_t(decoded_info.begin(), decoded_info.end());
  40. SANITY_CHECK(decoded_info_uint8_t);
  41. SANITY_CHECK(straight_barcode);
  42. }
  43. #endif
  44. typedef ::perf::TestBaseWithParam< std::string > Perf_Objdetect_QRCode_Multi;
  45. PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, detectMulti)
  46. {
  47. const std::string name_current_image = GetParam();
  48. const std::string root = "cv/qrcode/multiple/";
  49. std::string image_path = findDataFile(root + name_current_image);
  50. Mat src = imread(image_path);
  51. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  52. std::vector<Point2f> corners;
  53. QRCodeDetector qrcode;
  54. TEST_CYCLE() ASSERT_TRUE(qrcode.detectMulti(src, corners));
  55. SANITY_CHECK(corners);
  56. }
  57. #ifdef HAVE_QUIRC
  58. PERF_TEST_P_(Perf_Objdetect_QRCode_Multi, decodeMulti)
  59. {
  60. const std::string name_current_image = GetParam();
  61. const std::string root = "cv/qrcode/multiple/";
  62. std::string image_path = findDataFile(root + name_current_image);
  63. Mat src = imread(image_path);
  64. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  65. QRCodeDetector qrcode;
  66. std::vector<Point2f> corners;
  67. ASSERT_TRUE(qrcode.detectMulti(src, corners));
  68. std::vector<Mat> straight_barcode;
  69. std::vector< cv::String > decoded_info;
  70. TEST_CYCLE()
  71. {
  72. ASSERT_TRUE(qrcode.decodeMulti(src, corners, decoded_info, straight_barcode));
  73. for(size_t i = 0; i < decoded_info.size(); i++)
  74. {
  75. ASSERT_FALSE(decoded_info[i].empty());
  76. }
  77. }
  78. std::vector < std::vector< uint8_t > > decoded_info_uint8_t;
  79. for(size_t i = 0; i < decoded_info.size(); i++)
  80. {
  81. std::vector< uint8_t > tmp(decoded_info[i].begin(), decoded_info[i].end());
  82. decoded_info_uint8_t.push_back(tmp);
  83. }
  84. SANITY_CHECK(decoded_info_uint8_t);
  85. SANITY_CHECK(straight_barcode);
  86. }
  87. #endif
  88. INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode,
  89. ::testing::Values(
  90. "version_1_down.jpg", "version_1_left.jpg", "version_1_right.jpg", "version_1_up.jpg", "version_1_top.jpg",
  91. "version_5_down.jpg", "version_5_left.jpg", "version_5_right.jpg", "version_5_up.jpg", "version_5_top.jpg",
  92. "russian.jpg", "kanji.jpg", "link_github_ocv.jpg", "link_ocv.jpg", "link_wiki_cv.jpg"
  93. )
  94. );
  95. INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_QRCode_Multi,
  96. ::testing::Values(
  97. "2_qrcodes.png", "3_close_qrcodes.png", "3_qrcodes.png", "4_qrcodes.png",
  98. "5_qrcodes.png", "6_qrcodes.png", "7_qrcodes.png", "8_close_qrcodes.png"
  99. )
  100. );
  101. typedef ::perf::TestBaseWithParam< tuple< std::string, Size > > Perf_Objdetect_Not_QRCode;
  102. PERF_TEST_P_(Perf_Objdetect_Not_QRCode, detect)
  103. {
  104. std::vector<Point> corners;
  105. std::string type_gen = get<0>(GetParam());
  106. Size resolution = get<1>(GetParam());
  107. Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
  108. if (type_gen == "random")
  109. {
  110. RNG rng;
  111. rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
  112. }
  113. if (type_gen == "chessboard")
  114. {
  115. uint8_t next_pixel = 0;
  116. for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
  117. {
  118. int i = r / not_qr_code.cols;
  119. int j = r % not_qr_code.cols;
  120. not_qr_code.ptr<uchar>(i)[j] = next_pixel;
  121. next_pixel = 255 - next_pixel;
  122. }
  123. }
  124. QRCodeDetector qrcode;
  125. TEST_CYCLE() ASSERT_FALSE(qrcode.detect(not_qr_code, corners));
  126. SANITY_CHECK_NOTHING();
  127. }
  128. #ifdef HAVE_QUIRC
  129. PERF_TEST_P_(Perf_Objdetect_Not_QRCode, decode)
  130. {
  131. Mat straight_barcode;
  132. std::vector< Point > corners;
  133. corners.push_back(Point( 0, 0)); corners.push_back(Point( 0, 5));
  134. corners.push_back(Point(10, 0)); corners.push_back(Point(15, 15));
  135. std::string type_gen = get<0>(GetParam());
  136. Size resolution = get<1>(GetParam());
  137. Mat not_qr_code(resolution, CV_8UC1, Scalar(0));
  138. if (type_gen == "random")
  139. {
  140. RNG rng;
  141. rng.fill(not_qr_code, RNG::UNIFORM, Scalar(0), Scalar(1));
  142. }
  143. if (type_gen == "chessboard")
  144. {
  145. uint8_t next_pixel = 0;
  146. for (int r = 0; r < not_qr_code.rows * not_qr_code.cols; r++)
  147. {
  148. int i = r / not_qr_code.cols;
  149. int j = r % not_qr_code.cols;
  150. not_qr_code.ptr<uchar>(i)[j] = next_pixel;
  151. next_pixel = 255 - next_pixel;
  152. }
  153. }
  154. QRCodeDetector qrcode;
  155. TEST_CYCLE() ASSERT_TRUE(qrcode.decode(not_qr_code, corners, straight_barcode).empty());
  156. SANITY_CHECK_NOTHING();
  157. }
  158. #endif
  159. INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Objdetect_Not_QRCode,
  160. ::testing::Combine(
  161. ::testing::Values("zero", "random", "chessboard"),
  162. ::testing::Values(Size(640, 480), Size(1280, 720),
  163. Size(1920, 1080), Size(3840, 2160))
  164. ));
  165. }
  166. } // namespace