perf_contours.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 { namespace {
  6. CV_ENUM(RetrMode, RETR_EXTERNAL, RETR_LIST, RETR_CCOMP, RETR_TREE)
  7. CV_ENUM(ApproxMode, CHAIN_APPROX_NONE, CHAIN_APPROX_SIMPLE, CHAIN_APPROX_TC89_L1, CHAIN_APPROX_TC89_KCOS)
  8. typedef TestBaseWithParam< tuple<Size, RetrMode, ApproxMode, int> > TestFindContours;
  9. PERF_TEST_P(TestFindContours, findContours,
  10. Combine(
  11. Values( szVGA, sz1080p ), // image size
  12. RetrMode::all(), // retrieval mode
  13. ApproxMode::all(), // approximation method
  14. Values( 32, 128 ) // blob count
  15. )
  16. )
  17. {
  18. Size img_size = get<0>(GetParam());
  19. int retr_mode = get<1>(GetParam());
  20. int approx_method = get<2>(GetParam());
  21. int blob_count = get<3>(GetParam());
  22. RNG rng;
  23. Mat img = Mat::zeros(img_size, CV_8UC1);
  24. for(int i = 0; i < blob_count; i++ )
  25. {
  26. Point center;
  27. center.x = (unsigned)rng % (img.cols-2);
  28. center.y = (unsigned)rng % (img.rows-2);
  29. Size axes;
  30. axes.width = ((unsigned)rng % 49 + 2)/2;
  31. axes.height = ((unsigned)rng % 49 + 2)/2;
  32. double angle = (unsigned)rng % 180;
  33. int brightness = (unsigned)rng % 2;
  34. // keep the border clear
  35. ellipse( img(Rect(1,1,img.cols-2,img.rows-2)), Point(center), Size(axes), angle, 0., 360., Scalar(brightness), -1);
  36. }
  37. vector< vector<Point> > contours;
  38. TEST_CYCLE() findContours( img, contours, retr_mode, approx_method );
  39. SANITY_CHECK_NOTHING();
  40. }
  41. typedef TestBaseWithParam< tuple<Size, ApproxMode, int> > TestFindContoursFF;
  42. PERF_TEST_P(TestFindContoursFF, findContours,
  43. Combine(
  44. Values(szVGA, sz1080p), // image size
  45. ApproxMode::all(), // approximation method
  46. Values(32, 128) // blob count
  47. )
  48. )
  49. {
  50. Size img_size = get<0>(GetParam());
  51. int approx_method = get<1>(GetParam());
  52. int blob_count = get<2>(GetParam());
  53. RNG rng;
  54. Mat img = Mat::zeros(img_size, CV_32SC1);
  55. for (int i = 0; i < blob_count; i++)
  56. {
  57. Point center;
  58. center.x = (unsigned)rng % (img.cols - 2);
  59. center.y = (unsigned)rng % (img.rows - 2);
  60. Size axes;
  61. axes.width = ((unsigned)rng % 49 + 2) / 2;
  62. axes.height = ((unsigned)rng % 49 + 2) / 2;
  63. double angle = (unsigned)rng % 180;
  64. int brightness = (unsigned)rng % 2;
  65. // keep the border clear
  66. ellipse(img(Rect(1, 1, img.cols - 2, img.rows - 2)), Point(center), Size(axes), angle, 0., 360., Scalar(brightness), -1);
  67. }
  68. vector< vector<Point> > contours;
  69. TEST_CYCLE() findContours(img, contours, RETR_FLOODFILL, approx_method);
  70. SANITY_CHECK_NOTHING();
  71. }
  72. typedef TestBaseWithParam< tuple<MatDepth, int> > TestBoundingRect;
  73. PERF_TEST_P(TestBoundingRect, BoundingRect,
  74. Combine(
  75. testing::Values(CV_32S, CV_32F), // points type
  76. Values(400, 511, 1000, 10000, 100000) // points count
  77. )
  78. )
  79. {
  80. int ptType = get<0>(GetParam());
  81. int n = get<1>(GetParam());
  82. Mat pts(n, 2, ptType);
  83. declare.in(pts, WARMUP_RNG);
  84. cv::Rect rect;
  85. TEST_CYCLE() rect = boundingRect(pts);
  86. SANITY_CHECK_NOTHING();
  87. }
  88. } } // namespace