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
43#include "perf_precomp.hpp"
44
45#include "opencv2/photo/cuda.hpp"
46#include "opencv2/ts/cuda_perf.hpp"
47
48#include "opencv2/opencv_modules.hpp"
49
50#if defined (HAVE_CUDA) && defined(HAVE_OPENCV_CUDAARITHM) && defined(HAVE_OPENCV_CUDAIMGPROC)
51
52using namespace std;
53using namespace testing;
54using namespace perf;
55
56#define CUDA_DENOISING_IMAGE_SIZES testing::Values(perf::szVGA, perf::sz720p)
57
58//////////////////////////////////////////////////////////////////////
59// nonLocalMeans
60
61DEF_PARAM_TEST(Sz_Depth_Cn_WinSz_BlockSz, cv::Size, MatDepth, MatCn, int, int);
62
63PERF_TEST_P(Sz_Depth_Cn_WinSz_BlockSz, CUDA_NonLocalMeans,
64            Combine(CUDA_DENOISING_IMAGE_SIZES,
65                    Values<MatDepth>(CV_8U),
66                    CUDA_CHANNELS_1_3,
67                    Values(21),
68                    Values(5)))
69{
70    declare.time(600.0);
71
72    const cv::Size size = GET_PARAM(0);
73    const int depth = GET_PARAM(1);
74    const int channels = GET_PARAM(2);
75    const int search_widow_size = GET_PARAM(3);
76    const int block_size = GET_PARAM(4);
77
78    const float h = 10;
79    const int borderMode = cv::BORDER_REFLECT101;
80
81    const int type = CV_MAKE_TYPE(depth, channels);
82
83    cv::Mat src(size, type);
84    declare.in(src, WARMUP_RNG);
85
86    if (PERF_RUN_CUDA())
87    {
88        const cv::cuda::GpuMat d_src(src);
89        cv::cuda::GpuMat dst;
90
91        TEST_CYCLE() cv::cuda::nonLocalMeans(d_src, dst, h, search_widow_size, block_size, borderMode);
92
93        CUDA_SANITY_CHECK(dst);
94    }
95    else
96    {
97        FAIL_NO_CPU();
98    }
99}
100
101
102//////////////////////////////////////////////////////////////////////
103// fastNonLocalMeans
104
105DEF_PARAM_TEST(Sz_Depth_Cn_WinSz_BlockSz, cv::Size, MatDepth, MatCn, int, int);
106
107PERF_TEST_P(Sz_Depth_Cn_WinSz_BlockSz, CUDA_FastNonLocalMeans,
108            Combine(CUDA_DENOISING_IMAGE_SIZES,
109                    Values<MatDepth>(CV_8U),
110                    CUDA_CHANNELS_1_3,
111                    Values(21),
112                    Values(7)))
113{
114    declare.time(60.0);
115
116    const cv::Size size = GET_PARAM(0);
117    const int depth = GET_PARAM(1);
118    const int search_widow_size = GET_PARAM(2);
119    const int block_size = GET_PARAM(3);
120
121    const float h = 10;
122    const int type = CV_MAKE_TYPE(depth, 1);
123
124    cv::Mat src(size, type);
125    declare.in(src, WARMUP_RNG);
126
127    if (PERF_RUN_CUDA())
128    {
129        const cv::cuda::GpuMat d_src(src);
130        cv::cuda::GpuMat dst;
131
132        TEST_CYCLE() cv::cuda::fastNlMeansDenoising(d_src, dst, h, search_widow_size, block_size);
133
134        CUDA_SANITY_CHECK(dst);
135    }
136    else
137    {
138        cv::Mat dst;
139
140        TEST_CYCLE() cv::fastNlMeansDenoising(src, dst, h, block_size, search_widow_size);
141
142        CPU_SANITY_CHECK(dst);
143    }
144}
145
146//////////////////////////////////////////////////////////////////////
147// fastNonLocalMeans (colored)
148
149DEF_PARAM_TEST(Sz_Depth_WinSz_BlockSz, cv::Size, MatDepth, int, int);
150
151PERF_TEST_P(Sz_Depth_WinSz_BlockSz, CUDA_FastNonLocalMeansColored,
152            Combine(CUDA_DENOISING_IMAGE_SIZES,
153                    Values<MatDepth>(CV_8U),
154                    Values(21),
155                    Values(7)))
156{
157    declare.time(60.0);
158
159    const cv::Size size = GET_PARAM(0);
160    const int depth = GET_PARAM(1);
161    const int search_widow_size = GET_PARAM(2);
162    const int block_size = GET_PARAM(3);
163
164    const float h = 10;
165    const int type = CV_MAKE_TYPE(depth, 3);
166
167    cv::Mat src(size, type);
168    declare.in(src, WARMUP_RNG);
169
170    if (PERF_RUN_CUDA())
171    {
172        const cv::cuda::GpuMat d_src(src);
173        cv::cuda::GpuMat dst;
174
175        TEST_CYCLE() cv::cuda::fastNlMeansDenoisingColored(d_src, dst, h, h, search_widow_size, block_size);
176
177        CUDA_SANITY_CHECK(dst);
178    }
179    else
180    {
181        cv::Mat dst;
182
183        TEST_CYCLE() cv::fastNlMeansDenoisingColored(src, dst, h, h, block_size, search_widow_size);
184
185        CPU_SANITY_CHECK(dst);
186    }
187}
188
189#endif
190