diff --git a/modules/core/test/test_precomp.hpp b/modules/core/test/test_precomp.hpp index 56b9d55198..d981cea066 100644 --- a/modules/core/test/test_precomp.hpp +++ b/modules/core/test/test_precomp.hpp @@ -15,127 +15,4 @@ #include "opencv2/core/private.hpp" -#define MWIDTH 256 -#define MHEIGHT 256 - -#define MIN_VALUE 171 -#define MAX_VALUE 357 - -#define RNG_SEED 123456 - -template -struct TSTestWithParam : public ::testing::TestWithParam -{ - cv::RNG rng; - - TSTestWithParam() - { - rng = cv::RNG(RNG_SEED); - } - - int randomInt(int minVal, int maxVal) - { - return rng.uniform(minVal, maxVal); - } - - double randomDouble(double minVal, double maxVal) - { - return rng.uniform(minVal, maxVal); - } - - double randomDoubleLog(double minVal, double maxVal) - { - double logMin = log((double)minVal + 1); - double logMax = log((double)maxVal + 1); - double pow = rng.uniform(logMin, logMax); - double v = exp(pow) - 1; - CV_Assert(v >= minVal && (v < maxVal || (v == minVal && v == maxVal))); - return v; - } - - cv::Size randomSize(int minVal, int maxVal) - { -#if 1 - return cv::Size((int)randomDoubleLog(minVal, maxVal), (int)randomDoubleLog(minVal, maxVal)); -#else - return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal)); -#endif - } - - cv::Size randomSize(int minValX, int maxValX, int minValY, int maxValY) - { -#if 1 - return cv::Size(randomDoubleLog(minValX, maxValX), randomDoubleLog(minValY, maxValY)); -#else - return cv::Size(randomInt(minVal, maxVal), randomInt(minVal, maxVal)); -#endif - } - - cv::Scalar randomScalar(double minVal, double maxVal) - { - return cv::Scalar(randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal), randomDouble(minVal, maxVal)); - } - - cv::Mat randomMat(cv::Size size, int type, double minVal, double maxVal, bool useRoi = false) - { - cv::RNG dataRng(rng.next()); - return cvtest::randomMat(dataRng, size, type, minVal, maxVal, useRoi); - } - -}; - -#define PARAM_TEST_CASE(name, ...) struct name : public TSTestWithParam< std::tr1::tuple< __VA_ARGS__ > > - -#define GET_PARAM(k) std::tr1::get< k >(GetParam()) - -#define UMAT_TEST_CHANNELS testing::Values(1, 2, 3, 4) - -#define UMAT_TEST_SIZES testing::Values(cv::Size(1,1), cv::Size(1,128), cv::Size(128,1), cv::Size(128, 128), cv::Size(640,480), cv::Size(751,373), cv::Size(1200, 1200)) - -#define UMAT_TEST_DEPTH testing::Values(CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F) - -# define CORE_TEST_P(test_case_name, test_name) \ - class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : \ - public test_case_name { \ - public: \ - GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() { } \ - virtual void TestBody(); \ - void CoreTestBody(); \ - private: \ - static int AddToRegistry() \ - { \ - ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ - GetTestCasePatternHolder(\ - #test_case_name, __FILE__, __LINE__)->AddTestPattern(\ - #test_case_name, \ - #test_name, \ - new ::testing::internal::TestMetaFactory< \ - GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \ - return 0; \ - } \ - \ - static int gtest_registering_dummy_; \ - GTEST_DISALLOW_COPY_AND_ASSIGN_(\ - GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \ - }; \ - \ - int GTEST_TEST_CLASS_NAME_(test_case_name, \ - test_name)::gtest_registering_dummy_ = \ - GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ - \ - void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() \ - { \ - try \ - { \ - CoreTestBody(); \ - } \ - catch (...) \ - { \ - std::cout << "Something wrong in CoreTestBody running" << std::endl; \ - throw; \ - } \ - } \ - \ - void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::CoreTestBody() - #endif diff --git a/modules/core/test/test_umat.cpp b/modules/core/test/test_umat.cpp index 536f3db01a..fd344a9b0d 100644 --- a/modules/core/test/test_umat.cpp +++ b/modules/core/test/test_umat.cpp @@ -40,20 +40,19 @@ //M*/ #include "test_precomp.hpp" -#include "opencv2/core/ocl.hpp" +#include "opencv2/ts/ocl_test.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); \ -}\ +namespace cvtest { +namespace ocl { -////////////////////////////////////////////////////////////// Basic Tests ///////////////////////////////////////////////////////////////////// +#define UMAT_TEST_SIZES testing::Values(cv::Size(1, 1), cv::Size(1,128), cv::Size(128, 1), \ + cv::Size(128, 128), cv::Size(640, 480), cv::Size(751, 373), cv::Size(1200, 1200)) + +/////////////////////////////// Basic Tests //////////////////////////////// PARAM_TEST_CASE(UMatBasicTests, int, int, Size, bool) { @@ -66,6 +65,7 @@ PARAM_TEST_CASE(UMatBasicTests, int, int, Size, bool) bool useRoi; Size roi_size; Rect roi; + virtual void SetUp() { depth = GET_PARAM(0); @@ -82,7 +82,7 @@ PARAM_TEST_CASE(UMatBasicTests, int, int, Size, bool) } }; -CORE_TEST_P(UMatBasicTests, createUMat) +TEST_P(UMatBasicTests, createUMat) { if(useRoi) { @@ -112,7 +112,7 @@ CORE_TEST_P(UMatBasicTests, createUMat) ASSERT_EQ( ua.dims, 2); } -CORE_TEST_P(UMatBasicTests, swap) +TEST_P(UMatBasicTests, swap) { Mat b = randomMat(size, type, -100, 100); UMat ub; @@ -128,7 +128,7 @@ CORE_TEST_P(UMatBasicTests, swap) EXPECT_MAT_NEAR(ud, ua, 0); } -CORE_TEST_P(UMatBasicTests, base) +TEST_P(UMatBasicTests, base) { if(useRoi) { @@ -167,7 +167,7 @@ CORE_TEST_P(UMatBasicTests, base) ASSERT_EQ(ub.total(), total); } -CORE_TEST_P(UMatBasicTests, copyTo) +TEST_P(UMatBasicTests, DISABLED_copyTo) { UMat roi_ua; Mat roi_a; @@ -224,7 +224,7 @@ CORE_TEST_P(UMatBasicTests, copyTo) } } -CORE_TEST_P(UMatBasicTests, DISABLED_GetUMat) +TEST_P(UMatBasicTests, DISABLED_GetUMat) { if(useRoi) { @@ -254,7 +254,7 @@ CORE_TEST_P(UMatBasicTests, DISABLED_GetUMat) } INSTANTIATE_TEST_CASE_P(UMat, UMatBasicTests, Combine(testing::Values(CV_8U), testing::Values(1, 2), - testing::Values(cv::Size(1,1), cv::Size(1,128), cv::Size(128,1), cv::Size(128, 128), cv::Size(640,480)), Bool() ) ); + testing::Values(cv::Size(1, 1), cv::Size(1, 128), cv::Size(128, 1), cv::Size(128, 128), cv::Size(640, 480)), Bool())); //////////////////////////////////////////////////////////////// Reshape //////////////////////////////////////////////////////////////////////// @@ -278,7 +278,7 @@ PARAM_TEST_CASE(UMatTestReshape, int, int, Size, bool) } }; -CORE_TEST_P(UMatTestReshape, reshape) +TEST_P(UMatTestReshape, DISABLED_reshape) { a = randomMat(size,type, -100, 100); a.copyTo(ua); @@ -342,7 +342,7 @@ CORE_TEST_P(UMatTestReshape, reshape) } } -INSTANTIATE_TEST_CASE_P(UMat, UMatTestReshape, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() )); +INSTANTIATE_TEST_CASE_P(UMat, UMatTestReshape, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, UMAT_TEST_SIZES, Bool() )); ////////////////////////////////////////////////////////////////// ROI testing /////////////////////////////////////////////////////////////// @@ -364,7 +364,7 @@ PARAM_TEST_CASE(UMatTestRoi, int, int, Size) } }; -CORE_TEST_P(UMatTestRoi, createRoi) +TEST_P(UMatTestRoi, createRoi) { int roi_shift_x = randomInt(0, size.width-1); int roi_shift_y = randomInt(0, size.height-1); @@ -378,7 +378,7 @@ CORE_TEST_P(UMatTestRoi, createRoi) EXPECT_MAT_NEAR(roi_a, roi_ua, 0); } -CORE_TEST_P(UMatTestRoi, locateRoi) +TEST_P(UMatTestRoi, locateRoi) { int roi_shift_x = randomInt(0, size.width-1); int roi_shift_y = randomInt(0, size.height-1); @@ -396,7 +396,7 @@ CORE_TEST_P(UMatTestRoi, locateRoi) ASSERT_EQ(p, up); } -CORE_TEST_P(UMatTestRoi, adjustRoi) +TEST_P(UMatTestRoi, adjustRoi) { int roi_shift_x = randomInt(0, size.width-1); int roi_shift_y = randomInt(0, size.height-1); @@ -410,14 +410,14 @@ CORE_TEST_P(UMatTestRoi, adjustRoi) 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) ); + roi_shift_x = std::max(0, roi.x-adjLeft); + roi_shift_y = std::max(0, roi.y-adjTop); + Rect new_roi( roi_shift_x, roi_shift_y, std::min(roi.width+adjRight+adjLeft, size.width-roi_shift_x), std::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); } -INSTANTIATE_TEST_CASE_P(UMat, UMatTestRoi, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES )); +INSTANTIATE_TEST_CASE_P(UMat, UMatTestRoi, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, UMAT_TEST_SIZES )); /////////////////////////////////////////////////////////////// Size //////////////////////////////////////////////////////////////////// @@ -441,7 +441,7 @@ PARAM_TEST_CASE(UMatTestSizeOperations, int, int, Size, bool) } }; -CORE_TEST_P(UMatTestSizeOperations, copySize) +TEST_P(UMatTestSizeOperations, copySize) { Size s = randomSize(1,300); a = randomMat(size, type, -100, 100); @@ -466,7 +466,7 @@ CORE_TEST_P(UMatTestSizeOperations, copySize) ASSERT_EQ(ua.size, ub.size); } -INSTANTIATE_TEST_CASE_P(UMat, UMatTestSizeOperations, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() )); +INSTANTIATE_TEST_CASE_P(UMat, UMatTestSizeOperations, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, UMAT_TEST_SIZES, Bool() )); ///////////////////////////////////////////////////////////////// UMat operations //////////////////////////////////////////////////////////////////////////// @@ -490,7 +490,7 @@ PARAM_TEST_CASE(UMatTestUMatOperations, int, int, Size, bool) } }; -CORE_TEST_P(UMatTestUMatOperations, diag) +TEST_P(UMatTestUMatOperations, diag) { a = randomMat(size, type, -100, 100); a.copyTo(ua); @@ -514,7 +514,7 @@ CORE_TEST_P(UMatTestUMatOperations, diag) EXPECT_MAT_NEAR(ua.diag(), new_diag.t(), 0); } -INSTANTIATE_TEST_CASE_P(UMat, UMatTestUMatOperations, Combine(UMAT_TEST_DEPTH, UMAT_TEST_CHANNELS, UMAT_TEST_SIZES, Bool() )); +INSTANTIATE_TEST_CASE_P(UMat, UMatTestUMatOperations, Combine(OCL_ALL_DEPTHS, OCL_ALL_CHANNELS, UMAT_TEST_SIZES, Bool())); ///////////////////////////////////////////////////////////////// OpenCL //////////////////////////////////////////////////////////////////////////// @@ -541,9 +541,208 @@ TEST(UMat, BufferPoolGrowing) c->freeAllReservedBuffers(); } else - { std::cout << "Skipped, no OpenCL" << std::endl; +} + +class CV_UMatTest : + public cvtest::BaseTest +{ +public: + CV_UMatTest() {} + ~CV_UMatTest() {} +protected: + void run(int); + + struct test_excep + { + test_excep(const string& _s=string("")) : s(_s) { } + string s; + }; + + bool TestUMat(); + + void checkDiff(const Mat& m1, const Mat& m2, const string& s) + { + if (norm(m1, m2, NORM_INF) != 0) + throw test_excep(s); + } + void checkDiffF(const Mat& m1, const Mat& m2, const string& s) + { + if (norm(m1, m2, NORM_INF) > 1e-5) + throw test_excep(s); } +}; + +#define STR(a) STR2(a) +#define STR2(a) #a + +#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__)) + + +bool CV_UMatTest::TestUMat() +{ + try + { + 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); + + ura = ua(roi); + ura.copyTo(rb); + + CHECK_DIFF(ra, rb); + + ra += Scalar::all(1.f); + { + Mat temp = ura.getMat(ACCESS_RW); + temp += Scalar::all(1.f); + } + ra.copyTo(rb); + CHECK_DIFF(ra, rb); + + b = a.clone(); + ra = a(roi); + rb = b(roi); + randu(b, Scalar::all(-100), Scalar::all(100)); + b.copyTo(ub); + urb = ub(roi); + + /*std::cout << "==============================================\nbefore op (CPU):\n"; + std::cout << "ra: " << ra << std::endl; + std::cout << "rb: " << rb << std::endl;*/ + + ra.copyTo(ura); + rb.copyTo(urb); + ra.release(); + rb.release(); + ura.copyTo(ra); + urb.copyTo(rb); + + /*std::cout << "==============================================\nbefore op (GPU):\n"; + std::cout << "ra: " << ra << std::endl; + std::cout << "rb: " << rb << std::endl;*/ + + cv::max(ra, rb, rc); + cv::max(ura, urb, urc); + urc.copyTo(rc0); + + /*std::cout << "==============================================\nafter op:\n"; + std::cout << "rc: " << rc << std::endl; + std::cout << "rc0: " << rc0 << std::endl;*/ + + CHECK_DIFF(rc0, rc); + + { + UMat tmp = rc0.getUMat(ACCESS_WRITE); + cv::max(ura, urb, tmp); + } + 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); + + /*std::cout << "==============================================\nafter op:\n"; + std::cout << "ra: " << rc0 << std::endl; + std::cout << "rc: " << rc << std::endl;*/ + + CHECK_DIFF(rc0, rc); + + rc = ra + rb; + cv::add(ura, urb, urc); + urc.copyTo(rc0); + + CHECK_DIFF(rc0, rc); + + cv::subtract(ra, Scalar::all(5), rc); + cv::subtract(ura, Scalar::all(5), urc); + urc.copyTo(rc0); + + CHECK_DIFF(rc0, rc); + } + catch (const test_excep& e) + { + ts->printf(cvtest::TS::LOG, "%s\n", e.s.c_str()); + ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH); + return false; + } + return true; +} + +void CV_UMatTest::run( int /* start_from */) +{ + printf("Use OpenCL: %s\nHave OpenCL: %s\n", + cv::ocl::useOpenCL() ? "TRUE" : "FALSE", + cv::ocl::haveOpenCL() ? "TRUE" : "FALSE" ); + + if (!TestUMat()) + return; + + ts->set_failed_test_info(cvtest::TS::OK); +} + +TEST(Core_UMat, base) { CV_UMatTest test; test.safe_run(); } + +TEST(Core_UMat, getUMat) +{ + { + 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); + } + + { + Mat m(10, 10, CV_8UC1), ref; + for (int y = 0; y < m.rows; ++y) + { + uchar * const ptr = m.ptr(y); + for (int x = 0; x < m.cols; ++x) + ptr[x] = (uchar)(x + y * 2); + } + + ref = m.clone(); + Rect r(1, 1, 8, 8); + ref(r).setTo(17); + + { + UMat um = m(r).getUMat(ACCESS_WRITE); + um.setTo(17); + } + + 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); + } +} + +TEST(UMat, Sync) +{ + UMat um(10, 10, CV_8UC1); + + { + Mat m = um.getMat(ACCESS_WRITE); + m.setTo(cv::Scalar::all(17)); + } + + um.setTo(cv::Scalar::all(19)); + + EXPECT_EQ(0, cv::norm(um.getMat(ACCESS_READ), cv::Mat(um.size(), um.type(), 19), NORM_INF)); } TEST(UMat, setOpenCL) @@ -586,3 +785,5 @@ TEST(UMat, setOpenCL) // reset state to the previous one cv::ocl::setUseOpenCL(useOCL); } + +} } // namespace cvtest::ocl diff --git a/modules/ts/include/opencv2/ts/ocl_perf.hpp b/modules/ts/include/opencv2/ts/ocl_perf.hpp index 6fa77f6577..c2e860067b 100644 --- a/modules/ts/include/opencv2/ts/ocl_perf.hpp +++ b/modules/ts/include/opencv2/ts/ocl_perf.hpp @@ -45,8 +45,6 @@ #include "ocl_test.hpp" #include "ts_perf.hpp" -#ifdef HAVE_OPENCL - namespace cvtest { namespace ocl { @@ -130,6 +128,4 @@ using namespace perf; } // namespace cvtest::ocl } // namespace cvtest -#endif // HAVE_OPENCL - #endif // __OPENCV_TS_OCL_PERF_HPP__ diff --git a/modules/ts/include/opencv2/ts/ocl_test.hpp b/modules/ts/include/opencv2/ts/ocl_test.hpp index a4b2ec38cd..169e34fdcc 100644 --- a/modules/ts/include/opencv2/ts/ocl_test.hpp +++ b/modules/ts/include/opencv2/ts/ocl_test.hpp @@ -42,11 +42,8 @@ #ifndef __OPENCV_TS_OCL_TEST_HPP__ #define __OPENCV_TS_OCL_TEST_HPP__ -#include "cvconfig.h" // to get definition of HAVE_OPENCL #include "opencv2/opencv_modules.hpp" -#ifdef HAVE_OPENCL - #include "opencv2/ts.hpp" #include "opencv2/highgui.hpp" @@ -60,45 +57,20 @@ namespace ocl { using namespace cv; using namespace testing; -namespace traits { - -template -struct GetMatForRead -{ -}; -template <> -struct GetMatForRead -{ - static const Mat get(const Mat& m) { return m; } -}; -template <> -struct GetMatForRead -{ - static const Mat get(const UMat& m) { return m.getMat(ACCESS_READ); } -}; - -} // namespace traits - -template -const Mat getMatForRead(const T& mat) -{ - return traits::GetMatForRead::get(mat); -} - extern int test_loop_times; #define MAX_VALUE 357 #define EXPECT_MAT_NORM(mat, eps) \ { \ - EXPECT_LE(checkNorm(mat), eps) \ + EXPECT_LE(TestUtils::checkNorm(mat), eps) \ } #define EXPECT_MAT_NEAR(mat1, mat2, eps) \ { \ ASSERT_EQ(mat1.type(), mat2.type()); \ ASSERT_EQ(mat1.size(), mat2.size()); \ - EXPECT_LE(checkNorm(mat1, mat2), eps) \ + EXPECT_LE(TestUtils::checkNorm(mat1, mat2), eps) \ << "Size: " << mat1.size() << std::endl; \ } @@ -106,7 +78,7 @@ extern int test_loop_times; { \ ASSERT_EQ(mat1.type(), mat2.type()); \ ASSERT_EQ(mat1.size(), mat2.size()); \ - EXPECT_LE(checkNormRelative(mat1, mat2), eps) \ + EXPECT_LE(TestUtils::checkNormRelative(mat1, mat2), eps) \ << "Size: " << mat1.size() << std::endl; \ } @@ -227,54 +199,22 @@ struct CV_EXPORTS TestUtils // If the two vectors are not equal, it will return the difference in vector size // Else it will return (total diff of each 1 and 2 rects covered pixels)/(total 1 rects covered pixels) // The smaller, the better matched - static double checkRectSimilarity(cv::Size sz, std::vector& ob1, std::vector& ob2); + static double checkRectSimilarity(const cv::Size & sz, std::vector& ob1, std::vector& ob2); //! read image from testdata folder. - static cv::Mat readImage(const String &fileName, int flags = cv::IMREAD_COLOR); static cv::Mat readImageType(const String &fname, int type); - static double checkNorm(const cv::Mat &m); - static double checkNorm(const cv::Mat &m1, const cv::Mat &m2); - static double checkSimilarity(const cv::Mat &m1, const cv::Mat &m2); - static inline double checkNormRelative(const Mat &m1, const Mat &m2) - { - return cv::norm(m1, m2, cv::NORM_INF) / - std::max((double)std::numeric_limits::epsilon(), - (double)std::max(cv::norm(m1, cv::NORM_INF), norm(m2, cv::NORM_INF))); - } - static void showDiff(const Mat& src, const Mat& gold, const Mat& actual, double eps, bool alwaysShow = false); + static double checkNorm(InputArray m); + static double checkNorm(InputArray m1, InputArray m2); + static double checkSimilarity(InputArray m1, InputArray m2); + static void showDiff(InputArray _src, InputArray _gold, InputArray _actual, double eps, bool alwaysShow); - template - static double checkNorm(const T1& m) - { - return checkNorm(getMatForRead(m)); - } - template - static double checkNorm(const T1& m1, const T2& m2) - { - return checkNorm(getMatForRead(m1), getMatForRead(m2)); - } - template - static double checkSimilarity(const T1& m1, const T2& m2) + static inline double checkNormRelative(InputArray m1, InputArray m2) { - return checkSimilarity(getMatForRead(m1), getMatForRead(m2)); - } - template - static inline double checkNormRelative(const T1& m1, const T2& m2) - { - const Mat _m1 = getMatForRead(m1); - const Mat _m2 = getMatForRead(m2); - return checkNormRelative(_m1, _m2); - } - - template - static void showDiff(const T1& src, const T2& gold, const T3& actual, double eps, bool alwaysShow = false) - { - const Mat _src = getMatForRead(src); - const Mat _gold = getMatForRead(gold); - const Mat _actual = getMatForRead(actual); - showDiff(_src, _gold, _actual, eps, alwaysShow); + return cv::norm(m1.getMat(), m2.getMat(), cv::NORM_INF) / + std::max((double)std::numeric_limits::epsilon(), + (double)std::max(cv::norm(m1.getMat(), cv::NORM_INF), norm(m2.getMat(), cv::NORM_INF))); } }; @@ -334,8 +274,6 @@ CV_ENUM(BorderType, BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT, BORDER_WR #define OCL_INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \ INSTANTIATE_TEST_CASE_P(OCL_ ## prefix, test_case_name, generator) -}} // namespace cvtest::ocl - -#endif // HAVE_OPENCL +} } // namespace cvtest::ocl #endif // __OPENCV_TS_OCL_TEST_HPP__ diff --git a/modules/ts/src/ocl_perf.cpp b/modules/ts/src/ocl_perf.cpp index 4348a58a3b..8dacf219f6 100644 --- a/modules/ts/src/ocl_perf.cpp +++ b/modules/ts/src/ocl_perf.cpp @@ -43,8 +43,6 @@ #include "opencv2/ts/ocl_perf.hpp" -#ifdef HAVE_OPENCL - namespace cvtest { namespace ocl { @@ -82,6 +80,4 @@ void randu(InputOutputArray dst) } // namespace perf -}} // namespace cvtest::ocl - -#endif // HAVE_OPENCL +} } // namespace cvtest::ocl diff --git a/modules/ts/src/ocl_test.cpp b/modules/ts/src/ocl_test.cpp index 3387b193b9..994ae489ac 100644 --- a/modules/ts/src/ocl_test.cpp +++ b/modules/ts/src/ocl_test.cpp @@ -43,8 +43,6 @@ #include "opencv2/ts/ocl_test.hpp" -#ifdef HAVE_OPENCL - namespace cvtest { namespace ocl { @@ -197,41 +195,39 @@ Mat TestUtils::readImageType(const String &fname, int type) return src; } -double TestUtils::checkNorm(const Mat &m) +double TestUtils::checkNorm(InputArray m) { - return norm(m, NORM_INF); + return norm(m.getMat(), NORM_INF); } -double TestUtils::checkNorm(const Mat &m1, const Mat &m2) +double TestUtils::checkNorm(InputArray m1, InputArray m2) { - return norm(m1, m2, NORM_INF); + return norm(m1.getMat(), m2.getMat(), NORM_INF); } -double TestUtils::checkSimilarity(const Mat &m1, const Mat &m2) +double TestUtils::checkSimilarity(InputArray m1, InputArray m2) { Mat diff; - matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED); + matchTemplate(m1.getMat(), m2.getMat(), diff, CV_TM_CCORR_NORMED); return std::abs(diff.at(0, 0) - 1.f); } -double TestUtils::checkRectSimilarity(Size sz, std::vector& ob1, std::vector& ob2) +double TestUtils::checkRectSimilarity(const Size & sz, std::vector& ob1, std::vector& ob2) { double final_test_result = 0.0; size_t sz1 = ob1.size(); size_t sz2 = ob2.size(); - if(sz1 != sz2) - { + if (sz1 != sz2) return sz1 > sz2 ? (double)(sz1 - sz2) : (double)(sz2 - sz1); - } else { - if(sz1==0 && sz2==0) + if (sz1 == 0 && sz2 == 0) return 0; cv::Mat cpu_result(sz, CV_8UC1); cpu_result.setTo(0); - for(vector::const_iterator r = ob1.begin(); r != ob1.end(); r++) + for (vector::const_iterator r = ob1.begin(); r != ob1.end(); r++) { cv::Mat cpu_result_roi(cpu_result, *r); cpu_result_roi.setTo(1); @@ -251,7 +247,7 @@ double TestUtils::checkRectSimilarity(Size sz, std::vector& ob1, std::vect cv::Mat result_; multiply(cpu_result, gpu_result, result_); int result = cv::countNonZero(result_ > 0); - if(cpu_area!=0 && result!=0) + if (cpu_area!=0 && result!=0) final_test_result = 1.0 - (double)result/(double)cpu_area; else if(cpu_area==0 && result!=0) final_test_result = -1; @@ -259,8 +255,10 @@ double TestUtils::checkRectSimilarity(Size sz, std::vector& ob1, std::vect return final_test_result; } -void TestUtils::showDiff(const Mat& src, const Mat& gold, const Mat& actual, double eps, bool alwaysShow) +void TestUtils::showDiff(InputArray _src, InputArray _gold, InputArray _actual, double eps, bool alwaysShow) { + Mat src = _src.getMat(), actual = _actual.getMat(), gold = _gold.getMat(); + Mat diff, diff_thresh; absdiff(gold, actual, diff); diff.convertTo(diff, CV_32F); @@ -288,6 +286,4 @@ void TestUtils::showDiff(const Mat& src, const Mat& gold, const Mat& actual, dou } } -}} // namespace cvtest::ocl - -#endif // HAVE_OPENCL +} } // namespace cvtest::ocl