perf_distanceTransform.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. CV_ENUM(DistanceType, DIST_L1, DIST_L2 , DIST_C)
  7. CV_ENUM(MaskSize, DIST_MASK_3, DIST_MASK_5, DIST_MASK_PRECISE)
  8. CV_ENUM(DstType, CV_8U, CV_32F)
  9. CV_ENUM(LabelType, DIST_LABEL_CCOMP, DIST_LABEL_PIXEL)
  10. typedef tuple<Size, DistanceType, MaskSize, DstType> SrcSize_DistType_MaskSize_DstType;
  11. typedef tuple<Size, DistanceType, MaskSize, LabelType> SrcSize_DistType_MaskSize_LabelType;
  12. typedef perf::TestBaseWithParam<SrcSize_DistType_MaskSize_DstType> DistanceTransform_Test;
  13. typedef perf::TestBaseWithParam<SrcSize_DistType_MaskSize_LabelType> DistanceTransform_NeedLabels_Test;
  14. PERF_TEST_P(DistanceTransform_Test, distanceTransform,
  15. testing::Combine(
  16. testing::Values(cv::Size(640, 480), cv::Size(800, 600), cv::Size(1024, 768), cv::Size(1280, 1024)),
  17. DistanceType::all(),
  18. MaskSize::all(),
  19. DstType::all()
  20. )
  21. )
  22. {
  23. Size srcSize = get<0>(GetParam());
  24. int distanceType = get<1>(GetParam());
  25. int maskSize = get<2>(GetParam());
  26. int dstType = get<3>(GetParam());
  27. Mat src(srcSize, CV_8U);
  28. Mat dst(srcSize, dstType);
  29. declare
  30. .in(src, WARMUP_RNG)
  31. .out(dst, WARMUP_RNG)
  32. .time(30);
  33. TEST_CYCLE() distanceTransform( src, dst, distanceType, maskSize, dstType);
  34. double eps = 2e-4;
  35. SANITY_CHECK(dst, eps);
  36. }
  37. PERF_TEST_P(DistanceTransform_NeedLabels_Test, distanceTransform_NeedLabels,
  38. testing::Combine(
  39. testing::Values(cv::Size(640, 480), cv::Size(800, 600), cv::Size(1024, 768), cv::Size(1280, 1024)),
  40. DistanceType::all(),
  41. MaskSize::all(),
  42. LabelType::all()
  43. )
  44. )
  45. {
  46. Size srcSize = get<0>(GetParam());
  47. int distanceType = get<1>(GetParam());
  48. int maskSize = get<2>(GetParam());
  49. int labelType = get<3>(GetParam());
  50. Mat src(srcSize, CV_8U);
  51. Mat label(srcSize, CV_32S);
  52. Mat dst(srcSize, CV_32F);
  53. declare
  54. .in(src, WARMUP_RNG)
  55. .out(label, WARMUP_RNG)
  56. .out(dst, WARMUP_RNG)
  57. .time(30);
  58. TEST_CYCLE() distanceTransform( src, dst, label, distanceType, maskSize, labelType);
  59. double eps = 2e-4;
  60. SANITY_CHECK(label, eps);
  61. SANITY_CHECK(dst, eps);
  62. }
  63. } // namespace