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 "precomp.hpp"
51 using namespace cvtest;
52 using namespace testing;
55 ////////////////////////////////converto/////////////////////////////////////////////////
56 PARAM_TEST_CASE(ConvertToTestBase, MatType, MatType)
77 //ocl dst mat for testing
78 cv::ocl::oclMat gdst_whole;
87 dst_type = GET_PARAM(1);
89 cv::RNG &rng = TS::ptr()->get_rng();
90 cv::Size size(MWIDTH, MHEIGHT);
92 mat = randomMat(rng, size, type, 5, 16, false);
93 dst = randomMat(rng, size, type, 5, 16, false);
100 cv::RNG &rng = TS::ptr()->get_rng();
101 roicols = rng.uniform(1, mat.cols);
102 roirows = rng.uniform(1, mat.rows);
103 srcx = rng.uniform(0, mat.cols - roicols);
104 srcy = rng.uniform(0, mat.rows - roirows);
105 dstx = rng.uniform(0, dst.cols - roicols);
106 dsty = rng.uniform(0, dst.rows - roirows);
116 mat_roi = mat(Rect(srcx, srcy, roicols, roirows));
117 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
120 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
127 struct ConvertTo : ConvertToTestBase {};
129 TEST_P(ConvertTo, Accuracy)
131 for(int j = 0; j < LOOP_TIMES; j++)
135 mat_roi.convertTo(dst_roi, dst_type);
136 gmat.convertTo(gdst, dst_type);
138 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), 0.0);
145 ///////////////////////////////////////////copyto/////////////////////////////////////////////////////////////
147 PARAM_TEST_CASE(CopyToTestBase, MatType, bool)
170 //ocl dst mat for testing
171 cv::ocl::oclMat gdst_whole;
174 cv::ocl::oclMat gmat;
175 cv::ocl::oclMat gdst;
176 cv::ocl::oclMat gmask;
182 cv::RNG &rng = TS::ptr()->get_rng();
183 cv::Size size(MWIDTH, MHEIGHT);
185 mat = randomMat(rng, size, type, 5, 16, false);
186 dst = randomMat(rng, size, type, 5, 16, false);
187 mask = randomMat(rng, size, CV_8UC1, 0, 2, false);
189 cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
197 cv::RNG &rng = TS::ptr()->get_rng();
198 roicols = rng.uniform(1, mat.cols);
199 roirows = rng.uniform(1, mat.rows);
200 srcx = rng.uniform(0, mat.cols - roicols);
201 srcy = rng.uniform(0, mat.rows - roirows);
202 dstx = rng.uniform(0, dst.cols - roicols);
203 dsty = rng.uniform(0, dst.rows - roirows);
204 maskx = rng.uniform(0, mask.cols - roicols);
205 masky = rng.uniform(0, mask.rows - roirows);
217 mat_roi = mat(Rect(srcx, srcy, roicols, roirows));
218 mask_roi = mask(Rect(maskx, masky, roicols, roirows));
219 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
222 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
229 struct CopyTo : CopyToTestBase {};
231 TEST_P(CopyTo, Without_mask)
233 for(int j = 0; j < LOOP_TIMES; j++)
237 mat_roi.copyTo(dst_roi);
240 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), 0.0);
244 TEST_P(CopyTo, With_mask)
246 for(int j = 0; j < LOOP_TIMES; j++)
250 mat_roi.copyTo(dst_roi, mask_roi);
251 gmat.copyTo(gdst, gmask);
253 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), 0.0);
260 ///////////////////////////////////////////copyto/////////////////////////////////////////////////////////////
262 PARAM_TEST_CASE(SetToTestBase, MatType, bool)
282 //ocl dst mat for testing
283 cv::ocl::oclMat gmat_whole;
286 cv::ocl::oclMat gmat;
287 cv::ocl::oclMat gmask;
293 cv::RNG &rng = TS::ptr()->get_rng();
294 cv::Size size(MWIDTH, MHEIGHT);
296 mat = randomMat(rng, size, type, 5, 16, false);
297 mask = randomMat(rng, size, CV_8UC1, 0, 2, false);
299 cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
300 val = cv::Scalar(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0));
308 cv::RNG &rng = TS::ptr()->get_rng();
309 roicols = rng.uniform(1, mat.cols);
310 roirows = rng.uniform(1, mat.rows);
311 srcx = rng.uniform(0, mat.cols - roicols);
312 srcy = rng.uniform(0, mat.rows - roirows);
313 maskx = rng.uniform(0, mask.cols - roicols);
314 masky = rng.uniform(0, mask.rows - roirows);
324 mat_roi = mat(Rect(srcx, srcy, roicols, roirows));
325 mask_roi = mask(Rect(maskx, masky, roicols, roirows));
328 gmat = gmat_whole(Rect(srcx, srcy, roicols, roirows));
334 struct SetTo : SetToTestBase {};
336 TEST_P(SetTo, Without_mask)
338 for(int j = 0; j < LOOP_TIMES; j++)
345 EXPECT_MAT_NEAR(mat, Mat(gmat_whole), 1.);
349 TEST_P(SetTo, With_mask)
351 for(int j = 0; j < LOOP_TIMES; j++)
355 mat_roi.setTo(val, mask_roi);
356 gmat.setTo(val, gmask);
358 EXPECT_MAT_NEAR(mat, Mat(gmat_whole), 1.);
363 PARAM_TEST_CASE(convertC3C4, MatType, cv::Size)
384 //ocl dst mat for testing
385 cv::ocl::oclMat gdst_whole;
388 cv::ocl::oclMat gmat1;
389 cv::ocl::oclMat gdst;
394 ksize = GET_PARAM(1);
402 cv::RNG &rng = TS::ptr()->get_rng();
403 roicols = rng.uniform(2, mat1.cols);
404 roirows = rng.uniform(2, mat1.rows);
405 src1x = rng.uniform(0, mat1.cols - roicols);
406 src1y = rng.uniform(0, mat1.rows - roirows);
407 dstx = rng.uniform(0, dst.cols - roicols);
408 dsty = rng.uniform(0, dst.rows - roirows);
418 mat1_roi = mat1(Rect(src1x, src1y, roicols, roirows));
419 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
422 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
430 TEST_P(convertC3C4, Accuracy)
432 cv::RNG &rng = TS::ptr()->get_rng();
433 for(int j = 0; j < LOOP_TIMES; j++)
436 int width = rng.uniform(2, MWIDTH);
437 int height = rng.uniform(2, MHEIGHT);
438 cv::Size size(width, height);
440 mat1 = randomMat(rng, size, type, 0, 40, false);
443 EXPECT_MAT_NEAR(mat1, Mat(gmat1), 0.0);
448 INSTANTIATE_TEST_CASE_P(MatrixOperation, ConvertTo, Combine(
449 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32SC1, CV_32SC4, CV_32FC1, CV_32FC4),
450 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32SC1, CV_32SC4, CV_32FC1, CV_32FC4)));
452 INSTANTIATE_TEST_CASE_P(MatrixOperation, CopyTo, Combine(
453 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32SC1, CV_32SC3, CV_32SC4, CV_32FC1, CV_32FC3, CV_32FC4),
454 Values(false))); // Values(false) is the reserved parameter
456 INSTANTIATE_TEST_CASE_P(MatrixOperation, SetTo, Combine(
457 Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32SC1, CV_32SC3, CV_32SC4, CV_32FC1, CV_32FC3, CV_32FC4),
458 Values(false))); // Values(false) is the reserved parameter
460 INSTANTIATE_TEST_CASE_P(MatrixOperation, convertC3C4, Combine(
461 Values(CV_8UC3, CV_32SC3, CV_32FC3),
462 Values(cv::Size())));