From 40b8b58bc6603127eaa497fa5b569f08876c6600 Mon Sep 17 00:00:00 2001 From: Orest Chura Date: Wed, 30 Sep 2020 19:07:35 +0300 Subject: [PATCH] Merge pull request #18451 from OrestChura:oc/count_non_zero [G-API]: countNonZero() Standard Kernel Implementation * Add countNonZero() standard kernel - API and documentation provided - OCV backend supported - accuracy and performance tests provided - some refactoring of related documentation done * Fix GOpaque functionality for OCL Backend - test for OCL Opaque usage providied * countNonZero for GPU - OCL Backend implementation for countNonZero() added - tests provided * Addressing comments --- modules/gapi/include/opencv2/gapi/core.hpp | 43 +++++++++--- .../include/opencv2/gapi/ocl/goclkernel.hpp | 4 +- .../gapi/perf/common/gapi_core_perf_tests.hpp | 3 +- .../perf/common/gapi_core_perf_tests_inl.hpp | 40 ++++++++++- .../perf/cpu/gapi_core_perf_tests_cpu.cpp | 8 ++- .../perf/gpu/gapi_core_perf_tests_gpu.cpp | 8 ++- modules/gapi/src/api/kernels_core.cpp | 7 +- modules/gapi/src/backends/cpu/gcpucore.cpp | 11 ++- modules/gapi/src/backends/ocl/goclcore.cpp | 11 ++- modules/gapi/src/backends/ocl/goclkernel.cpp | 5 ++ modules/gapi/test/common/gapi_core_tests.hpp | 1 + .../gapi/test/common/gapi_core_tests_inl.hpp | 25 ++++++- modules/gapi/test/cpu/gapi_core_tests_cpu.cpp | 11 ++- modules/gapi/test/gapi_opaque_tests.cpp | 69 +++++++++++++++++++ modules/gapi/test/gpu/gapi_core_tests_gpu.cpp | 13 +++- 15 files changed, 235 insertions(+), 24 deletions(-) diff --git a/modules/gapi/include/opencv2/gapi/core.hpp b/modules/gapi/include/opencv2/gapi/core.hpp index 0313aad093..c4ddaf6bd3 100644 --- a/modules/gapi/include/opencv2/gapi/core.hpp +++ b/modules/gapi/include/opencv2/gapi/core.hpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #ifndef OPENCV_GAPI_CORE_HPP @@ -308,6 +308,13 @@ namespace core { } }; + G_TYPED_KERNEL(GCountNonZero, (GMat)>, "org.opencv.core.matrixop.countNonZero") { + static GOpaqueDesc outMeta(GMatDesc in) { + GAPI_Assert(in.chan == 1); + return empty_gopaque_desc(); + } + }; + G_TYPED_KERNEL(GAddW, , "org.opencv.core.matrixop.addweighted") { static GMatDesc outMeta(GMatDesc a, double, GMatDesc b, double, double, int ddepth) { if (ddepth == -1) @@ -755,6 +762,7 @@ Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref @note Function textual ID is "org.opencv.core.math.mean" @param src input matrix. +@sa countNonZero, min, max */ GAPI_EXPORTS_W GScalar mean(const GMat& src); @@ -856,7 +864,7 @@ Supported input matrix data types are @ref CV_8UC1, @ref CV_16UC1, @ref CV_16SC1 @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGT" @param src1 first input matrix. @param src2 second input matrix/scalar of the same depth as first input matrix. -@sa min, max, threshold, cmpLE, cmpGE, cmpLS +@sa min, max, threshold, cmpLE, cmpGE, cmpLT */ GAPI_EXPORTS GMat cmpGT(const GMat& src1, const GMat& src2); /** @overload @@ -908,7 +916,7 @@ Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpGE" @param src1 first input matrix. @param src2 second input matrix/scalar of the same depth as first input matrix. -@sa min, max, threshold, cmpLE, cmpGT, cmpLS +@sa min, max, threshold, cmpLE, cmpGT, cmpLT */ GAPI_EXPORTS GMat cmpGE(const GMat& src1, const GMat& src2); /** @overload @@ -934,7 +942,7 @@ Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @note Function textual ID is "org.opencv.core.pixelwise.compare.cmpLE" @param src1 first input matrix. @param src2 second input matrix/scalar of the same depth as first input matrix. -@sa min, max, threshold, cmpGT, cmpGE, cmpLS +@sa min, max, threshold, cmpGT, cmpGE, cmpLT */ GAPI_EXPORTS GMat cmpLE(const GMat& src1, const GMat& src2); /** @overload @@ -1012,7 +1020,7 @@ Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref */ GAPI_EXPORTS GMat bitwise_and(const GMat& src1, const GMat& src2); /** @overload -@note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_andS" +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_andS" @param src1 first input matrix. @param src2 scalar, which will be per-lemenetly conjuncted with elements of src1. */ @@ -1036,7 +1044,7 @@ Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref */ GAPI_EXPORTS GMat bitwise_or(const GMat& src1, const GMat& src2); /** @overload -@note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_orS" +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_orS" @param src1 first input matrix. @param src2 scalar, which will be per-lemenetly disjuncted with elements of src1. */ @@ -1061,7 +1069,7 @@ Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref */ GAPI_EXPORTS GMat bitwise_xor(const GMat& src1, const GMat& src2); /** @overload -@note Function textual ID is "org.opencv.core.pixelwise.compare.bitwise_xorS" +@note Function textual ID is "org.opencv.core.pixelwise.bitwise_xorS" @param src1 first input matrix. @param src2 scalar, for which per-lemenet "logical or" operation on elements of src1 will be performed. */ @@ -1121,7 +1129,7 @@ Supported input matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @note Function textual ID is "org.opencv.core.matrixop.min" @param src1 first input matrix. @param src2 second input matrix of the same size and depth as src1. -@sa max, compareEqual, compareLess, compareLessEqual +@sa max, cmpEQ, cmpLT, cmpLE */ GAPI_EXPORTS GMat min(const GMat& src1, const GMat& src2); @@ -1138,7 +1146,7 @@ Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref @note Function textual ID is "org.opencv.core.matrixop.max" @param src1 first input matrix. @param src2 second input matrix of the same size and depth as src1. -@sa min, compare, compareEqual, compareGreater, compareGreaterEqual +@sa min, compare, cmpEQ, cmpGT, cmpGE */ GAPI_EXPORTS GMat max(const GMat& src1, const GMat& src2); @@ -1184,10 +1192,23 @@ Supported matrix data types are @ref CV_8UC1, @ref CV_8UC3, @ref CV_16UC1, @ref @note Function textual ID is "org.opencv.core.matrixop.sum" @param src input matrix. -@sa min, max +@sa countNonZero, mean, min, max */ GAPI_EXPORTS GScalar sum(const GMat& src); +/** @brief Counts non-zero array elements. + +The function returns the number of non-zero elements in src : +\f[\sum _{I: \; \texttt{src} (I) \ne0 } 1\f] + +Supported matrix data types are @ref CV_8UC1, @ref CV_16UC1, @ref CV_16SC1, @ref CV_32FC1. + +@note Function textual ID is "org.opencv.core.matrixop.countNonZero" +@param src input single-channel matrix. +@sa mean, min, max +*/ +GAPI_EXPORTS GOpaque countNonZero(const GMat& src); + /** @brief Calculates the weighted sum of two matrices. The function addWeighted calculates the weighted sum of two matrices as follows: @@ -1324,7 +1345,7 @@ Output matrix must be of the same size and depth as src. types. @param type thresholding type (see the cv::ThresholdTypes). -@sa min, max, cmpGT, cmpLE, cmpGE, cmpLS +@sa min, max, cmpGT, cmpLE, cmpGE, cmpLT */ GAPI_EXPORTS GMat threshold(const GMat& src, const GScalar& thresh, const GScalar& maxval, int type); /** @overload diff --git a/modules/gapi/include/opencv2/gapi/ocl/goclkernel.hpp b/modules/gapi/include/opencv2/gapi/ocl/goclkernel.hpp index ee363c05a0..8ec388d588 100644 --- a/modules/gapi/include/opencv2/gapi/ocl/goclkernel.hpp +++ b/modules/gapi/include/opencv2/gapi/ocl/goclkernel.hpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018-2019 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #ifndef OPENCV_GAPI_GOCLKERNEL_HPP @@ -75,7 +75,7 @@ public: protected: detail::VectorRef& outVecRef(int output); - detail::VectorRef& outOpaqueRef(int output); + detail::OpaqueRef& outOpaqueRef(int output); std::vector m_args; std::unordered_map m_results; diff --git a/modules/gapi/perf/common/gapi_core_perf_tests.hpp b/modules/gapi/perf/common/gapi_core_perf_tests.hpp index ac7182c07f..4a88b4f59c 100644 --- a/modules/gapi/perf/common/gapi_core_perf_tests.hpp +++ b/modules/gapi/perf/common/gapi_core_perf_tests.hpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #ifndef OPENCV_GAPI_CORE_PERF_TESTS_HPP @@ -52,6 +52,7 @@ namespace opencv_test class AbsDiffPerfTest : public TestPerfParams> {}; class AbsDiffCPerfTest : public TestPerfParams> {}; class SumPerfTest : public TestPerfParams> {}; + class CountNonZeroPerfTest : public TestPerfParams> {}; class AddWeightedPerfTest : public TestPerfParams> {}; class NormPerfTest : public TestPerfParams> {}; class IntegralPerfTest : public TestPerfParams> {}; diff --git a/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp b/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp index 9ad1d04d60..91d08bba06 100644 --- a/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp +++ b/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #ifndef OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP @@ -1011,6 +1011,44 @@ PERF_TEST_P_(SumPerfTest, TestPerformance) SANITY_CHECK_NOTHING(); } +//------------------------------------------------------------------------------ +#pragma push_macro("countNonZero") +#undef countNonZero +PERF_TEST_P_(CountNonZeroPerfTest, TestPerformance) +{ + compare_scalar_f cmpF; + cv::Size sz_in; + MatType type = -1; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz_in, type, compile_args) = GetParam(); + + initMatrixRandU(type, sz_in, type, false); + int out_cnz_gapi, out_cnz_ocv; + + // OpenCV code /////////////////////////////////////////////////////////// + out_cnz_ocv = cv::countNonZero(in_mat1); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::countNonZero(in); + cv::GComputation c(cv::GIn(in), cv::GOut(out)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1), cv::gout(out_cnz_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_cnz_gapi)); + } + + // Comparison //////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_cnz_gapi, out_cnz_ocv)); + } + + SANITY_CHECK_NOTHING(); +} +#pragma pop_macro("countNonZero") //------------------------------------------------------------------------------ PERF_TEST_P_(AddWeightedPerfTest, TestPerformance) diff --git a/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp b/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp index d4319f24cf..ffc4b1a646 100644 --- a/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp +++ b/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #include "../perf_precomp.hpp" @@ -160,6 +160,12 @@ INSTANTIATE_TEST_CASE_P(SumPerfTestCPU, SumPerfTest, //Values(0.0), Values(cv::compile_args(CORE_CPU)))); +INSTANTIATE_TEST_CASE_P(CountNonZeroPerfTestCPU, CountNonZeroPerfTest, + Combine(Values(AbsToleranceScalar(0.0).to_compare_f()), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + INSTANTIATE_TEST_CASE_P(AddWeightedPerfTestCPU, AddWeightedPerfTest, Combine(Values(Tolerance_FloatRel_IntAbs(1e-6, 1).to_compare_f()), Values(szSmall128, szVGA, sz720p, sz1080p), diff --git a/modules/gapi/perf/gpu/gapi_core_perf_tests_gpu.cpp b/modules/gapi/perf/gpu/gapi_core_perf_tests_gpu.cpp index 0c5ff9e044..2d8c254cd2 100644 --- a/modules/gapi/perf/gpu/gapi_core_perf_tests_gpu.cpp +++ b/modules/gapi/perf/gpu/gapi_core_perf_tests_gpu.cpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #include "../perf_precomp.hpp" @@ -157,6 +157,12 @@ INSTANTIATE_TEST_CASE_P(SumPerfTestGPU, SumPerfTest, Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), Values(cv::compile_args(CORE_GPU)))); +INSTANTIATE_TEST_CASE_P(CountNonZeroPerfTestGPU, CountNonZeroPerfTest, + Combine(Values(AbsToleranceScalar(0.0).to_compare_f()), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_GPU)))); + INSTANTIATE_TEST_CASE_P(AddWeightedPerfTestGPU, AddWeightedPerfTest, Combine(Values(Tolerance_FloatRel_IntAbs(1e-6, 1).to_compare_f()), Values( szSmall128, szVGA, sz720p, sz1080p ), diff --git a/modules/gapi/src/api/kernels_core.cpp b/modules/gapi/src/api/kernels_core.cpp index 961d19cdaa..55c43594af 100644 --- a/modules/gapi/src/api/kernels_core.cpp +++ b/modules/gapi/src/api/kernels_core.cpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #include "precomp.hpp" @@ -234,6 +234,11 @@ GScalar sum(const GMat& src) return core::GSum::on(src); } +GOpaque countNonZero(const GMat& src) +{ + return core::GCountNonZero::on(src); +} + GMat addWeighted(const GMat& src1, double alpha, const GMat& src2, double beta, double gamma, int dtype) { return core::GAddW::on(src1, alpha, src2, beta, gamma, dtype); diff --git a/modules/gapi/src/backends/cpu/gcpucore.cpp b/modules/gapi/src/backends/cpu/gcpucore.cpp index d9c3c3ae2a..f2b8f7077d 100644 --- a/modules/gapi/src/backends/cpu/gcpucore.cpp +++ b/modules/gapi/src/backends/cpu/gcpucore.cpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #include "precomp.hpp" @@ -342,6 +342,14 @@ GAPI_OCV_KERNEL(GCPUSum, cv::gapi::core::GSum) } }; +GAPI_OCV_KERNEL(GCPUCountNonZero, cv::gapi::core::GCountNonZero) +{ + static void run(const cv::Mat& in, int& out) + { + out = cv::countNonZero(in); + } +}; + GAPI_OCV_KERNEL(GCPUAddW, cv::gapi::core::GAddW) { static void run(const cv::Mat& in1, double alpha, const cv::Mat& in2, double beta, double gamma, int dtype, cv::Mat& out) @@ -679,6 +687,7 @@ cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels() , GCPUAbsDiff , GCPUAbsDiffC , GCPUSum + , GCPUCountNonZero , GCPUAddW , GCPUNormL1 , GCPUNormL2 diff --git a/modules/gapi/src/backends/ocl/goclcore.cpp b/modules/gapi/src/backends/ocl/goclcore.cpp index ec6ab18f84..61e03340fb 100644 --- a/modules/gapi/src/backends/ocl/goclcore.cpp +++ b/modules/gapi/src/backends/ocl/goclcore.cpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #include "precomp.hpp" @@ -337,6 +337,14 @@ GAPI_OCL_KERNEL(GOCLSum, cv::gapi::core::GSum) } }; +GAPI_OCL_KERNEL(GOCLCountNonZero, cv::gapi::core::GCountNonZero) +{ + static void run(const cv::UMat& in, int& out) + { + out = cv::countNonZero(in); + } +}; + GAPI_OCL_KERNEL(GOCLAddW, cv::gapi::core::GAddW) { static void run(const cv::UMat& in1, double alpha, const cv::UMat& in2, double beta, double gamma, int dtype, cv::UMat& out) @@ -565,6 +573,7 @@ cv::gapi::GKernelPackage cv::gapi::core::ocl::kernels() , GOCLAbsDiff , GOCLAbsDiffC , GOCLSum + , GOCLCountNonZero , GOCLAddW , GOCLNormL1 , GOCLNormL2 diff --git a/modules/gapi/src/backends/ocl/goclkernel.cpp b/modules/gapi/src/backends/ocl/goclkernel.cpp index 585e0174c8..9ea8502d26 100644 --- a/modules/gapi/src/backends/ocl/goclkernel.cpp +++ b/modules/gapi/src/backends/ocl/goclkernel.cpp @@ -34,6 +34,11 @@ cv::detail::VectorRef& cv::GOCLContext::outVecRef(int output) return util::get(m_results.at(output)); } +cv::detail::OpaqueRef& cv::GOCLContext::outOpaqueRef(int output) +{ + return util::get(m_results.at(output)); +} + cv::GOCLKernel::GOCLKernel() { } diff --git a/modules/gapi/test/common/gapi_core_tests.hpp b/modules/gapi/test/common/gapi_core_tests.hpp index 308f88622b..4a0a7641f9 100644 --- a/modules/gapi/test/common/gapi_core_tests.hpp +++ b/modules/gapi/test/common/gapi_core_tests.hpp @@ -97,6 +97,7 @@ GAPI_TEST_FIXTURE(MaxTest, initMatsRandU, <>, 0) GAPI_TEST_FIXTURE(AbsDiffTest, initMatsRandU, <>, 0) GAPI_TEST_FIXTURE(AbsDiffCTest, initMatsRandU, <>, 0) GAPI_TEST_FIXTURE(SumTest, initMatrixRandU, FIXTURE_API(CompareScalars), 1, cmpF) +GAPI_TEST_FIXTURE(CountNonZeroTest, initMatrixRandU, FIXTURE_API(CompareScalars), 1, cmpF) GAPI_TEST_FIXTURE(AddWeightedTest, initMatsRandU, FIXTURE_API(CompareMats), 1, cmpF) GAPI_TEST_FIXTURE(NormTest, initMatrixRandU, FIXTURE_API(CompareScalars,NormTypes), 2, cmpF, opType) diff --git a/modules/gapi/test/common/gapi_core_tests_inl.hpp b/modules/gapi/test/common/gapi_core_tests_inl.hpp index 331ef70a3b..e350a14e65 100644 --- a/modules/gapi/test/common/gapi_core_tests_inl.hpp +++ b/modules/gapi/test/common/gapi_core_tests_inl.hpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018-2019 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #ifndef OPENCV_GAPI_CORE_TESTS_INL_HPP @@ -614,6 +614,29 @@ TEST_P(SumTest, AccuracyTest) } } +#pragma push_macro("countNonZero") +#undef countNonZero +TEST_P(CountNonZeroTest, AccuracyTest) +{ + int out_cnz_gapi, out_cnz_ocv; + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::countNonZero(in); + + cv::GComputation c(cv::GIn(in), cv::GOut(out)); + c.apply(cv::gin(in_mat1), cv::gout(out_cnz_gapi), getCompileArgs()); + // OpenCV code ///////////////////////////////////////////////////////////// + { + out_cnz_ocv = cv::countNonZero(in_mat1); + } + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_cnz_gapi, out_cnz_ocv)); + } +} +#pragma pop_macro("countNonZero") + TEST_P(AddWeightedTest, AccuracyTest) { auto& rng = cv::theRNG(); diff --git a/modules/gapi/test/cpu/gapi_core_tests_cpu.cpp b/modules/gapi/test/cpu/gapi_core_tests_cpu.cpp index ff981309ba..53faa28178 100644 --- a/modules/gapi/test/cpu/gapi_core_tests_cpu.cpp +++ b/modules/gapi/test/cpu/gapi_core_tests_cpu.cpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018-2019 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #include "../test_precomp.hpp" @@ -202,6 +202,15 @@ INSTANTIATE_TEST_CASE_P(SumTestCPU, SumTest, Values(CORE_CPU), Values(AbsToleranceScalar(1e-5).to_compare_obj()))); +INSTANTIATE_TEST_CASE_P(CountNonZeroTestCPU, CountNonZeroTest, + Combine(Values( CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1 ), + Values(cv::Size(1280, 720), + cv::Size(640, 480), + cv::Size(128, 128)), + Values(-1), + Values(CORE_CPU), + Values(AbsToleranceScalar(1e-5).to_compare_obj()))); + INSTANTIATE_TEST_CASE_P(AbsDiffTestCPU, AbsDiffTest, Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), Values(cv::Size(1280, 720), diff --git a/modules/gapi/test/gapi_opaque_tests.cpp b/modules/gapi/test/gapi_opaque_tests.cpp index 9bbb431052..4cadb918b8 100644 --- a/modules/gapi/test/gapi_opaque_tests.cpp +++ b/modules/gapi/test/gapi_opaque_tests.cpp @@ -63,6 +63,14 @@ GAPI_OCV_KERNEL(OCVGeneratePoint, ThisTest::GeneratePoint) } }; +GAPI_OCL_KERNEL(OCLGeneratePoint, ThisTest::GeneratePoint) +{ + static void run(const cv::UMat&, cv::Point& out) + { + out = cv::Point(42, 42); + } +}; + GAPI_OCV_KERNEL(OCVFillMat, ThisTest::FillMat) { static void run(int a, int, int, cv::Size, cv::Mat& out) @@ -79,6 +87,16 @@ GAPI_OCV_KERNEL(OCVPaintPoint, ThisTest::PaintPoint) } }; +GAPI_OCL_KERNEL(OCLPaintPoint, ThisTest::PaintPoint) +{ + static void run(cv::Point a, int depth, int chan, cv::Size size, cv::UMat& out) + { + GAPI_Assert(chan == 1); + out.create(size, CV_MAKETYPE(depth, chan)); + cv::drawMarker(out, a, cv::Scalar(77)); + } +}; + GAPI_OCV_KERNEL(OCVGenerateOpaque, ThisTest::GenerateOpaque) { static void run(const cv::Mat& a, const cv::Mat& b, const std::string& s, @@ -189,6 +207,57 @@ TEST(GOpaque, TestOpaqueCustomOut2) EXPECT_EQ(out2.s, str2); } +TEST(GOpaque, TestOpaqueOCLBackendIn) +{ + cv::Point p_in = {42, 42}; + cv::Mat mat_out; + + ThisTest::GPointOpaque in; + cv::GMat out = ThisTest::PaintPoint::on(in, CV_8U, 1, {50, 50}); + + cv::GComputation c(cv::GIn(in), cv::GOut(out)); + c.apply(cv::gin(p_in), cv::gout(mat_out), + cv::compile_args(cv::gapi::kernels())); + + int painted = mat_out.at(42, 42); + EXPECT_EQ(painted, 77); +} + +TEST(GOpaque, TestOpaqueOCLBackendBetween) +{ + cv::Size sz = {50, 50}; + int depth = CV_8U; + int chan = 1; + cv::Mat mat_in = cv::Mat::zeros(sz, CV_MAKETYPE(depth, chan)); + cv::Mat mat_out; + + cv::GMat in; + auto betw = ThisTest::GeneratePoint::on(in); + cv::GMat out = ThisTest::PaintPoint::on(betw, depth, chan, sz); + + cv::GComputation c(cv::GIn(in), cv::GOut(out)); + c.apply(cv::gin(mat_in), cv::gout(mat_out), + cv::compile_args(cv::gapi::kernels())); + + int painted = mat_out.at(42, 42); + EXPECT_EQ(painted, 77); +} + +TEST(GOpaque, TestOpaqueOCLBackendOut) +{ + cv::Mat input = cv::Mat(52, 52, CV_8U); + cv::Point p_out; + + cv::GMat in; + ThisTest::GPointOpaque out = ThisTest::GeneratePoint::on(in); + + cv::GComputation c(cv::GIn(in), cv::GOut(out)); + c.apply(cv::gin(input), cv::gout(p_out), + cv::compile_args(cv::gapi::kernels())); + + EXPECT_TRUE(p_out == cv::Point(42, 42)); +} + TEST(GOpaque_OpaqueRef, TestMov) { // Warning: this test is testing some not-very-public APIs diff --git a/modules/gapi/test/gpu/gapi_core_tests_gpu.cpp b/modules/gapi/test/gpu/gapi_core_tests_gpu.cpp index 35daed7503..1bd076a480 100644 --- a/modules/gapi/test/gpu/gapi_core_tests_gpu.cpp +++ b/modules/gapi/test/gpu/gapi_core_tests_gpu.cpp @@ -2,7 +2,7 @@ // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // -// Copyright (C) 2018-2019 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #include "../test_precomp.hpp" @@ -192,7 +192,16 @@ INSTANTIATE_TEST_CASE_P(SumTestGPU, SumTest, cv::Size(128, 128)), Values(-1), Values(CORE_GPU), - Values(AbsToleranceScalar(1e-3).to_compare_obj())));//TODO: too relaxed? + Values(AbsToleranceScalar(1e-5).to_compare_obj()))); + +INSTANTIATE_TEST_CASE_P(CountNonZeroTestGPU, CountNonZeroTest, + Combine(Values( CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1 ), + Values(cv::Size(1280, 720), + cv::Size(640, 480), + cv::Size(128, 128)), + Values(-1), + Values(CORE_GPU), + Values(AbsToleranceScalar(1e-5).to_compare_obj()))); INSTANTIATE_TEST_CASE_P(AbsDiffTestGPU, AbsDiffTest, Combine(Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ),