test_l0_smooth.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "test_precomp.hpp"
  5. namespace opencv_test { namespace {
  6. CV_ENUM(SrcTypes, CV_8UC1, CV_8UC3, CV_16UC1, CV_16UC3);
  7. typedef tuple<Size, SrcTypes> L0SmoothParams;
  8. typedef TestWithParam<L0SmoothParams> L0SmoothTest;
  9. TEST(L0SmoothTest, SplatSurfaceAccuracy)
  10. {
  11. RNG rnd(0);
  12. for (int i = 0; i < 3; i++)
  13. {
  14. Size sz(rnd.uniform(512, 1024), rnd.uniform(512, 1024));
  15. Scalar surfaceValue;
  16. int srcCn = 3;
  17. rnd.fill(surfaceValue, RNG::UNIFORM, 0, 255);
  18. Mat src(sz, CV_MAKE_TYPE(CV_8U, srcCn), surfaceValue);
  19. double lambda = rnd.uniform(0.01, 0.05);
  20. double kappa = rnd.uniform(1.5, 5.0);
  21. Mat res;
  22. l0Smooth(src, res, lambda, kappa);
  23. // When filtering a constant image we should get the same image:
  24. double normL1 = cvtest::norm(src, res, NORM_L1)/src.total()/src.channels();
  25. EXPECT_LE(normL1, 1.0/64);
  26. }
  27. }
  28. TEST_P(L0SmoothTest, MultiThreadReproducibility)
  29. {
  30. if (cv::getNumberOfCPUs() == 1)
  31. return;
  32. double MAX_DIF = 10.0;
  33. double MAX_MEAN_DIF = 1.0 / 8.0;
  34. int loopsCount = 2;
  35. RNG rng(0);
  36. L0SmoothParams params = GetParam();
  37. Size size = get<0>(params);
  38. int srcType = get<1>(params);
  39. Mat src(size,srcType);
  40. if(src.depth()==CV_8U)
  41. randu(src, 0, 255);
  42. else if(src.depth()==CV_16U)
  43. randu(src, 0, 65535);
  44. else
  45. randu(src, -100000.0f, 100000.0f);
  46. int nThreads = cv::getNumThreads();
  47. if (nThreads == 1)
  48. throw SkipTestException("Single thread environment");
  49. for (int iter = 0; iter <= loopsCount; iter++)
  50. {
  51. double lambda = rng.uniform(0.01, 0.05);
  52. double kappa = rng.uniform(1.5, 5.0);
  53. cv::setNumThreads(nThreads);
  54. Mat resMultiThread;
  55. l0Smooth(src, resMultiThread, lambda, kappa);
  56. cv::setNumThreads(1);
  57. Mat resSingleThread;
  58. l0Smooth(src, resSingleThread, lambda, kappa);
  59. EXPECT_LE(cv::norm(resSingleThread, resMultiThread, NORM_INF), MAX_DIF);
  60. EXPECT_LE(cv::norm(resSingleThread, resMultiThread, NORM_L1), MAX_MEAN_DIF*src.total()*src.channels());
  61. }
  62. }
  63. INSTANTIATE_TEST_CASE_P(FullSet, L0SmoothTest,Combine(Values(szODD, szQVGA), SrcTypes::all()));
  64. }} // namespace