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 ////////////////////////////////converto/////////////////////////////////////////////////
57 PARAM_TEST_CASE(ConvertToTestBase, MatType, MatType, int, bool)
59 int src_depth, dst_depth;
76 // ocl dst mat for testing
77 cv::ocl::oclMat gdst_whole;
85 src_depth = GET_PARAM(0);
86 dst_depth = GET_PARAM(1);
88 int src_type = CV_MAKE_TYPE(src_depth, cn);
89 dst_type = CV_MAKE_TYPE(dst_depth, cn);
91 use_roi = GET_PARAM(3);
93 mat = randomMat(randomSize(MIN_VALUE, MAX_VALUE), src_type, 5, 136, false);
94 dst = randomMat(use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : mat.size(), dst_type, 5, 136, false);
102 roicols = rng.uniform(1, MIN_VALUE);
103 roirows = rng.uniform(1, MIN_VALUE);
104 srcx = rng.uniform(0, mat.cols - roicols);
105 srcy = rng.uniform(0, mat.rows - roirows);
106 dstx = rng.uniform(0, dst.cols - roicols);
107 dsty = rng.uniform(0, dst.rows - roirows);
117 mat_roi = mat(Rect(srcx, srcy, roicols, roirows));
118 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
121 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
127 typedef ConvertToTestBase ConvertTo;
129 OCL_TEST_P(ConvertTo, Accuracy)
131 if((src_depth == CV_64F || dst_depth == CV_64F) &&
132 !cv::ocl::Context::getContext()->supportsFeature(cv::ocl::FEATURE_CL_DOUBLE))
134 return; // returns silently
136 for (int j = 0; j < LOOP_TIMES; j++)
140 mat_roi.convertTo(dst_roi, dst_type);
141 gsrc.convertTo(gdst, dst_type);
143 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), src_depth == CV_64F ? 1.0 : 0.0);
144 EXPECT_MAT_NEAR(dst_roi, Mat(gdst), src_depth == CV_64F ? 1.0 : 0.0);
148 ///////////////////////////////////////////copyto/////////////////////////////////////////////////////////////
150 PARAM_TEST_CASE(CopyToTestBase, MatType, int, bool)
154 cv::Mat src, mask, dst;
167 // ocl dst mat for testing
168 cv::ocl::oclMat gdst_whole;
171 cv::ocl::oclMat gsrc, gdst, gmask;
175 int type = CV_MAKETYPE(GET_PARAM(0), GET_PARAM(1));
176 use_roi = GET_PARAM(2);
178 src = randomMat(randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, false);
179 dst = randomMat(use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), type, 5, 16, false);
180 mask = randomMat(use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), CV_8UC1, 0, 2, false);
182 cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
190 roicols = rng.uniform(1, MIN_VALUE);
191 roirows = rng.uniform(1, MIN_VALUE);
192 srcx = rng.uniform(0, src.cols - roicols);
193 srcy = rng.uniform(0, src.rows - roirows);
194 dstx = rng.uniform(0, dst.cols - roicols);
195 dsty = rng.uniform(0, dst.rows - roirows);
196 maskx = rng.uniform(0, mask.cols - roicols);
197 masky = rng.uniform(0, mask.rows - roirows);
208 src_roi = src(Rect(srcx, srcy, roicols, roirows));
209 mask_roi = mask(Rect(maskx, masky, roicols, roirows));
210 dst_roi = dst(Rect(dstx, dsty, roicols, roirows));
213 gdst = gdst_whole(Rect(dstx, dsty, roicols, roirows));
220 typedef CopyToTestBase CopyTo;
222 OCL_TEST_P(CopyTo, Without_mask)
224 if((src.depth() == CV_64F) &&
225 !cv::ocl::Context::getContext()->supportsFeature(cv::ocl::FEATURE_CL_DOUBLE))
227 return; // returns silently
229 for (int j = 0; j < LOOP_TIMES; j++)
233 src_roi.copyTo(dst_roi);
236 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), 0.0);
240 OCL_TEST_P(CopyTo, With_mask)
242 if(src.depth() == CV_64F &&
243 !cv::ocl::Context::getContext()->supportsFeature(cv::ocl::FEATURE_CL_DOUBLE))
245 return; // returns silently
247 for (int j = 0; j < LOOP_TIMES; j++)
251 src_roi.copyTo(dst_roi, mask_roi);
252 gsrc.copyTo(gdst, gmask);
254 EXPECT_MAT_NEAR(dst, Mat(gdst_whole), 0.0);
258 /////////////////////////////////////////// setTo /////////////////////////////////////////////////////////////
260 PARAM_TEST_CASE(SetToTestBase, MatType, int, bool)
271 int roicols, roirows;
279 // ocl dst mat for testing
280 cv::ocl::oclMat gsrc_whole;
283 cv::ocl::oclMat gsrc;
284 cv::ocl::oclMat gmask;
288 depth = GET_PARAM(0);
289 channels = GET_PARAM(1);
290 use_roi = GET_PARAM(2);
292 int type = CV_MAKE_TYPE(depth, channels);
294 src = randomMat(randomSize(MIN_VALUE, MAX_VALUE), type, 5, 16, false);
295 mask = randomMat(use_roi ? randomSize(MIN_VALUE, MAX_VALUE) : src.size(), CV_8UC1, 0, 2, false);
297 cv::threshold(mask, mask, 0.5, 255., CV_8UC1);
298 val = cv::Scalar(rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0),
299 rng.uniform(-10.0, 10.0), rng.uniform(-10.0, 10.0));
307 roicols = rng.uniform(1, MIN_VALUE);
308 roirows = rng.uniform(1, MIN_VALUE);
309 srcx = rng.uniform(0, src.cols - roicols);
310 srcy = rng.uniform(0, src.rows - roirows);
311 maskx = rng.uniform(0, mask.cols - roicols);
312 masky = rng.uniform(0, mask.rows - roirows);
322 src_roi = src(Rect(srcx, srcy, roicols, roirows));
323 mask_roi = mask(Rect(maskx, masky, roicols, roirows));
326 gsrc = gsrc_whole(Rect(srcx, srcy, roicols, roirows));
332 typedef SetToTestBase SetTo;
334 OCL_TEST_P(SetTo, Without_mask)
336 if(depth == CV_64F &&
337 !cv::ocl::Context::getContext()->supportsFeature(cv::ocl::FEATURE_CL_DOUBLE))
339 return; // returns silently
341 for (int j = 0; j < LOOP_TIMES; j++)
348 EXPECT_MAT_NEAR(src, Mat(gsrc_whole), 1.);
352 OCL_TEST_P(SetTo, With_mask)
354 if(depth == CV_64F &&
355 !cv::ocl::Context::getContext()->supportsFeature(cv::ocl::FEATURE_CL_DOUBLE))
357 return; // returns silently
359 for (int j = 0; j < LOOP_TIMES; j++)
363 src_roi.setTo(val, mask_roi);
364 gsrc.setTo(val, gmask);
366 EXPECT_MAT_NEAR(src, Mat(gsrc_whole), 1.);
372 PARAM_TEST_CASE(convertC3C4, MatType, bool)
381 int roicols, roirows;
388 cv::ocl::oclMat gsrc_roi;
392 depth = GET_PARAM(0);
393 use_roi = GET_PARAM(1);
394 int type = CV_MAKE_TYPE(depth, 3);
396 src = randomMat(randomSize(1, MAX_VALUE), type, 0, 40, false);
404 roicols = rng.uniform(1, src.cols);
405 roirows = rng.uniform(1, src.rows);
406 srcx = rng.uniform(0, src.cols - roicols);
407 srcy = rng.uniform(0, src.rows - roirows);
416 src_roi = src(Rect(srcx, srcy, roicols, roirows));
420 OCL_TEST_P(convertC3C4, Accuracy)
422 if(depth == CV_64F &&
423 !cv::ocl::Context::getContext()->supportsFeature(cv::ocl::FEATURE_CL_DOUBLE))
425 return; // returns silently
427 for (int j = 0; j < LOOP_TIMES; j++)
433 EXPECT_MAT_NEAR(src_roi, Mat(gsrc_roi), 0.0);
437 INSTANTIATE_TEST_CASE_P(MatrixOperation, ConvertTo, Combine(
438 Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F),
439 Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F),
440 Range(1, 5), Bool()));
442 INSTANTIATE_TEST_CASE_P(MatrixOperation, CopyTo, Combine(
443 Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F),
444 testing::Range(1, 5), Bool()));
446 INSTANTIATE_TEST_CASE_P(MatrixOperation, SetTo, Combine(
447 Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F),
448 testing::Range(1, 5), Bool()));
450 INSTANTIATE_TEST_CASE_P(MatrixOperation, convertC3C4, Combine(
451 Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F),