Merged upstream master
[profile/ivi/opencv.git] / modules / cudaimgproc / perf / perf_color.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 // CvtColor
51
52 DEF_PARAM_TEST(Sz_Depth_Code, cv::Size, MatDepth, CvtColorInfo);
53
54 PERF_TEST_P(Sz_Depth_Code, CvtColor,
55             Combine(CUDA_TYPICAL_MAT_SIZES,
56                     Values(CV_8U, CV_32F),
57                     Values(CvtColorInfo(4, 4, cv::COLOR_RGBA2BGRA),
58                            CvtColorInfo(4, 1, cv::COLOR_BGRA2GRAY),
59                            CvtColorInfo(1, 4, cv::COLOR_GRAY2BGRA),
60                            CvtColorInfo(3, 3, cv::COLOR_BGR2XYZ),
61                            CvtColorInfo(3, 3, cv::COLOR_XYZ2BGR),
62                            CvtColorInfo(3, 3, cv::COLOR_BGR2YCrCb),
63                            CvtColorInfo(3, 3, cv::COLOR_YCrCb2BGR),
64                            CvtColorInfo(3, 3, cv::COLOR_BGR2YUV),
65                            CvtColorInfo(3, 3, cv::COLOR_YUV2BGR),
66                            CvtColorInfo(3, 3, cv::COLOR_BGR2HSV),
67                            CvtColorInfo(3, 3, cv::COLOR_HSV2BGR),
68                            CvtColorInfo(3, 3, cv::COLOR_BGR2HLS),
69                            CvtColorInfo(3, 3, cv::COLOR_HLS2BGR),
70                            CvtColorInfo(3, 3, cv::COLOR_BGR2Lab),
71                            CvtColorInfo(3, 3, cv::COLOR_LBGR2Lab),
72                            CvtColorInfo(3, 3, cv::COLOR_BGR2Luv),
73                            CvtColorInfo(3, 3, cv::COLOR_LBGR2Luv),
74                            CvtColorInfo(3, 3, cv::COLOR_Lab2BGR),
75                            CvtColorInfo(3, 3, cv::COLOR_Lab2LBGR),
76                            CvtColorInfo(3, 3, cv::COLOR_Luv2RGB),
77                            CvtColorInfo(3, 3, cv::COLOR_Luv2LRGB))))
78 {
79     const cv::Size size = GET_PARAM(0);
80     const int depth = GET_PARAM(1);
81     const CvtColorInfo info = GET_PARAM(2);
82
83     cv::Mat src(size, CV_MAKETYPE(depth, info.scn));
84     cv::randu(src, 0, depth == CV_8U ? 255.0 : 1.0);
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::cvtColor(d_src, dst, info.code, info.dcn);
92
93         CUDA_SANITY_CHECK(dst, 1e-4);
94     }
95     else
96     {
97         cv::Mat dst;
98
99         TEST_CYCLE() cv::cvtColor(src, dst, info.code, info.dcn);
100
101         CPU_SANITY_CHECK(dst);
102     }
103 }
104
105 PERF_TEST_P(Sz_Depth_Code, CvtColorBayer,
106             Combine(CUDA_TYPICAL_MAT_SIZES,
107                     Values(CV_8U, CV_16U),
108                     Values(CvtColorInfo(1, 3, cv::COLOR_BayerBG2BGR),
109                            CvtColorInfo(1, 3, cv::COLOR_BayerGB2BGR),
110                            CvtColorInfo(1, 3, cv::COLOR_BayerRG2BGR),
111                            CvtColorInfo(1, 3, cv::COLOR_BayerGR2BGR),
112
113                            CvtColorInfo(1, 1, cv::COLOR_BayerBG2GRAY),
114                            CvtColorInfo(1, 1, cv::COLOR_BayerGB2GRAY),
115                            CvtColorInfo(1, 1, cv::COLOR_BayerRG2GRAY),
116                            CvtColorInfo(1, 1, cv::COLOR_BayerGR2GRAY))))
117 {
118     const cv::Size size = GET_PARAM(0);
119     const int depth = GET_PARAM(1);
120     const CvtColorInfo info = GET_PARAM(2);
121
122     cv::Mat src(size, CV_MAKETYPE(depth, info.scn));
123     declare.in(src, WARMUP_RNG);
124
125     if (PERF_RUN_CUDA())
126     {
127         const cv::cuda::GpuMat d_src(src);
128         cv::cuda::GpuMat dst;
129
130         TEST_CYCLE() cv::cuda::cvtColor(d_src, dst, info.code, info.dcn);
131
132         CUDA_SANITY_CHECK(dst);
133     }
134     else
135     {
136         cv::Mat dst;
137
138         TEST_CYCLE() cv::cvtColor(src, dst, info.code, info.dcn);
139
140         CPU_SANITY_CHECK(dst);
141     }
142 }
143
144 //////////////////////////////////////////////////////////////////////
145 // Demosaicing
146
147 CV_ENUM(DemosaicingCode,
148         cv::COLOR_BayerBG2BGR, cv::COLOR_BayerGB2BGR, cv::COLOR_BayerRG2BGR, cv::COLOR_BayerGR2BGR,
149         cv::COLOR_BayerBG2GRAY, cv::COLOR_BayerGB2GRAY, cv::COLOR_BayerRG2GRAY, cv::COLOR_BayerGR2GRAY,
150         cv::cuda::COLOR_BayerBG2BGR_MHT, cv::cuda::COLOR_BayerGB2BGR_MHT, cv::cuda::COLOR_BayerRG2BGR_MHT, cv::cuda::COLOR_BayerGR2BGR_MHT,
151         cv::cuda::COLOR_BayerBG2GRAY_MHT, cv::cuda::COLOR_BayerGB2GRAY_MHT, cv::cuda::COLOR_BayerRG2GRAY_MHT, cv::cuda::COLOR_BayerGR2GRAY_MHT)
152
153 DEF_PARAM_TEST(Sz_Code, cv::Size, DemosaicingCode);
154
155 PERF_TEST_P(Sz_Code, Demosaicing,
156             Combine(CUDA_TYPICAL_MAT_SIZES,
157                     DemosaicingCode::all()))
158 {
159     const cv::Size size = GET_PARAM(0);
160     const int code = GET_PARAM(1);
161
162     cv::Mat src(size, CV_8UC1);
163     declare.in(src, WARMUP_RNG);
164
165     if (PERF_RUN_CUDA())
166     {
167         const cv::cuda::GpuMat d_src(src);
168         cv::cuda::GpuMat dst;
169
170         TEST_CYCLE() cv::cuda::demosaicing(d_src, dst, code);
171
172         CUDA_SANITY_CHECK(dst);
173     }
174     else
175     {
176         if (code >= cv::COLOR_COLORCVT_MAX)
177         {
178             FAIL_NO_CPU();
179         }
180         else
181         {
182             cv::Mat dst;
183
184             TEST_CYCLE() cv::cvtColor(src, dst, code);
185
186             CPU_SANITY_CHECK(dst);
187         }
188     }
189 }
190
191 //////////////////////////////////////////////////////////////////////
192 // SwapChannels
193
194 PERF_TEST_P(Sz, SwapChannels,
195             CUDA_TYPICAL_MAT_SIZES)
196 {
197     const cv::Size size = GetParam();
198
199     cv::Mat src(size, CV_8UC4);
200     declare.in(src, WARMUP_RNG);
201
202     const int dstOrder[] = {2, 1, 0, 3};
203
204     if (PERF_RUN_CUDA())
205     {
206         cv::cuda::GpuMat dst(src);
207
208         TEST_CYCLE() cv::cuda::swapChannels(dst, dstOrder);
209
210         CUDA_SANITY_CHECK(dst);
211     }
212     else
213     {
214         FAIL_NO_CPU();
215     }
216 }
217
218 //////////////////////////////////////////////////////////////////////
219 // AlphaComp
220
221 CV_ENUM(AlphaOp, cv::cuda::ALPHA_OVER, cv::cuda::ALPHA_IN, cv::cuda::ALPHA_OUT, cv::cuda::ALPHA_ATOP, cv::cuda::ALPHA_XOR, cv::cuda::ALPHA_PLUS, cv::cuda::ALPHA_OVER_PREMUL, cv::cuda::ALPHA_IN_PREMUL, cv::cuda::ALPHA_OUT_PREMUL, cv::cuda::ALPHA_ATOP_PREMUL, cv::cuda::ALPHA_XOR_PREMUL, cv::cuda::ALPHA_PLUS_PREMUL, cv::cuda::ALPHA_PREMUL)
222
223 DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, AlphaOp);
224
225 PERF_TEST_P(Sz_Type_Op, AlphaComp,
226             Combine(CUDA_TYPICAL_MAT_SIZES,
227                     Values(CV_8UC4, CV_16UC4, CV_32SC4, CV_32FC4),
228                     AlphaOp::all()))
229 {
230     const cv::Size size = GET_PARAM(0);
231     const int type = GET_PARAM(1);
232     const int alpha_op = GET_PARAM(2);
233
234     cv::Mat img1(size, type);
235     cv::Mat img2(size, type);
236     declare.in(img1, img2, WARMUP_RNG);
237
238     if (PERF_RUN_CUDA())
239     {
240         const cv::cuda::GpuMat d_img1(img1);
241         const cv::cuda::GpuMat d_img2(img2);
242         cv::cuda::GpuMat dst;
243
244         TEST_CYCLE() cv::cuda::alphaComp(d_img1, d_img2, dst, alpha_op);
245
246         if (CV_MAT_DEPTH(type) < CV_32F)
247         {
248             CUDA_SANITY_CHECK(dst, 1);
249         }
250         else
251         {
252             CUDA_SANITY_CHECK(dst, 1e-3, ERROR_RELATIVE);
253         }
254     }
255     else
256     {
257         FAIL_NO_CPU();
258     }
259 }