perf_floodfill.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // Copyright (C) 2014, Itseez, Inc., all rights reserved.
  5. // Third party copyrights are property of their respective owners.
  6. #include "perf_precomp.hpp"
  7. namespace opencv_test {
  8. typedef tuple<string, Point, int, int, int, int> Size_Source_Fl_t;
  9. typedef perf::TestBaseWithParam<Size_Source_Fl_t> Size_Source_Fl;
  10. PERF_TEST_P(Size_Source_Fl, floodFill1, Combine(
  11. testing::Values("cv/shared/fruits.png", "cv/optflow/RubberWhale1.png"), //images
  12. testing::Values(Point(120, 82), Point(200, 140)), //seed points
  13. testing::Values(4,8), //connectivity
  14. testing::Values((int)IMREAD_COLOR, (int)IMREAD_GRAYSCALE), //color image, or not
  15. testing::Values(0, 1, 2), //use fixed(1), gradient (2) or simple(0) mode
  16. testing::Values((int)CV_8U, (int)CV_32F, (int)CV_32S) //image depth
  17. ))
  18. {
  19. //test given image(s)
  20. string filename = getDataPath(get<0>(GetParam()));
  21. Point pseed;
  22. pseed = get<1>(GetParam());
  23. int connectivity = get<2>(GetParam());
  24. int colorType = get<3>(GetParam());
  25. int modeType = get<4>(GetParam());
  26. int imdepth = get<5>(GetParam());
  27. Mat image0 = imread(filename, colorType);
  28. Scalar newval, loVal, upVal;
  29. if (modeType == 0)
  30. {
  31. loVal = Scalar(0, 0, 0);
  32. upVal = Scalar(0, 0, 0);
  33. }
  34. else
  35. {
  36. loVal = Scalar(4, 4, 4);
  37. upVal = Scalar(20, 20, 20);
  38. }
  39. int newMaskVal = 255; //base mask for floodfill type
  40. int flags = connectivity + (newMaskVal << 8) + (modeType == 1 ? FLOODFILL_FIXED_RANGE : 0);
  41. int b = 152;//(unsigned)theRNG() & 255;
  42. int g = 136;//(unsigned)theRNG() & 255;
  43. int r = 53;//(unsigned)theRNG() & 255;
  44. newval = (colorType == IMREAD_COLOR) ? Scalar(b, g, r) : Scalar(r*0.299 + g*0.587 + b*0.114);
  45. Rect outputRect = Rect();
  46. Mat source = Mat();
  47. for (; next(); )
  48. {
  49. image0.convertTo(source, imdepth);
  50. startTimer();
  51. cv::floodFill(source, pseed, newval, &outputRect, loVal, upVal, flags);
  52. stopTimer();
  53. }
  54. EXPECT_EQ(image0.cols, source.cols);
  55. EXPECT_EQ(image0.rows, source.rows);
  56. SANITY_CHECK_NOTHING();
  57. }
  58. } // namespace