//M*/
#include "test_precomp.hpp"
-
-#include <string>
-#include <iostream>
#include "opencv2/core/ocl.hpp"
+using namespace cvtest;
+using namespace testing;
using namespace cv;
-using namespace std;
-class CV_UMatTest :
- public cvtest::BaseTest
-{
-public:
- CV_UMatTest() {}
- ~CV_UMatTest() {}
-protected:
- void run(int);
+#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); \
+}\
- struct test_excep
- {
- test_excep(const string& _s=string("")) : s(_s) { }
- string s;
- };
+////////////////////////////////////////////////////////////// Basic Tests /////////////////////////////////////////////////////////////////////
- bool TestUMat();
+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);
+ }
+};
- void checkDiff(const Mat& m1, const Mat& m2, const string& s)
+CORE_TEST_P(UMatBasicTests, createUMat)
+{
+ if(useRoi)
{
- if (norm(m1, m2, NORM_INF) != 0)
- throw test_excep(s);
+ ua = UMat(ua, roi);
}
- void checkDiffF(const Mat& m1, const Mat& m2, const string& s)
+ int dims = randomInt(2,6);
+ int _sz[CV_MAX_DIM];
+ for( int i = 0; i<dims; i++)
{
- if (norm(m1, m2, NORM_INF) > 1e-5)
- throw test_excep(s);
+ _sz[i] = randomInt(1,50);
}
-};
-
-#define STR(a) STR2(a)
-#define STR2(a) #a
+ int *sz = _sz;
+ int new_depth = randomInt(CV_8S, CV_64F);
+ int new_cn = randomInt(1,4);
+ ua.create(dims, sz, CV_MAKE_TYPE(new_depth, new_cn));
-#define CHECK_DIFF(a, b) checkDiff(a, b, "(" #a ") != (" #b ") at l." STR(__LINE__))
-#define CHECK_DIFF_FLT(a, b) checkDiffF(a, b, "(" #a ") !=(eps) (" #b ") at l." STR(__LINE__))
+ for(int i = 0; i<dims; i++)
+ {
+ ASSERT_EQ(ua.size[i], sz[i]);
+ }
+ ASSERT_EQ(ua.dims, dims);
+ ASSERT_EQ(ua.type(), CV_MAKE_TYPE(new_depth, new_cn) );
+ Size new_size = randomSize(1, 1000);
+ ua.create(new_size, CV_MAKE_TYPE(new_depth, new_cn) );
+ ASSERT_EQ( ua.size(), new_size);
+ ASSERT_EQ(ua.type(), CV_MAKE_TYPE(new_depth, new_cn) );
+ ASSERT_EQ( ua.dims, 2);
+}
+CORE_TEST_P(UMatBasicTests, swap)
+{
+ if(useRoi)
+ {
+ ua = UMat(ua,roi);
+ ub = UMat(ub,roi);
+ }
+ UMat uc = ua, ud = ub;
+ swap(ua,ub);
+ EXPECT_MAT_NEAR(ub,uc, 0);
+ EXPECT_MAT_NEAR(ud, ua, 0);
+}
-bool CV_UMatTest::TestUMat()
+CORE_TEST_P(UMatBasicTests, base)
{
- try
+ if(useRoi)
{
- Mat a(100, 100, CV_16SC2), b, c;
- randu(a, Scalar::all(-100), Scalar::all(100));
- Rect roi(1, 3, 5, 4);
- Mat ra(a, roi), rb, rc, rc0;
- UMat ua, ura, ub, urb, uc, urc;
- a.copyTo(ua);
- ua.copyTo(b);
- CHECK_DIFF(a, b);
+ ua = UMat(ua,roi);
+ }
+ ub = ua.clone();
+ EXPECT_MAT_NEAR(ub,ua,0);
+
+ ASSERT_EQ(ua.channels(), cn);
+ ASSERT_EQ(ua.depth(), depth);
+ ASSERT_EQ(ua.type(), type);
+ ASSERT_EQ(ua.elemSize(), a.elemSize());
+ ASSERT_EQ(ua.elemSize1(), a.elemSize1());
+ ASSERT_EQ(ub.empty(), ub.cols*ub.rows == 0);
+ ub.release();
+ ASSERT_TRUE( ub.empty() );
+ if(useRoi && a.size() != ua.size())
+ {
+ ASSERT_EQ(ua.isSubmatrix(), true);
+ }
+ else
+ {
+ ASSERT_EQ(ua.isSubmatrix(), false);
+ }
- ura = ua(roi);
- ura.copyTo(rb);
+ int dims = randomInt(2,6);
+ int sz[CV_MAX_DIM];
+ size_t total = 1;
+ for(int i = 0; i<dims; i++)
+ {
+ sz[i] = randomInt(1,45);
+ total *= (size_t)sz[i];
+ }
+ int new_type = CV_MAKE_TYPE(randomInt(CV_8S,CV_64F),randomInt(1,4));
+ ub = UMat(dims, sz, new_type);
+ ASSERT_EQ(ub.total(), total);
+}
- CHECK_DIFF(ra, rb);
+CORE_TEST_P(UMatBasicTests, copyTo)
+{
+ if(useRoi)
+ {
+ roi_ua = UMat(ua, roi);
+ roi_a = Mat(a, roi);
+ roi_a.copyTo(roi_ua);
+ EXPECT_MAT_NEAR(roi_a, roi_ua, 0);
+ roi_ua.copyTo(roi_a);
+ EXPECT_MAT_NEAR(roi_ua, roi_a, 0);
+ roi_ua.copyTo(ua);
+ EXPECT_MAT_NEAR(roi_ua, ua, 0);
+ ua.copyTo(a);
+ EXPECT_MAT_NEAR(ua, a, 0);
+ }
+ ua.copyTo(ub);
+ EXPECT_MAT_NEAR(ua, ub, 0);
+ int i = randomInt(0, ua.cols-1);
+ a.col(i).copyTo(ub);
+ EXPECT_MAT_NEAR(a.col(i), ub, 0);
+ ua.col(i).copyTo(ub);
+ EXPECT_MAT_NEAR(ua.col(i), ub, 0);
+ ua.col(i).copyTo(b);
+ EXPECT_MAT_NEAR(ua.col(i), b, 0);
+ i = randomInt(0, a.rows-1);
+ ua.row(i).copyTo(ub);
+ EXPECT_MAT_NEAR(ua.row(i), ub, 0);
+ a.row(i).copyTo(ub);
+ EXPECT_MAT_NEAR(a.row(i), ub, 0);
+ ua.row(i).copyTo(b);
+ EXPECT_MAT_NEAR(ua.row(i), b, 0);
+}
- ra += Scalar::all(1.f);
- {
- Mat temp = ura.getMat(ACCESS_RW);
- temp += Scalar::all(1.f);
- }
- ra.copyTo(rb);
- CHECK_DIFF(ra, rb);
+CORE_TEST_P(UMatBasicTests, GetUMat)
+{
+ if(useRoi)
+ {
+ a = Mat(a, roi);
+ ua = UMat(ua,roi);
+ }
+ ub = a.getUMat(ACCESS_RW);
+ EXPECT_MAT_NEAR(ub, ua, 0);
+ b = a.getUMat(ACCESS_RW).getMat(ACCESS_RW);
+ EXPECT_MAT_NEAR(b, a, 0);
+ b.release();
+ b = ua.getMat(ACCESS_RW);
+ EXPECT_MAT_NEAR(b, a, 0);
+ b.release();
+ ub = ua.getMat(ACCESS_RW).getUMat(ACCESS_RW);
+ EXPECT_MAT_NEAR(ub, ua, 0);
+}
- b = a.clone();
- ra = a(roi);
- rb = b(roi);
- randu(b, Scalar::all(-100), Scalar::all(100));
- b.copyTo(ub);
- urb = ub(roi);
+INSTANTIATE_TEST_CASE_P(UMat, UMatBasicTests, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() ) );
- /*std::cout << "==============================================\nbefore op (CPU):\n";
- std::cout << "ra: " << ra << std::endl;
- std::cout << "rb: " << rb << std::endl;*/
+//////////////////////////////////////////////////////////////// Reshape ////////////////////////////////////////////////////////////////////////
- ra.copyTo(ura);
- rb.copyTo(urb);
- ra.release();
- rb.release();
- ura.copyTo(ra);
- urb.copyTo(rb);
+PARAM_TEST_CASE(UMatTestReshape, int, int, Size, bool)
+{
+ Mat a;
+ UMat ua, ub;
+ int type;
+ int depth;
+ int cn;
+ Size size;
+ bool useRoi;
+ Size roi_size;
+ 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);
+ }
+};
- /*std::cout << "==============================================\nbefore op (GPU):\n";
- std::cout << "ra: " << ra << std::endl;
- std::cout << "rb: " << rb << std::endl;*/
+CORE_TEST_P(UMatTestReshape, reshape)
+{
+ a = randomMat(size,type, -100, 100);
+ a.copyTo(ua);
+ if(useRoi)
+ {
+ 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);
+ Rect roi(roi_shift_x, roi_shift_y, roi_size.width, roi_size.height);
+ ua = UMat(ua, roi).clone();
+ a = Mat(a, roi).clone();
+ }
- cv::max(ra, rb, rc);
- cv::max(ura, urb, urc);
- urc.copyTo(rc0);
+ int nChannels = randomInt(1,4);
- /*std::cout << "==============================================\nafter op:\n";
- std::cout << "rc: " << rc << std::endl;
- std::cout << "rc0: " << rc0 << std::endl;*/
+ if ((ua.cols*ua.channels()*ua.rows)%nChannels != 0)
+ {
+ EXPECT_ANY_THROW(ua.reshape(nChannels));
+ }
+ else
+ {
+ ub = ua.reshape(nChannels);
+ ASSERT_EQ(ub.channels(),nChannels);
+ ASSERT_EQ(ub.channels()*ub.cols*ub.rows, ua.channels()*ua.cols*ua.rows);
- CHECK_DIFF(rc0, rc);
+ EXPECT_MAT_NEAR(ua.reshape(nChannels), a.reshape(nChannels), 0);
+ int new_rows = randomInt(1, INT_MAX);
+ if ( ((int)ua.total()*ua.channels())%(new_rows*nChannels) != 0)
{
- UMat tmp = rc0.getUMat(ACCESS_WRITE);
- cv::max(ura, urb, tmp);
+ EXPECT_ANY_THROW (ua.reshape(nChannels, new_rows) );
}
- CHECK_DIFF(rc0, rc);
-
- ura.copyTo(urc);
- cv::max(urc, urb, urc);
- urc.copyTo(rc0);
- CHECK_DIFF(rc0, rc);
-
- rc = ra ^ rb;
- cv::bitwise_xor(ura, urb, urc);
- urc.copyTo(rc0);
+ else
+ {
+ EXPECT_NO_THROW ( ub = ua.reshape(nChannels, new_rows) );
+ ASSERT_EQ(ub.channels(),nChannels);
+ ASSERT_EQ(ub.rows, new_rows);
+ ASSERT_EQ(ub.channels()*ub.cols*ub.rows, ua.channels()*ua.cols*ua.rows);
- /*std::cout << "==============================================\nafter op:\n";
- std::cout << "ra: " << rc0 << std::endl;
- std::cout << "rc: " << rc << std::endl;*/
+ EXPECT_MAT_NEAR(ua.reshape(nChannels,new_rows), a.reshape(nChannels,new_rows), 0);
+ }
- CHECK_DIFF(rc0, rc);
+ new_rows = (int)ua.total()*ua.channels()/(nChannels*randomInt(1, size.width*size.height));
+ if (new_rows == 0) new_rows = 1;
+ int new_cols = (int)ua.total()*ua.channels()/(new_rows*nChannels);
+ int sz[] = {new_rows, new_cols};
+ if( ((int)ua.total()*ua.channels()) % (new_rows*new_cols) != 0 )
+ {
+ EXPECT_ANY_THROW( ua.reshape(nChannels, ua.dims, sz) );
+ }
+ else
+ {
+ EXPECT_NO_THROW ( ub = ua.reshape(nChannels, ua.dims, sz) );
+ ASSERT_EQ(ub.channels(),nChannels);
+ ASSERT_EQ(ub.rows, new_rows);
+ ASSERT_EQ(ub.cols, new_cols);
+ ASSERT_EQ(ub.channels()*ub.cols*ub.rows, ua.channels()*ua.cols*ua.rows);
- rc = ra + rb;
- cv::add(ura, urb, urc);
- urc.copyTo(rc0);
+ EXPECT_MAT_NEAR(ua.reshape(nChannels, ua.dims, sz), a.reshape(nChannels, a.dims, sz), 0);
+ }
+ }
+}
- CHECK_DIFF(rc0, rc);
+INSTANTIATE_TEST_CASE_P(UMat, UMatTestReshape, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() ));
- cv::subtract(ra, Scalar::all(5), rc);
- cv::subtract(ura, Scalar::all(5), urc);
- urc.copyTo(rc0);
+////////////////////////////////////////////////////////////////// ROI testing ///////////////////////////////////////////////////////////////
- CHECK_DIFF(rc0, rc);
- }
- catch (const test_excep& e)
+PARAM_TEST_CASE(UMatTestRoi, int, int, Size)
+{
+ Mat a, roi_a;
+ UMat ua, roi_ua;
+ int type;
+ int depth;
+ int cn;
+ Size size;
+ Size roi_size;
+ virtual void SetUp()
{
- ts->printf(cvtest::TS::LOG, "%s\n", e.s.c_str());
- ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
- return false;
+ depth = GET_PARAM(0);
+ cn = GET_PARAM(1);
+ size = GET_PARAM(2);
+ type = CV_MAKE_TYPE(depth, cn);
}
- return true;
-}
+};
-void CV_UMatTest::run( int /* start_from */)
+CORE_TEST_P(UMatTestRoi, createRoi)
{
- printf("Use OpenCL: %s\nHave OpenCL: %s\n",
- ocl::useOpenCL() ? "TRUE" : "FALSE",
- ocl::haveOpenCL() ? "TRUE" : "FALSE" );
+ 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);
+ a = randomMat(size, type, -100, 100);
+ Rect roi(roi_shift_x, roi_shift_y, roi_size.width, roi_size.height);
+ roi_a = Mat(a, roi);
+ a.copyTo(ua);
+ roi_ua = UMat(ua, roi);
+
+ EXPECT_MAT_NEAR(roi_a, roi_ua, 0);
+}
- if (!TestUMat())
- return;
+CORE_TEST_P(UMatTestRoi, locateRoi)
+{
+ 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);
+ a = randomMat(size, type, -100, 100);
+ Rect roi(roi_shift_x, roi_shift_y, roi_size.width, roi_size.height);
+ roi_a = Mat(a, roi);
+ a.copyTo(ua);
+ roi_ua = UMat(ua,roi);
+ Size sz, usz;
+ Point p, up;
+ roi_a.locateROI(sz, p);
+ roi_ua.locateROI(usz, up);
+ ASSERT_EQ(sz, usz);
+ ASSERT_EQ(p, up);
+}
- ts->set_failed_test_info(cvtest::TS::OK);
+CORE_TEST_P(UMatTestRoi, adjustRoi)
+{
+ 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);
+ a = randomMat(size, type, -100, 100);
+ Rect roi(roi_shift_x, roi_shift_y, roi_size.width, roi_size.height);
+ a.copyTo(ua);
+ roi_ua = UMat( ua, roi);
+ int adjLeft = randomInt(-(roi_ua.cols/2), (size.width-1)/2);
+ int adjRight = randomInt(-(roi_ua.cols/2), (size.width-1)/2);
+ int adjTop = randomInt(-(roi_ua.rows/2), (size.height-1)/2);
+ int adjBot = randomInt(-(roi_ua.rows/2), (size.height-1)/2);
+ roi_ua.adjustROI(adjTop, adjBot, adjLeft, adjRight);
+ roi_shift_x = max(0, roi.x-adjLeft);
+ roi_shift_y = max(0, roi.y-adjTop);
+ Rect new_roi( roi_shift_x, roi_shift_y, min(roi.width+adjRight+adjLeft, size.width-roi_shift_x), min(roi.height+adjBot+adjTop, size.height-roi_shift_y) );
+ UMat test_roi = UMat(ua, new_roi);
+ EXPECT_MAT_NEAR(roi_ua, test_roi, 0);
}
-TEST(Core_UMat, base) { CV_UMatTest test; test.safe_run(); }
+INSTANTIATE_TEST_CASE_P(UMat, UMatTestRoi, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES ));
+
+/////////////////////////////////////////////////////////////// Size ////////////////////////////////////////////////////////////////////
-TEST(Core_UMat, getUMat)
+PARAM_TEST_CASE(UMatTestSizeOperations, 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;
+ Size roi_size;
+ bool useRoi;
+ virtual void SetUp()
{
- int a[3] = { 1, 2, 3 };
- Mat m = Mat(1, 1, CV_32SC3, a);
- UMat u = m.getUMat(ACCESS_READ);
- EXPECT_NE((void*)NULL, u.u);
+ depth = GET_PARAM(0);
+ cn = GET_PARAM(1);
+ size = GET_PARAM(2);
+ useRoi = GET_PARAM(3);
+ type = CV_MAKE_TYPE(depth, cn);
}
+};
+CORE_TEST_P(UMatTestSizeOperations, copySize)
+{
+ Size s = randomSize(1,300);
+ a = randomMat(size, type, -100, 100);
+ b = randomMat(s, type, -100, 100);
+ a.copyTo(ua);
+ b.copyTo(ub);
+ if(useRoi)
{
- Mat m(10, 10, CV_8UC1), ref;
- for (int y = 0; y < m.rows; ++y)
- {
- uchar * const ptr = m.ptr<uchar>(y);
- for (int x = 0; x < m.cols; ++x)
- ptr[x] = (uchar)(x + y * 2);
- }
+ 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);
+ Rect roi(roi_shift_x, roi_shift_y, roi_size.width, roi_size.height);
+ ua = UMat(ua,roi);
+
+ roi_shift_x = randomInt(0, s.width-1);
+ roi_shift_y = randomInt(0, s.height-1);
+ roi_size = Size(s.width - roi_shift_x, s.height - roi_shift_y);
+ roi = Rect(roi_shift_x, roi_shift_y, roi_size.width, roi_size.height);
+ ub = UMat(ub, roi);
+ }
+ ua.copySize(ub);
+ ASSERT_EQ(ua.size, ub.size);
+}
- ref = m.clone();
- Rect r(1, 1, 8, 8);
- ref(r).setTo(17);
+INSTANTIATE_TEST_CASE_P(UMat, UMatTestSizeOperations, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() ));
- {
- UMat um = m(r).getUMat(ACCESS_WRITE);
- um.setTo(17);
- }
+///////////////////////////////////////////////////////////////// UMat operations ////////////////////////////////////////////////////////////////////////////
- double err = norm(m, ref, NORM_INF);
- if (err > 0)
- {
- std::cout << "m: " << std::endl << m << std::endl;
- std::cout << "ref: " << std::endl << ref << std::endl;
- }
- EXPECT_EQ(0., err);
+PARAM_TEST_CASE(UMatTestUMatOperations, int, int, Size, bool)
+{
+ Mat a, b;
+ UMat ua, ub;
+ int type;
+ int depth;
+ int cn;
+ Size size;
+ Size roi_size;
+ bool useRoi;
+ 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);
}
-}
+};
-TEST(UMat, Sync)
+CORE_TEST_P(UMatTestUMatOperations, diag)
{
- UMat um(10, 10, CV_8UC1);
-
+ a = randomMat(size, type, -100, 100);
+ a.copyTo(ua);
+ Mat new_diag;
+ if(useRoi)
{
- Mat m = um.getMat(ACCESS_WRITE);
- m.setTo(cv::Scalar::all(17));
+ 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);
+ Rect roi(roi_shift_x, roi_shift_y, roi_size.width, roi_size.height);
+ ua = UMat(ua,roi);
+ a = Mat(a, roi);
}
-
- um.setTo(cv::Scalar::all(19));
-
- EXPECT_EQ(0, cv::norm(um.getMat(ACCESS_READ), cv::Mat(um.size(), um.type(), 19), NORM_INF));
+ int n = randomInt(0, ua.cols-1);
+ ub = ua.diag(n);
+ b = a.diag(n);
+ EXPECT_MAT_NEAR(b, ub, 0);
+ new_diag = randomMat(Size(ua.rows, 1), type, -100, 100);
+ new_diag.copyTo(ub);
+ ua = cv::UMat::diag(ub);
+ EXPECT_MAT_NEAR(ua.diag(), new_diag.t(), 0);
}
-#define EXPECT_MAT_NEAR(m1, m2) ASSERT_EQ(0, cv::norm(m1, m1, cv::NORM_INF))
-
-TEST(UMat, setOpenCL)
+CORE_TEST_P(UMatTestUMatOperations, dotUMat)
{
- // save the current state
- bool useOCL = ocl::useOpenCL();
-
- Mat m = (Mat_<uchar>(3,3)<<0,1,2,3,4,5,6,7,8);
-
- ocl::setUseOpenCL(true);
- UMat um1;
- m.copyTo(um1);
-
- ocl::setUseOpenCL(false);
- UMat um2;
- m.copyTo(um2);
-
- ocl::setUseOpenCL(true);
- countNonZero(um1);
- countNonZero(um2);
-
- um1.copyTo(um2);
- EXPECT_MAT_NEAR(um1, um2);
- EXPECT_MAT_NEAR(um1, m);
- um2.copyTo(um1);
- EXPECT_MAT_NEAR(um1, m);
- EXPECT_MAT_NEAR(um1, um2);
-
- ocl::setUseOpenCL(false);
- countNonZero(um1);
- countNonZero(um2);
+ a = randomMat(size, type, -100, 100);
+ b = randomMat(size, type, -100, 100);
+ a.copyTo(ua);
+ b.copyTo(ub);
+ //ASSERT_EQ(ua.dot(ub), a.dot(b)); UMat::dot doesn't compiles
+}
- um1.copyTo(um2);
- EXPECT_MAT_NEAR(um1, um2);
- EXPECT_MAT_NEAR(um1, m);
- um2.copyTo(um1);
- EXPECT_MAT_NEAR(um1, um2);
- EXPECT_MAT_NEAR(um1, m);
+INSTANTIATE_TEST_CASE_P(UMat, UMatTestUMatOperations, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() ));
- // reset state to the previous one
- ocl::setUseOpenCL(useOCL);
-}
+///////////////////////////////////////////////////////////////// OpenCL ////////////////////////////////////////////////////////////////////////////
TEST(UMat, BufferPoolGrowing)
{
const int ITERATIONS = 200;
#endif
const Size sz(1920, 1080);
- BufferPoolController* c = ocl::getOpenCLAllocator()->getBufferPoolController();
+ BufferPoolController* c = cv::ocl::getOpenCLAllocator()->getBufferPoolController();
if (c)
{
size_t oldMaxReservedSize = c->getMaxReservedSize();
std::cout << "Skipped, no OpenCL" << std::endl;
}
}
+
+TEST(UMat, setOpenCL)
+{
+ // save the current state
+ bool useOCL = cv::ocl::useOpenCL();
+
+ Mat m = (Mat_<uchar>(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);
+}
+