perf_barcode.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 "opencv2/objdetect/barcode.hpp"
  6. namespace opencv_test{namespace{
  7. typedef ::perf::TestBaseWithParam< tuple<string, cv::Size> > Perf_Barcode_multi;
  8. typedef ::perf::TestBaseWithParam< tuple<string, cv::Size> > Perf_Barcode_single;
  9. PERF_TEST_P_(Perf_Barcode_multi, detect)
  10. {
  11. const string root = "cv/barcode/multiple/";
  12. const string name_current_image = get<0>(GetParam());
  13. const cv::Size sz = get<1>(GetParam());
  14. const string image_path = findDataFile(root + name_current_image);
  15. Mat src = imread(image_path);
  16. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  17. cv::resize(src, src, sz);
  18. vector< Point > corners;
  19. auto bardet = barcode::BarcodeDetector();
  20. bool res = false;
  21. TEST_CYCLE()
  22. {
  23. res = bardet.detectMulti(src, corners);
  24. }
  25. SANITY_CHECK_NOTHING();
  26. ASSERT_TRUE(res);
  27. ASSERT_EQ(16ull, corners.size());
  28. }
  29. PERF_TEST_P_(Perf_Barcode_multi, detect_decode)
  30. {
  31. const string root = "cv/barcode/multiple/";
  32. const string name_current_image = get<0>(GetParam());
  33. const cv::Size sz = get<1>(GetParam());
  34. const string image_path = findDataFile(root + name_current_image);
  35. Mat src = imread(image_path);
  36. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  37. cv::resize(src, src, sz);
  38. vector<std::string> decoded_info;
  39. vector<std::string> decoded_type;
  40. vector< Point > corners;
  41. auto bardet = barcode::BarcodeDetector();
  42. bool res = false;
  43. TEST_CYCLE()
  44. {
  45. res = bardet.detectAndDecodeWithType(src, decoded_info, decoded_type, corners);
  46. }
  47. SANITY_CHECK_NOTHING();
  48. ASSERT_TRUE(res);
  49. ASSERT_EQ(16ull, corners.size());
  50. ASSERT_EQ(4ull, decoded_info.size());
  51. }
  52. PERF_TEST_P_(Perf_Barcode_single, detect)
  53. {
  54. const string root = "cv/barcode/single/";
  55. const string name_current_image = get<0>(GetParam());
  56. const cv::Size sz = get<1>(GetParam());
  57. const string image_path = findDataFile(root + name_current_image);
  58. Mat src = imread(image_path);
  59. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  60. cv::resize(src, src, sz);
  61. vector< Point > corners;
  62. auto bardet = barcode::BarcodeDetector();
  63. bool res = false;
  64. TEST_CYCLE()
  65. {
  66. res = bardet.detectMulti(src, corners);
  67. }
  68. SANITY_CHECK_NOTHING();
  69. ASSERT_TRUE(res);
  70. ASSERT_EQ(4ull, corners.size());
  71. }
  72. PERF_TEST_P_(Perf_Barcode_single, detect_decode)
  73. {
  74. const string root = "cv/barcode/single/";
  75. const string name_current_image = get<0>(GetParam());
  76. const cv::Size sz = get<1>(GetParam());
  77. const string image_path = findDataFile(root + name_current_image);
  78. Mat src = imread(image_path);
  79. ASSERT_FALSE(src.empty()) << "Can't read image: " << image_path;
  80. cv::resize(src, src, sz);
  81. vector<std::string> decoded_info;
  82. vector<std::string> decoded_type;
  83. vector< Point > corners;
  84. auto bardet = barcode::BarcodeDetector();
  85. bool res = false;
  86. TEST_CYCLE()
  87. {
  88. res = bardet.detectAndDecodeWithType(src, decoded_info, decoded_type, corners);
  89. }
  90. SANITY_CHECK_NOTHING();
  91. ASSERT_TRUE(res);
  92. ASSERT_EQ(4ull, corners.size());
  93. ASSERT_EQ(1ull, decoded_info.size());
  94. }
  95. INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_multi,
  96. testing::Combine(
  97. testing::Values("4_barcodes.jpg"),
  98. testing::Values(cv::Size(2041, 2722), cv::Size(1361, 1815), cv::Size(680, 907))));
  99. INSTANTIATE_TEST_CASE_P(/*nothing*/, Perf_Barcode_single,
  100. testing::Combine(
  101. testing::Values("book.jpg", "bottle_1.jpg", "bottle_2.jpg"),
  102. testing::Values(cv::Size(480, 360), cv::Size(640, 480), cv::Size(800, 600))));
  103. }} //namespace