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 #ifdef HAVE_CUDA
46 
47 #include "opencv2/core/cuda.hpp"
48 #include "opencv2/ts/cuda_perf.hpp"
49 
50 using namespace std;
51 using namespace testing;
52 using namespace perf;
53 
54 //////////////////////////////////////////////////////////////////////
55 // SetTo
56 
PERF_TEST_P(Sz_Depth_Cn,CUDA_GpuMat_SetTo,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F,CV_64F),CUDA_CHANNELS_1_3_4))57 PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_SetTo,
58             Combine(CUDA_TYPICAL_MAT_SIZES,
59                     Values(CV_8U, CV_16U, CV_32F, CV_64F),
60                     CUDA_CHANNELS_1_3_4))
61 {
62     const cv::Size size = GET_PARAM(0);
63     const int depth = GET_PARAM(1);
64     const int channels = GET_PARAM(2);
65 
66     const int type = CV_MAKE_TYPE(depth, channels);
67 
68     const cv::Scalar val(1, 2, 3, 4);
69 
70     if (PERF_RUN_CUDA())
71     {
72         cv::cuda::GpuMat dst(size, type);
73 
74         TEST_CYCLE() dst.setTo(val);
75     }
76     else
77     {
78         cv::Mat dst(size, type);
79 
80         TEST_CYCLE() dst.setTo(val);
81     }
82 
83     SANITY_CHECK_NOTHING();
84 }
85 
86 //////////////////////////////////////////////////////////////////////
87 // SetToMasked
88 
PERF_TEST_P(Sz_Depth_Cn,CUDA_GpuMat_SetToMasked,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F,CV_64F),CUDA_CHANNELS_1_3_4))89 PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_SetToMasked,
90             Combine(CUDA_TYPICAL_MAT_SIZES,
91                     Values(CV_8U, CV_16U, CV_32F, CV_64F),
92                     CUDA_CHANNELS_1_3_4))
93 {
94     const cv::Size size = GET_PARAM(0);
95     const int depth = GET_PARAM(1);
96     const int channels = GET_PARAM(2);
97 
98     const int type = CV_MAKE_TYPE(depth, channels);
99 
100     cv::Mat src(size, type);
101     cv::Mat mask(size, CV_8UC1);
102     declare.in(src, mask, WARMUP_RNG);
103 
104     const cv::Scalar val(1, 2, 3, 4);
105 
106     if (PERF_RUN_CUDA())
107     {
108         cv::cuda::GpuMat dst(src);
109         const cv::cuda::GpuMat d_mask(mask);
110 
111         TEST_CYCLE() dst.setTo(val, d_mask);
112     }
113     else
114     {
115         cv::Mat dst = src;
116 
117         TEST_CYCLE() dst.setTo(val, mask);
118     }
119 
120     SANITY_CHECK_NOTHING();
121 }
122 
123 //////////////////////////////////////////////////////////////////////
124 // CopyToMasked
125 
PERF_TEST_P(Sz_Depth_Cn,CUDA_GpuMat_CopyToMasked,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F,CV_64F),CUDA_CHANNELS_1_3_4))126 PERF_TEST_P(Sz_Depth_Cn, CUDA_GpuMat_CopyToMasked,
127             Combine(CUDA_TYPICAL_MAT_SIZES,
128                     Values(CV_8U, CV_16U, CV_32F, CV_64F),
129                     CUDA_CHANNELS_1_3_4))
130 {
131     const cv::Size size = GET_PARAM(0);
132     const int depth = GET_PARAM(1);
133     const int channels = GET_PARAM(2);
134 
135     const int type = CV_MAKE_TYPE(depth, channels);
136 
137     cv::Mat src(size, type);
138     cv::Mat mask(size, CV_8UC1);
139     declare.in(src, mask, WARMUP_RNG);
140 
141     if (PERF_RUN_CUDA())
142     {
143         const cv::cuda::GpuMat d_src(src);
144         const cv::cuda::GpuMat d_mask(mask);
145         cv::cuda::GpuMat dst(d_src.size(), d_src.type(), cv::Scalar::all(0));
146 
147         TEST_CYCLE() d_src.copyTo(dst, d_mask);
148     }
149     else
150     {
151         cv::Mat dst(src.size(), src.type(), cv::Scalar::all(0));
152 
153         TEST_CYCLE() src.copyTo(dst, mask);
154     }
155 
156     SANITY_CHECK_NOTHING();
157 }
158 
159 //////////////////////////////////////////////////////////////////////
160 // ConvertTo
161 
162 DEF_PARAM_TEST(Sz_2Depth, cv::Size, MatDepth, MatDepth);
163 
PERF_TEST_P(Sz_2Depth,CUDA_GpuMat_ConvertTo,Combine (CUDA_TYPICAL_MAT_SIZES,Values (CV_8U,CV_16U,CV_32F,CV_64F),Values (CV_8U,CV_16U,CV_32F,CV_64F)))164 PERF_TEST_P(Sz_2Depth, CUDA_GpuMat_ConvertTo,
165             Combine(CUDA_TYPICAL_MAT_SIZES,
166                     Values(CV_8U, CV_16U, CV_32F, CV_64F),
167                     Values(CV_8U, CV_16U, CV_32F, CV_64F)))
168 {
169     const cv::Size size = GET_PARAM(0);
170     const int depth1 = GET_PARAM(1);
171     const int depth2 = GET_PARAM(2);
172 
173     cv::Mat src(size, depth1);
174     declare.in(src, WARMUP_RNG);
175 
176     const double a = 0.5;
177     const double b = 1.0;
178 
179     if (PERF_RUN_CUDA())
180     {
181         const cv::cuda::GpuMat d_src(src);
182         cv::cuda::GpuMat dst;
183 
184         TEST_CYCLE() d_src.convertTo(dst, depth2, a, b);
185     }
186     else
187     {
188         cv::Mat dst;
189 
190         TEST_CYCLE() src.convertTo(dst, depth2, a, b);
191     }
192 
193     SANITY_CHECK_NOTHING();
194 }
195 
196 #endif
197