/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // // By downloading, copying, installing or using the software you agree to this license. // If you do not agree to this license, do not download, install, // copy or use the software. // // // License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistribution's of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistribution's in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * The name of the copyright holders may not be used to endorse or promote products // derived from this software without specific prior written permission. // // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. // In no event shall the OpenCV Foundation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused // and on any theory of liability, whether in contract, strict liability, // or tort (including negligence or otherwise) arising in any way out of // the use of this software, even if advised of the possibility of such damage. // //M*/ #include "test_precomp.hpp" #include "opencv2/core/ocl.hpp" using namespace cvtest; using namespace testing; using namespace cv; #define EXPECT_MAT_NEAR(mat1, mat2, eps) \ { \ ASSERT_EQ(mat1.type(), mat2.type()); \ ASSERT_EQ(mat1.size(), mat2.size()); \ EXPECT_LE(cv::norm(mat1, mat2), eps); \ }\ ////////////////////////////////////////////////////////////// Basic Tests ///////////////////////////////////////////////////////////////////// PARAM_TEST_CASE(UMatBasicTests, int, int, Size, bool) { Mat a, b, roi_a, roi_b; UMat ua, ub, roi_ua, roi_ub; int type; int depth; int cn; Size size; bool useRoi; Size roi_size; Rect roi; virtual void SetUp() { depth = GET_PARAM(0); cn = GET_PARAM(1); size = GET_PARAM(2); useRoi = GET_PARAM(3); type = CV_MAKE_TYPE(depth, cn); a = randomMat(size, type, -100, 100); b = randomMat(size, type, -100, 100); a.copyTo(ua); b.copyTo(ub); int roi_shift_x = randomInt(0, size.width-1); int roi_shift_y = randomInt(0, size.height-1); roi_size = Size(size.width - roi_shift_x, size.height - roi_shift_y); roi = Rect(roi_shift_x, roi_shift_y, roi_size.width, roi_size.height); } }; CORE_TEST_P(UMatBasicTests, createUMat) { if(useRoi) { ua = UMat(ua, roi); } int dims = randomInt(2,6); int _sz[CV_MAX_DIM]; for( int i = 0; igetBufferPoolController(); if (c) { size_t oldMaxReservedSize = c->getMaxReservedSize(); c->freeAllReservedBuffers(); c->setMaxReservedSize(sz.area() * 10); for (int i = 0; i < ITERATIONS; i++) { UMat um(Size(sz.width + i, sz.height + i), CV_8UC1); UMat um2(Size(sz.width + 2 * i, sz.height + 2 * i), CV_8UC1); } c->setMaxReservedSize(oldMaxReservedSize); c->freeAllReservedBuffers(); } else { std::cout << "Skipped, no OpenCL" << std::endl; } } TEST(UMat, setOpenCL) { // save the current state bool useOCL = cv::ocl::useOpenCL(); Mat m = (Mat_(3,3)<<0,1,2,3,4,5,6,7,8); cv::ocl::setUseOpenCL(true); UMat um1; m.copyTo(um1); cv::ocl::setUseOpenCL(false); UMat um2; m.copyTo(um2); cv::ocl::setUseOpenCL(true); countNonZero(um1); countNonZero(um2); um1.copyTo(um2); EXPECT_MAT_NEAR(um1, um2, 0); EXPECT_MAT_NEAR(um1, m, 0); um2.copyTo(um1); EXPECT_MAT_NEAR(um1, m, 0); EXPECT_MAT_NEAR(um1, um2, 0); cv::ocl::setUseOpenCL(false); countNonZero(um1); countNonZero(um2); um1.copyTo(um2); EXPECT_MAT_NEAR(um1, um2, 0); EXPECT_MAT_NEAR(um1, m, 0); um2.copyTo(um1); EXPECT_MAT_NEAR(um1, um2, 0); EXPECT_MAT_NEAR(um1, m, 0); // reset state to the previous one cv::ocl::setUseOpenCL(useOCL); }