• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Remap
51 
52 enum { HALF_SIZE=0, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH };
CV_ENUM(RemapMode,HALF_SIZE,UPSIDE_DOWN,REFLECTION_X,REFLECTION_BOTH)53 CV_ENUM(RemapMode, HALF_SIZE, UPSIDE_DOWN, REFLECTION_X, REFLECTION_BOTH)
54 
55 void generateMap(cv::Mat& map_x, cv::Mat& map_y, int remapMode)
56 {
57     for (int j = 0; j < map_x.rows; ++j)
58     {
59         for (int i = 0; i < map_x.cols; ++i)
60         {
61             switch (remapMode)
62             {
63             case HALF_SIZE:
64                 if (i > map_x.cols*0.25 && i < map_x.cols*0.75 && j > map_x.rows*0.25 && j < map_x.rows*0.75)
65                 {
66                     map_x.at<float>(j,i) = 2.f * (i - map_x.cols * 0.25f) + 0.5f;
67                     map_y.at<float>(j,i) = 2.f * (j - map_x.rows * 0.25f) + 0.5f;
68                 }
69                 else
70                 {
71                     map_x.at<float>(j,i) = 0.f;
72                     map_y.at<float>(j,i) = 0.f;
73                 }
74                 break;
75             case UPSIDE_DOWN:
76                 map_x.at<float>(j,i) = static_cast<float>(i);
77                 map_y.at<float>(j,i) = static_cast<float>(map_x.rows - j);
78                 break;
79             case REFLECTION_X:
80                 map_x.at<float>(j,i) = static_cast<float>(map_x.cols - i);
81                 map_y.at<float>(j,i) = static_cast<float>(j);
82                 break;
83             case REFLECTION_BOTH:
84                 map_x.at<float>(j,i) = static_cast<float>(map_x.cols - i);
85                 map_y.at<float>(j,i) = static_cast<float>(map_x.rows - j);
86                 break;
87             } // end of switch
88         }
89     }
90 }
91 
92 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border_Mode, cv::Size, MatDepth, MatCn, Interpolation, BorderMode, RemapMode);
93 
PERF_TEST_P(Sz_Depth_Cn_Inter_Border_Mode,Remap,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F),CUDA_CHANNELS_1_3_4,Values (Interpolation (cv::INTER_NEAREST),Interpolation (cv::INTER_LINEAR),Interpolation (cv::INTER_CUBIC)),ALL_BORDER_MODES,RemapMode::all ()))94 PERF_TEST_P(Sz_Depth_Cn_Inter_Border_Mode, Remap,
95             Combine(CUDA_TYPICAL_MAT_SIZES,
96                     Values(CV_8U, CV_16U, CV_32F),
97                     CUDA_CHANNELS_1_3_4,
98                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
99                     ALL_BORDER_MODES,
100                     RemapMode::all()))
101 {
102     declare.time(20.0);
103 
104     const cv::Size size = GET_PARAM(0);
105     const int depth = GET_PARAM(1);
106     const int channels = GET_PARAM(2);
107     const int interpolation = GET_PARAM(3);
108     const int borderMode = GET_PARAM(4);
109     const int remapMode = GET_PARAM(5);
110 
111     const int type = CV_MAKE_TYPE(depth, channels);
112 
113     cv::Mat src(size, type);
114     declare.in(src, WARMUP_RNG);
115 
116     cv::Mat xmap(size, CV_32FC1);
117     cv::Mat ymap(size, CV_32FC1);
118     generateMap(xmap, ymap, remapMode);
119 
120     if (PERF_RUN_CUDA())
121     {
122         const cv::cuda::GpuMat d_src(src);
123         const cv::cuda::GpuMat d_xmap(xmap);
124         const cv::cuda::GpuMat d_ymap(ymap);
125         cv::cuda::GpuMat dst;
126 
127         TEST_CYCLE() cv::cuda::remap(d_src, dst, d_xmap, d_ymap, interpolation, borderMode);
128 
129         CUDA_SANITY_CHECK(dst);
130     }
131     else
132     {
133         cv::Mat dst;
134 
135         TEST_CYCLE() cv::remap(src, dst, xmap, ymap, interpolation, borderMode);
136 
137         CPU_SANITY_CHECK(dst);
138     }
139 }
140 
141 //////////////////////////////////////////////////////////////////////
142 // Resize
143 
144 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Scale, cv::Size, MatDepth, MatCn, Interpolation, double);
145 
146 PERF_TEST_P(Sz_Depth_Cn_Inter_Scale, Resize,
147             Combine(CUDA_TYPICAL_MAT_SIZES,
148                     Values(CV_8U, CV_16U, CV_32F),
149                     CUDA_CHANNELS_1_3_4,
150                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
151                     Values(0.5, 0.3, 2.0)))
152 {
153     declare.time(20.0);
154 
155     const cv::Size size = GET_PARAM(0);
156     const int depth = GET_PARAM(1);
157     const int channels = GET_PARAM(2);
158     const int interpolation = GET_PARAM(3);
159     const double f = GET_PARAM(4);
160 
161     const int type = CV_MAKE_TYPE(depth, channels);
162 
163     cv::Mat src(size, type);
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 
171         TEST_CYCLE() cv::cuda::resize(d_src, dst, cv::Size(), f, f, interpolation);
172 
173         CUDA_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
174     }
175     else
176     {
177         cv::Mat dst;
178 
179         TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation);
180 
181         CPU_SANITY_CHECK(dst);
182     }
183 }
184 
185 //////////////////////////////////////////////////////////////////////
186 // ResizeArea
187 
188 DEF_PARAM_TEST(Sz_Depth_Cn_Scale, cv::Size, MatDepth, MatCn, double);
189 
190 PERF_TEST_P(Sz_Depth_Cn_Scale, ResizeArea,
191             Combine(CUDA_TYPICAL_MAT_SIZES,
192                     Values(CV_8U, CV_16U, CV_32F),
193                     CUDA_CHANNELS_1_3_4,
194                     Values(0.2, 0.1, 0.05)))
195 {
196     declare.time(1.0);
197 
198     const cv::Size size = GET_PARAM(0);
199     const int depth = GET_PARAM(1);
200     const int channels = GET_PARAM(2);
201     const int interpolation = cv::INTER_AREA;
202     const double f = GET_PARAM(3);
203 
204     const int type = CV_MAKE_TYPE(depth, channels);
205 
206     cv::Mat src(size, type);
207     declare.in(src, WARMUP_RNG);
208 
209     if (PERF_RUN_CUDA())
210     {
211         const cv::cuda::GpuMat d_src(src);
212         cv::cuda::GpuMat dst;
213 
214         TEST_CYCLE() cv::cuda::resize(d_src, dst, cv::Size(), f, f, interpolation);
215 
216         CUDA_SANITY_CHECK(dst);
217     }
218     else
219     {
220         cv::Mat dst;
221 
222         TEST_CYCLE() cv::resize(src, dst, cv::Size(), f, f, interpolation);
223 
224         CPU_SANITY_CHECK(dst);
225     }
226 }
227 
228 //////////////////////////////////////////////////////////////////////
229 // WarpAffine
230 
231 DEF_PARAM_TEST(Sz_Depth_Cn_Inter_Border, cv::Size, MatDepth, MatCn, Interpolation, BorderMode);
232 
PERF_TEST_P(Sz_Depth_Cn_Inter_Border,WarpAffine,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F),CUDA_CHANNELS_1_3_4,Values (Interpolation (cv::INTER_NEAREST),Interpolation (cv::INTER_LINEAR),Interpolation (cv::INTER_CUBIC)),ALL_BORDER_MODES))233 PERF_TEST_P(Sz_Depth_Cn_Inter_Border, WarpAffine,
234             Combine(CUDA_TYPICAL_MAT_SIZES,
235                     Values(CV_8U, CV_16U, CV_32F),
236                     CUDA_CHANNELS_1_3_4,
237                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
238                     ALL_BORDER_MODES))
239 {
240     declare.time(20.0);
241 
242     const cv::Size size = GET_PARAM(0);
243     const int depth = GET_PARAM(1);
244     const int channels = GET_PARAM(2);
245     const int interpolation = GET_PARAM(3);
246     const int borderMode = GET_PARAM(4);
247 
248     const int type = CV_MAKE_TYPE(depth, channels);
249 
250     cv::Mat src(size, type);
251     declare.in(src, WARMUP_RNG);
252 
253     const double aplha = CV_PI / 4;
254     const double mat[2 * 3] =
255     {
256         std::cos(aplha), -std::sin(aplha), static_cast<double>(src.cols) / 2.0,
257         std::sin(aplha),  std::cos(aplha), 0
258     };
259     const cv::Mat M(2, 3, CV_64F, (void*) mat);
260 
261     if (PERF_RUN_CUDA())
262     {
263         const cv::cuda::GpuMat d_src(src);
264         cv::cuda::GpuMat dst;
265 
266         TEST_CYCLE() cv::cuda::warpAffine(d_src, dst, M, size, interpolation, borderMode);
267 
268         CUDA_SANITY_CHECK(dst, 1);
269     }
270     else
271     {
272         cv::Mat dst;
273 
274         TEST_CYCLE() cv::warpAffine(src, dst, M, size, interpolation, borderMode);
275 
276         CPU_SANITY_CHECK(dst);
277     }
278 }
279 
280 //////////////////////////////////////////////////////////////////////
281 // WarpPerspective
282 
PERF_TEST_P(Sz_Depth_Cn_Inter_Border,WarpPerspective,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F),CUDA_CHANNELS_1_3_4,Values (Interpolation (cv::INTER_NEAREST),Interpolation (cv::INTER_LINEAR),Interpolation (cv::INTER_CUBIC)),ALL_BORDER_MODES))283 PERF_TEST_P(Sz_Depth_Cn_Inter_Border, WarpPerspective,
284             Combine(CUDA_TYPICAL_MAT_SIZES,
285                     Values(CV_8U, CV_16U, CV_32F),
286                     CUDA_CHANNELS_1_3_4,
287                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
288                     ALL_BORDER_MODES))
289 {
290     declare.time(20.0);
291 
292     const cv::Size size = GET_PARAM(0);
293     const int depth = GET_PARAM(1);
294     const int channels = GET_PARAM(2);
295     const int interpolation = GET_PARAM(3);
296     const int borderMode = GET_PARAM(4);
297 
298     const int type = CV_MAKE_TYPE(depth, channels);
299 
300     cv::Mat src(size, type);
301     declare.in(src, WARMUP_RNG);
302 
303     const double aplha = CV_PI / 4;
304     double mat[3][3] = { {std::cos(aplha), -std::sin(aplha), static_cast<double>(src.cols) / 2.0},
305                          {std::sin(aplha),  std::cos(aplha), 0},
306                          {0.0,              0.0,             1.0}};
307     const cv::Mat M(3, 3, CV_64F, (void*) mat);
308 
309     if (PERF_RUN_CUDA())
310     {
311         const cv::cuda::GpuMat d_src(src);
312         cv::cuda::GpuMat dst;
313 
314         TEST_CYCLE() cv::cuda::warpPerspective(d_src, dst, M, size, interpolation, borderMode);
315 
316         CUDA_SANITY_CHECK(dst, 1);
317     }
318     else
319     {
320         cv::Mat dst;
321 
322         TEST_CYCLE() cv::warpPerspective(src, dst, M, size, interpolation, borderMode);
323 
324         CPU_SANITY_CHECK(dst);
325     }
326 }
327 
328 //////////////////////////////////////////////////////////////////////
329 // Rotate
330 
331 DEF_PARAM_TEST(Sz_Depth_Cn_Inter, cv::Size, MatDepth, MatCn, Interpolation);
332 
PERF_TEST_P(Sz_Depth_Cn_Inter,Rotate,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F),CUDA_CHANNELS_1_3_4,Values (Interpolation (cv::INTER_NEAREST),Interpolation (cv::INTER_LINEAR),Interpolation (cv::INTER_CUBIC))))333 PERF_TEST_P(Sz_Depth_Cn_Inter, Rotate,
334             Combine(CUDA_TYPICAL_MAT_SIZES,
335                     Values(CV_8U, CV_16U, CV_32F),
336                     CUDA_CHANNELS_1_3_4,
337                     Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))))
338 {
339     const cv::Size size = GET_PARAM(0);
340     const int depth = GET_PARAM(1);
341     const int channels = GET_PARAM(2);
342     const int interpolation = GET_PARAM(3);
343 
344     const int type = CV_MAKE_TYPE(depth, channels);
345 
346     cv::Mat src(size, type);
347     declare.in(src, WARMUP_RNG);
348 
349     if (PERF_RUN_CUDA())
350     {
351         const cv::cuda::GpuMat d_src(src);
352         cv::cuda::GpuMat dst;
353 
354         TEST_CYCLE() cv::cuda::rotate(d_src, dst, size, 30.0, 0, 0, interpolation);
355 
356         CUDA_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
357     }
358     else
359     {
360         FAIL_NO_CPU();
361     }
362 }
363 
364 //////////////////////////////////////////////////////////////////////
365 // PyrDown
366 
PERF_TEST_P(Sz_Depth_Cn,PyrDown,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F),CUDA_CHANNELS_1_3_4))367 PERF_TEST_P(Sz_Depth_Cn, PyrDown,
368             Combine(CUDA_TYPICAL_MAT_SIZES,
369                     Values(CV_8U, CV_16U, CV_32F),
370                     CUDA_CHANNELS_1_3_4))
371 {
372     const cv::Size size = GET_PARAM(0);
373     const int depth = GET_PARAM(1);
374     const int channels = GET_PARAM(2);
375 
376     const int type = CV_MAKE_TYPE(depth, channels);
377 
378     cv::Mat src(size, type);
379     declare.in(src, WARMUP_RNG);
380 
381     if (PERF_RUN_CUDA())
382     {
383         const cv::cuda::GpuMat d_src(src);
384         cv::cuda::GpuMat dst;
385 
386         TEST_CYCLE() cv::cuda::pyrDown(d_src, dst);
387 
388         CUDA_SANITY_CHECK(dst);
389     }
390     else
391     {
392         cv::Mat dst;
393 
394         TEST_CYCLE() cv::pyrDown(src, dst);
395 
396         CPU_SANITY_CHECK(dst);
397     }
398 }
399 
400 //////////////////////////////////////////////////////////////////////
401 // PyrUp
402 
PERF_TEST_P(Sz_Depth_Cn,PyrUp,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F),CUDA_CHANNELS_1_3_4))403 PERF_TEST_P(Sz_Depth_Cn, PyrUp,
404             Combine(CUDA_TYPICAL_MAT_SIZES,
405                     Values(CV_8U, CV_16U, CV_32F),
406                     CUDA_CHANNELS_1_3_4))
407 {
408     const cv::Size size = GET_PARAM(0);
409     const int depth = GET_PARAM(1);
410     const int channels = GET_PARAM(2);
411 
412     const int type = CV_MAKE_TYPE(depth, channels);
413 
414     cv::Mat src(size, type);
415     declare.in(src, WARMUP_RNG);
416 
417     if (PERF_RUN_CUDA())
418     {
419         const cv::cuda::GpuMat d_src(src);
420         cv::cuda::GpuMat dst;
421 
422         TEST_CYCLE() cv::cuda::pyrUp(d_src, dst);
423 
424         CUDA_SANITY_CHECK(dst);
425     }
426     else
427     {
428         cv::Mat dst;
429 
430         TEST_CYCLE() cv::pyrUp(src, dst);
431 
432         CPU_SANITY_CHECK(dst);
433     }
434 }
435