perf_houghlines.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include "opencv2/ts/ocl_perf.hpp"
  8. #ifdef HAVE_OPENCL
  9. namespace opencv_test {
  10. namespace ocl {
  11. ///////////// HoughLines //////////////////////
  12. struct Vec2fComparator
  13. {
  14. bool operator()(const Vec2f& a, const Vec2f b) const
  15. {
  16. if(a[0] != b[0]) return a[0] < b[0];
  17. else return a[1] < b[1];
  18. }
  19. };
  20. typedef tuple<Size, double, double> ImageSize_RhoStep_ThetaStep_t;
  21. typedef TestBaseWithParam<ImageSize_RhoStep_ThetaStep_t> HoughLinesFixture;
  22. OCL_PERF_TEST_P(HoughLinesFixture, HoughLines, Combine(OCL_TEST_SIZES,
  23. Values( 0.1, 1 ),
  24. Values( CV_PI / 180.0, 0.1 )))
  25. {
  26. const Size srcSize = get<0>(GetParam());
  27. double rhoStep = get<1>(GetParam());
  28. double thetaStep = get<2>(GetParam());
  29. int threshold = 250;
  30. UMat usrc(srcSize, CV_8UC1), lines(1, 1, CV_32FC2);
  31. Mat src(srcSize, CV_8UC1);
  32. src.setTo(Scalar::all(0));
  33. line(src, Point(0, 100), Point(src.cols, 100), Scalar::all(255), 1);
  34. line(src, Point(0, 200), Point(src.cols, 200), Scalar::all(255), 1);
  35. line(src, Point(0, 400), Point(src.cols, 400), Scalar::all(255), 1);
  36. line(src, Point(100, 0), Point(100, src.rows), Scalar::all(255), 1);
  37. line(src, Point(200, 0), Point(200, src.rows), Scalar::all(255), 1);
  38. line(src, Point(400, 0), Point(400, src.rows), Scalar::all(255), 1);
  39. src.copyTo(usrc);
  40. declare.in(usrc).out(lines);
  41. OCL_TEST_CYCLE() cv::HoughLines(usrc, lines, rhoStep, thetaStep, threshold);
  42. Mat result;
  43. lines.copyTo(result);
  44. std::sort(result.begin<Vec2f>(), result.end<Vec2f>(), Vec2fComparator());
  45. SANITY_CHECK(result, 1e-6);
  46. }
  47. ///////////// HoughLinesP /////////////////////
  48. typedef tuple<string, double, double> Image_RhoStep_ThetaStep_t;
  49. typedef TestBaseWithParam<Image_RhoStep_ThetaStep_t> HoughLinesPFixture;
  50. OCL_PERF_TEST_P(HoughLinesPFixture, HoughLinesP, Combine(Values("cv/shared/pic5.png", "stitching/a1.png"),
  51. Values( 0.1, 1 ),
  52. Values( CV_PI / 180.0, 0.1 )))
  53. {
  54. string filename = get<0>(GetParam());
  55. double rhoStep = get<1>(GetParam());
  56. double thetaStep = get<2>(GetParam());
  57. int threshold = 100;
  58. double minLineLength = 50, maxGap = 5;
  59. Mat image = imread(getDataPath(filename), IMREAD_GRAYSCALE);
  60. Canny(image, image, 50, 200, 3);
  61. UMat usrc, lines(1, 1, CV_32SC4);
  62. image.copyTo(usrc);
  63. declare.in(usrc).out(lines);
  64. OCL_TEST_CYCLE() cv::HoughLinesP(usrc, lines, rhoStep, thetaStep, threshold, minLineLength, maxGap);
  65. EXPECT_NE((int) lines.total(), 0);
  66. SANITY_CHECK_NOTHING();
  67. }
  68. } } // namespace opencv_test::ocl
  69. #endif // HAVE_OPENCL