1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
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.
19 // Jia Haipeng, jiahaipeng95@gmail.com
21 // Redistribution and use in source and binary forms, with or without modification,
22 // are permitted provided that the following conditions are met:
24 // * Redistribution's of source code must retain the above copyright notice,
25 // this list of conditions and the following disclaimer.
27 // * Redistribution's in binary form must reproduce the above copyright notice,
28 // this list of conditions and the following disclaimer in the documentation
29 // and/or other oclMaterials provided with the distribution.
31 // * The name of the copyright holders may not be used to endorse or promote products
32 // derived from this software without specific prior written permission.
34 // This software is provided by the copyright holders and contributors "as is" and
35 // any express or implied warranties, including, but not limited to, the implied
36 // warranties of merchantability and fitness for a particular purpose are disclaimed.
37 // In no event shall the Intel Corporation or contributors be liable for any direct,
38 // indirect, incidental, special, exemplary, or consequential damages
39 // (including, but not limited to, procurement of substitute goods or services;
40 // loss of use, data, or profits; or business interruption) however caused
41 // and on any theory of liability, whether in contract, strict liability,
42 // or tort (including negligence or otherwise) arising in any way out of
43 // the use of this software, even if advised of the possibility of such damage.
47 #include "test_precomp.hpp"
51 using namespace cvtest;
52 using namespace testing;
55 #define MAX_CHANNELS 4
57 PARAM_TEST_CASE(MergeTestBase, MatType, int, bool)
64 cv::Mat mat[MAX_CHANNELS];
70 int srcx[MAX_CHANNELS];
71 int srcy[MAX_CHANNELS];
75 cv::Mat mat_roi[MAX_CHANNELS];
80 //ocl dst mat for testing
81 cv::ocl::oclMat gdst_whole;
84 cv::ocl::oclMat gmat[MAX_CHANNELS];
90 channels = GET_PARAM(1);
91 use_roi = GET_PARAM(2);
93 cv::Size size(MWIDTH, MHEIGHT);
95 for (int i = 0; i < channels; ++i)
96 mat[i] = randomMat(size, CV_MAKETYPE(type, 1), 5, 16, false);
97 dst = randomMat(size, CV_MAKETYPE(type, channels), 5, 16, false);
105 roicols = rng.uniform(1, mat[0].cols);
106 roirows = rng.uniform(1, mat[0].rows);
108 for (int i = 0; i < channels; ++i)
110 srcx[i] = rng.uniform(0, mat[i].cols - roicols);
111 srcy[i] = rng.uniform(0, mat[i].rows - roirows);
114 dstx = rng.uniform(0, dst.cols - roicols);
115 dsty = rng.uniform(0, dst.rows - roirows);
119 roicols = mat[0].cols;
120 roirows = mat[0].rows;
121 for (int i = 0; i < channels; ++i)
122 srcx[i] = srcy[i] = 0;
127 for (int i = 0; i < channels; ++i)
128 mat_roi[i] = mat[i](Rect(srcx[i], srcy[i], roicols, roirows));
130 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
133 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
135 for (int i = 0; i < channels; ++i)
136 gmat[i] = mat_roi[i];
140 struct Merge : MergeTestBase {};
142 OCL_TEST_P(Merge, Accuracy)
144 for(int j = 0; j < LOOP_TIMES; j++)
148 cv::merge(mat_roi, channels, dst_roi);
149 cv::ocl::merge(gmat, channels, gdst);
151 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), 0.0);
155 PARAM_TEST_CASE(SplitTestBase, MatType, int, bool)
165 cv::Mat dst[MAX_CHANNELS];
168 int roicols, roirows;
170 int dstx[MAX_CHANNELS];
171 int dsty[MAX_CHANNELS];
177 cv::Mat dst_roi[MAX_CHANNELS];
179 //ocl dst mat for testing
180 cv::ocl::oclMat gdst_whole[MAX_CHANNELS];
183 cv::ocl::oclMat gmat;
184 cv::ocl::oclMat gdst[MAX_CHANNELS];
189 channels = GET_PARAM(1);
190 use_roi = GET_PARAM(2);
192 cv::Size size(MWIDTH, MHEIGHT);
194 mat = randomMat(size, CV_MAKETYPE(type, channels), 5, 16, false);
195 for (int i = 0; i < channels; ++i)
196 dst[i] = randomMat(size, CV_MAKETYPE(type, 1), 5, 16, false); }
203 roicols = rng.uniform(1, mat.cols);
204 roirows = rng.uniform(1, mat.rows);
205 srcx = rng.uniform(0, mat.cols - roicols);
206 srcy = rng.uniform(0, mat.rows - roirows);
208 for (int i = 0; i < channels; ++i)
210 dstx[i] = rng.uniform(0, dst[i].cols - roicols);
211 dsty[i] = rng.uniform(0, dst[i].rows - roirows);
220 for (int i = 0; i < channels; ++i)
221 dstx[i] = dsty[i] = 0;
224 mat_roi = mat(Rect(srcx, srcy, roicols, roirows));
226 for (int i = 0; i < channels; ++i)
227 dst_roi[i] = dst[i](Rect(dstx[i], dsty[i], roicols, roirows));
229 for (int i = 0; i < channels; ++i)
231 gdst_whole[i] = dst[i];
232 gdst[i] = gdst_whole[i](Rect(dstx[i], dsty[i], roicols, roirows));
239 struct Split : SplitTestBase {};
241 OCL_TEST_P(Split, Accuracy)
243 for(int j = 0; j < LOOP_TIMES; j++)
247 cv::split(mat_roi, dst_roi);
248 cv::ocl::split(gmat, gdst);
250 for (int i = 0; i < channels; ++i)
251 EXPECT_MAT_NEAR(dst[i], Mat(gdst_whole[i]), 0.0);
256 INSTANTIATE_TEST_CASE_P(SplitMerge, Merge, Combine(
257 Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F), Range(1, 5), Bool()));
260 INSTANTIATE_TEST_CASE_P(SplitMerge, Split , Combine(
261 Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F), Range(1, 5), Bool()));
264 #endif // HAVE_OPENCL