Merge pull request #2468 from mlyashko:back_proj_fix
[profile/ivi/opencv.git] / modules / cudaimgproc / perf / perf_histogram.cpp
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 using namespace std;
46 using namespace testing;
47 using namespace perf;
48
49 //////////////////////////////////////////////////////////////////////
50 // HistEvenC1
51
52 PERF_TEST_P(Sz_Depth, HistEvenC1,
53             Combine(CUDA_TYPICAL_MAT_SIZES,
54                     Values(CV_8U, CV_16U, CV_16S)))
55 {
56     const cv::Size size = GET_PARAM(0);
57     const int depth = GET_PARAM(1);
58
59     cv::Mat src(size, depth);
60     declare.in(src, WARMUP_RNG);
61
62     if (PERF_RUN_CUDA())
63     {
64         const cv::cuda::GpuMat d_src(src);
65         cv::cuda::GpuMat dst;
66         cv::cuda::GpuMat d_buf;
67
68         TEST_CYCLE() cv::cuda::histEven(d_src, dst, d_buf, 30, 0, 180);
69
70         CUDA_SANITY_CHECK(dst);
71     }
72     else
73     {
74         const int hbins = 30;
75         const float hranges[] = {0.0f, 180.0f};
76         const int histSize[] = {hbins};
77         const float* ranges[] = {hranges};
78         const int channels[] = {0};
79
80         cv::Mat dst;
81
82         TEST_CYCLE() cv::calcHist(&src, 1, channels, cv::Mat(), dst, 1, histSize, ranges);
83
84         CPU_SANITY_CHECK(dst);
85     }
86 }
87
88 //////////////////////////////////////////////////////////////////////
89 // HistEvenC4
90
91 PERF_TEST_P(Sz_Depth, HistEvenC4,
92             Combine(CUDA_TYPICAL_MAT_SIZES,
93                     Values(CV_8U, CV_16U, CV_16S)))
94 {
95     const cv::Size size = GET_PARAM(0);
96     const int depth = GET_PARAM(1);
97
98     cv::Mat src(size, CV_MAKE_TYPE(depth, 4));
99     declare.in(src, WARMUP_RNG);
100
101     int histSize[] = {30, 30, 30, 30};
102     int lowerLevel[] = {0, 0, 0, 0};
103     int upperLevel[] = {180, 180, 180, 180};
104
105     if (PERF_RUN_CUDA())
106     {
107         const cv::cuda::GpuMat d_src(src);
108         cv::cuda::GpuMat d_hist[4];
109         cv::cuda::GpuMat d_buf;
110
111         TEST_CYCLE() cv::cuda::histEven(d_src, d_hist, d_buf, histSize, lowerLevel, upperLevel);
112
113         cv::Mat cpu_hist0, cpu_hist1, cpu_hist2, cpu_hist3;
114         d_hist[0].download(cpu_hist0);
115         d_hist[1].download(cpu_hist1);
116         d_hist[2].download(cpu_hist2);
117         d_hist[3].download(cpu_hist3);
118         SANITY_CHECK(cpu_hist0);
119         SANITY_CHECK(cpu_hist1);
120         SANITY_CHECK(cpu_hist2);
121         SANITY_CHECK(cpu_hist3);
122     }
123     else
124     {
125         FAIL_NO_CPU();
126     }
127 }
128
129 //////////////////////////////////////////////////////////////////////
130 // CalcHist
131
132 PERF_TEST_P(Sz, CalcHist,
133             CUDA_TYPICAL_MAT_SIZES)
134 {
135     const cv::Size size = GetParam();
136
137     cv::Mat src(size, CV_8UC1);
138     declare.in(src, WARMUP_RNG);
139
140     if (PERF_RUN_CUDA())
141     {
142         const cv::cuda::GpuMat d_src(src);
143         cv::cuda::GpuMat dst;
144
145         TEST_CYCLE() cv::cuda::calcHist(d_src, dst);
146
147         CUDA_SANITY_CHECK(dst);
148     }
149     else
150     {
151         FAIL_NO_CPU();
152     }
153 }
154
155 //////////////////////////////////////////////////////////////////////
156 // EqualizeHist
157
158 PERF_TEST_P(Sz, EqualizeHist,
159             CUDA_TYPICAL_MAT_SIZES)
160 {
161     const cv::Size size = GetParam();
162
163     cv::Mat src(size, CV_8UC1);
164     declare.in(src, WARMUP_RNG);
165
166     if (PERF_RUN_CUDA())
167     {
168         const cv::cuda::GpuMat d_src(src);
169         cv::cuda::GpuMat dst;
170         cv::cuda::GpuMat d_buf;
171
172         TEST_CYCLE() cv::cuda::equalizeHist(d_src, dst, d_buf);
173
174         CUDA_SANITY_CHECK(dst);
175     }
176     else
177     {
178         cv::Mat dst;
179
180         TEST_CYCLE() cv::equalizeHist(src, dst);
181
182         CPU_SANITY_CHECK(dst);
183     }
184 }
185
186 //////////////////////////////////////////////////////////////////////
187 // CLAHE
188
189 DEF_PARAM_TEST(Sz_ClipLimit, cv::Size, double);
190
191 PERF_TEST_P(Sz_ClipLimit, CLAHE,
192             Combine(CUDA_TYPICAL_MAT_SIZES,
193                     Values(0.0, 40.0)))
194 {
195     const cv::Size size = GET_PARAM(0);
196     const double clipLimit = GET_PARAM(1);
197
198     cv::Mat src(size, CV_8UC1);
199     declare.in(src, WARMUP_RNG);
200
201     if (PERF_RUN_CUDA())
202     {
203         cv::Ptr<cv::cuda::CLAHE> clahe = cv::cuda::createCLAHE(clipLimit);
204         cv::cuda::GpuMat d_src(src);
205         cv::cuda::GpuMat dst;
206
207         TEST_CYCLE() clahe->apply(d_src, dst);
208
209         CUDA_SANITY_CHECK(dst);
210     }
211     else
212     {
213         cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(clipLimit);
214         cv::Mat dst;
215
216         TEST_CYCLE() clahe->apply(src, dst);
217
218         CPU_SANITY_CHECK(dst);
219     }
220 }