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