fixed ocl tests for BlendLinear, BoxFilter, Integral
[profile/ivi/opencv.git] / modules / imgproc / test / ocl / test_boxfilter.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) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
16 // Third party copyrights are property of their respective owners.
17 //
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
20 //
21 //   * Redistribution's of source code must retain the above copyright notice,
22 //     this list of conditions and the following disclaimer.
23 //
24 //   * Redistribution's in binary form must reproduce the above copyright notice,
25 //     this list of conditions and the following disclaimer in the documentation
26 //     and/or other materials provided with the distribution.
27 //
28 //   * The name of the copyright holders may not be used to endorse or promote products
29 //     derived from this software without specific prior written permission.
30 //
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
41 //
42 //M*/
43
44 #include "test_precomp.hpp"
45 #include "opencv2/ts/ocl_test.hpp"
46
47 #ifdef HAVE_OPENCL
48
49 namespace cvtest {
50 namespace ocl {
51
52 ////////////////////////////////////////// boxFilter ///////////////////////////////////////////////////////
53
54 PARAM_TEST_CASE(BoxFilterBase, MatDepth, Channels, BorderType, bool, bool)
55 {
56     static const int kernelMinSize = 2;
57     static const int kernelMaxSize = 10;
58
59     int depth, cn, borderType;
60     Size ksize, dsize;
61     Point anchor;
62     bool normalize, useRoi;
63
64     TEST_DECLARE_INPUT_PARAMETER(src);
65     TEST_DECLARE_OUTPUT_PARAMETER(dst);
66
67     virtual void SetUp()
68     {
69         depth = GET_PARAM(0);
70         cn = GET_PARAM(1);
71         borderType = GET_PARAM(2); // only not isolated border tested, because CPU module doesn't support isolated border case.
72         normalize = GET_PARAM(3);
73         useRoi = GET_PARAM(4);
74     }
75
76     void random_roi()
77     {
78         int type = CV_MAKE_TYPE(depth, cn);
79         ksize = randomSize(kernelMinSize, kernelMaxSize);
80
81         Size roiSize = randomSize(ksize.width, MAX_VALUE, ksize.height, MAX_VALUE);
82         Border srcBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
83         randomSubMat(src, src_roi, roiSize, srcBorder, type, -MAX_VALUE, MAX_VALUE);
84
85         Border dstBorder = randomBorder(0, useRoi ? MAX_VALUE : 0);
86         randomSubMat(dst, dst_roi, roiSize, dstBorder, type, -MAX_VALUE, MAX_VALUE);
87
88         anchor.x = randomInt(-1, ksize.width);
89         anchor.y = randomInt(-1, ksize.height);
90
91         UMAT_UPLOAD_INPUT_PARAMETER(src);
92         UMAT_UPLOAD_OUTPUT_PARAMETER(dst);
93     }
94
95     void Near(double threshold = 0.0)
96     {
97         OCL_EXPECT_MATS_NEAR(dst, threshold);
98     }
99 };
100
101 typedef BoxFilterBase BoxFilter;
102
103 OCL_TEST_P(BoxFilter, Mat)
104 {
105     for (int j = 0; j < test_loop_times; j++)
106     {
107         random_roi();
108
109         OCL_OFF(cv::boxFilter(src_roi, dst_roi, -1, ksize, anchor, normalize, borderType));
110         OCL_ON(cv::boxFilter(usrc_roi, udst_roi, -1, ksize, anchor, normalize, borderType));
111
112         Near(depth <= CV_32S ? 1 : 3e-3);
113     }
114 }
115
116 typedef BoxFilterBase SqrBoxFilter;
117
118 OCL_TEST_P(SqrBoxFilter, Mat)
119 {
120     for (int j = 0; j < test_loop_times; j++)
121     {
122         random_roi();
123
124         int ddepth = depth == CV_8U ? CV_32S : CV_64F;
125
126         OCL_OFF(cv::sqrBoxFilter(src_roi, dst_roi, ddepth, ksize, anchor, normalize, borderType));
127         OCL_ON(cv::sqrBoxFilter(usrc_roi, udst_roi, ddepth, ksize, anchor, normalize, borderType));
128
129         Near(depth <= CV_32S ? 1 : 7e-2);
130     }
131 }
132
133 OCL_INSTANTIATE_TEST_CASE_P(ImageProc, BoxFilter,
134                             Combine(
135                                 Values(CV_8U, CV_16U, CV_16S, CV_32S, CV_32F),
136                                 OCL_ALL_CHANNELS,
137                                 Values((BorderType)BORDER_CONSTANT,
138                                        (BorderType)BORDER_REPLICATE,
139                                        (BorderType)BORDER_REFLECT,
140                                        (BorderType)BORDER_REFLECT_101),
141                                 Bool(),
142                                 Bool()  // ROI
143                                 )
144                            );
145
146 OCL_INSTANTIATE_TEST_CASE_P(ImageProc, SqrBoxFilter,
147                             Combine(
148                                 Values(CV_8U, CV_16U, CV_16S, CV_32F, CV_64F),
149                                 OCL_ALL_CHANNELS,
150                                 Values((BorderType)BORDER_CONSTANT,
151                                        (BorderType)BORDER_REPLICATE,
152                                        (BorderType)BORDER_REFLECT,
153                                        (BorderType)BORDER_REFLECT_101),
154                                 Bool(),
155                                 Bool()  // ROI
156                                 )
157                            );
158
159
160 } } // namespace cvtest::ocl
161
162 #endif // HAVE_OPENCL