perf_cuda.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and/or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #include "perf_precomp.hpp"
  43. #include "opencv2/photo/cuda.hpp"
  44. #include "opencv2/ts/cuda_perf.hpp"
  45. #include "opencv2/opencv_modules.hpp"
  46. #if defined (HAVE_CUDA) && defined(HAVE_OPENCV_CUDAARITHM) && defined(HAVE_OPENCV_CUDAIMGPROC)
  47. namespace opencv_test { namespace {
  48. using namespace perf;
  49. #define CUDA_DENOISING_IMAGE_SIZES testing::Values(perf::szVGA, perf::sz720p)
  50. //////////////////////////////////////////////////////////////////////
  51. // nonLocalMeans
  52. DEF_PARAM_TEST(Sz_Depth_Cn_WinSz_BlockSz, cv::Size, MatDepth, MatCn, int, int);
  53. PERF_TEST_P(Sz_Depth_Cn_WinSz_BlockSz, CUDA_NonLocalMeans,
  54. Combine(CUDA_DENOISING_IMAGE_SIZES,
  55. Values<MatDepth>(CV_8U),
  56. CUDA_CHANNELS_1_3,
  57. Values(21),
  58. Values(5)))
  59. {
  60. declare.time(600.0);
  61. const cv::Size size = GET_PARAM(0);
  62. const int depth = GET_PARAM(1);
  63. const int channels = GET_PARAM(2);
  64. const int search_widow_size = GET_PARAM(3);
  65. const int block_size = GET_PARAM(4);
  66. const float h = 10;
  67. const int borderMode = cv::BORDER_REFLECT101;
  68. const int type = CV_MAKE_TYPE(depth, channels);
  69. cv::Mat src(size, type);
  70. declare.in(src, WARMUP_RNG);
  71. if (PERF_RUN_CUDA())
  72. {
  73. const cv::cuda::GpuMat d_src(src);
  74. cv::cuda::GpuMat dst;
  75. TEST_CYCLE() cv::cuda::nonLocalMeans(d_src, dst, h, search_widow_size, block_size, borderMode);
  76. CUDA_SANITY_CHECK(dst);
  77. }
  78. else
  79. {
  80. FAIL_NO_CPU();
  81. }
  82. }
  83. //////////////////////////////////////////////////////////////////////
  84. // fastNonLocalMeans
  85. DEF_PARAM_TEST(Sz_Depth_Cn_WinSz_BlockSz, cv::Size, MatDepth, MatCn, int, int);
  86. PERF_TEST_P(Sz_Depth_Cn_WinSz_BlockSz, CUDA_FastNonLocalMeans,
  87. Combine(CUDA_DENOISING_IMAGE_SIZES,
  88. Values<MatDepth>(CV_8U),
  89. CUDA_CHANNELS_1_3,
  90. Values(21),
  91. Values(7)))
  92. {
  93. declare.time(60.0);
  94. const cv::Size size = GET_PARAM(0);
  95. const int depth = GET_PARAM(1);
  96. const int search_widow_size = GET_PARAM(2);
  97. const int block_size = GET_PARAM(3);
  98. const float h = 10;
  99. const int type = CV_MAKE_TYPE(depth, 1);
  100. cv::Mat src(size, type);
  101. declare.in(src, WARMUP_RNG);
  102. if (PERF_RUN_CUDA())
  103. {
  104. const cv::cuda::GpuMat d_src(src);
  105. cv::cuda::GpuMat dst;
  106. TEST_CYCLE() cv::cuda::fastNlMeansDenoising(d_src, dst, h, search_widow_size, block_size);
  107. CUDA_SANITY_CHECK(dst);
  108. }
  109. else
  110. {
  111. cv::Mat dst;
  112. TEST_CYCLE() cv::fastNlMeansDenoising(src, dst, h, block_size, search_widow_size);
  113. CPU_SANITY_CHECK(dst);
  114. }
  115. }
  116. //////////////////////////////////////////////////////////////////////
  117. // fastNonLocalMeans (colored)
  118. DEF_PARAM_TEST(Sz_Depth_WinSz_BlockSz, cv::Size, MatDepth, int, int);
  119. PERF_TEST_P(Sz_Depth_WinSz_BlockSz, CUDA_FastNonLocalMeansColored,
  120. Combine(CUDA_DENOISING_IMAGE_SIZES,
  121. Values<MatDepth>(CV_8U),
  122. Values(21),
  123. Values(7)))
  124. {
  125. declare.time(60.0);
  126. const cv::Size size = GET_PARAM(0);
  127. const int depth = GET_PARAM(1);
  128. const int search_widow_size = GET_PARAM(2);
  129. const int block_size = GET_PARAM(3);
  130. const float h = 10;
  131. const int type = CV_MAKE_TYPE(depth, 3);
  132. cv::Mat src(size, type);
  133. declare.in(src, WARMUP_RNG);
  134. if (PERF_RUN_CUDA())
  135. {
  136. const cv::cuda::GpuMat d_src(src);
  137. cv::cuda::GpuMat dst;
  138. TEST_CYCLE() cv::cuda::fastNlMeansDenoisingColored(d_src, dst, h, h, search_widow_size, block_size);
  139. CUDA_SANITY_CHECK(dst);
  140. }
  141. else
  142. {
  143. cv::Mat dst;
  144. TEST_CYCLE() cv::fastNlMeansDenoisingColored(src, dst, h, h, block_size, search_widow_size);
  145. CPU_SANITY_CHECK(dst);
  146. }
  147. }
  148. }} // namespace
  149. #endif