From 220b278575e59cb11dc5f9994f5ce1644a3a39cb Mon Sep 17 00:00:00 2001 From: Dmitry Budnikov Date: Mon, 29 Oct 2018 17:34:20 +0300 Subject: [PATCH] Merge pull request #12944 from dbudniko:dbudniko/tests_thresholds * added threshold to g-api imgproc tests * trailing spaces remove * try to fix warnings * fix license header * fix random numbers issue * fix Sobel test * license headers + precompiled headers included --- .../gapi/perf/common/gapi_core_perf_tests.cpp | 9 + .../gapi/perf/common/gapi_core_perf_tests.hpp | 1808 +---------------- .../perf/common/gapi_core_perf_tests_inl.hpp | 1784 ++++++++++++++++ .../perf/common/gapi_imgproc_perf_tests.cpp | 9 + .../perf/common/gapi_imgproc_perf_tests.hpp | 898 +------- .../common/gapi_imgproc_perf_tests_inl.hpp | 910 +++++++++ .../perf/cpu/gapi_core_perf_tests_cpu.cpp | 469 +++-- .../perf/cpu/gapi_imgproc_perf_tests_cpu.cpp | 280 ++- .../gapi/test/common/gapi_core_tests_inl.hpp | 8 +- .../gapi/test/common/gapi_imgproc_tests.hpp | 45 +- .../test/common/gapi_imgproc_tests_inl.hpp | 293 +-- .../gapi/test/common/gapi_tests_common.hpp | 31 +- .../gapi/test/cpu/gapi_imgproc_tests_cpu.cpp | 94 +- .../test/cpu/gapi_imgproc_tests_fluid.cpp | 151 +- 14 files changed, 3577 insertions(+), 3212 deletions(-) create mode 100644 modules/gapi/perf/common/gapi_core_perf_tests.cpp create mode 100644 modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp create mode 100644 modules/gapi/perf/common/gapi_imgproc_perf_tests.cpp create mode 100644 modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp diff --git a/modules/gapi/perf/common/gapi_core_perf_tests.cpp b/modules/gapi/perf/common/gapi_core_perf_tests.cpp new file mode 100644 index 0000000000..2df4d88906 --- /dev/null +++ b/modules/gapi/perf/common/gapi_core_perf_tests.cpp @@ -0,0 +1,9 @@ +// This file is part of OpenCV project. +// 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 + + +#include "perf_precomp.hpp" +#include "gapi_core_perf_tests_inl.hpp" diff --git a/modules/gapi/perf/common/gapi_core_perf_tests.hpp b/modules/gapi/perf/common/gapi_core_perf_tests.hpp index 49d7791f75..791ee87a40 100644 --- a/modules/gapi/perf/common/gapi_core_perf_tests.hpp +++ b/modules/gapi/perf/common/gapi_core_perf_tests.hpp @@ -5,6 +5,10 @@ // Copyright (C) 2018 Intel Corporation +#ifndef OPENCV_GAPI_CORE_PERF_TESTS_HPP +#define OPENCV_GAPI_CORE_PERF_TESTS_HPP + + #include "../../test/common/gapi_tests_common.hpp" #include "opencv2/gapi/core.hpp" @@ -22,1761 +26,51 @@ namespace opencv_test //------------------------------------------------------------------------------ - class AddPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(AddPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::add(in_mat1, in_mat2, out_mat_ocv, cv::noArray(), dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out; - out = cv::gapi::add(in1, in2, dtype); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class AddCPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(AddCPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::add(in_mat1, sc, out_mat_ocv, cv::noArray(), dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar sc1; - out = cv::gapi::addC(in1, sc1, dtype); - cv::GComputation c(GIn(in1, sc1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class SubPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(SubPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::subtract(in_mat1, in_mat2, out_mat_ocv, cv::noArray(), dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out; - out = cv::gapi::sub(in1, in2, dtype); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class SubCPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(SubCPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::subtract(in_mat1, sc, out_mat_ocv, cv::noArray(), dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar sc1; - out = cv::gapi::subC(in1, sc1, dtype); - cv::GComputation c(GIn(in1, sc1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class SubRCPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(SubRCPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::subtract(sc, in_mat1, out_mat_ocv, cv::noArray(), dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar sc1; - out = cv::gapi::subRC(sc1, in1, dtype); - cv::GComputation c(GIn(in1, sc1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class MulPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(MulPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::multiply(in_mat1, in_mat2, out_mat_ocv, dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out; - out = cv::gapi::mul(in1, in2, dtype); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class MulDoublePerfTest : public TestPerfParams> {}; - PERF_TEST_P_(MulDoublePerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - auto& rng = cv::theRNG(); - double d = rng.uniform(0.0, 10.0); - initMatrixRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::multiply(in_mat1, d, out_mat_ocv, 1, dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - out = cv::gapi::mulC(in1, d, dtype); - cv::GComputation c(in1, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class MulCPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(MulCPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::multiply(in_mat1, sc, out_mat_ocv, 1, dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar sc1; - out = cv::gapi::mulC(in1, sc1, dtype); - cv::GComputation c(GIn(in1, sc1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class DivPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(DivPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::divide(in_mat1, in_mat2, out_mat_ocv, dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out; - out = cv::gapi::div(in1, in2, dtype); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class DivCPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(DivCPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::divide(in_mat1, sc, out_mat_ocv, 1.0, dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar sc1; - out = cv::gapi::divC(in1, sc1, 1.0, dtype); - cv::GComputation c(GIn(in1, sc1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class DivRCPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(DivRCPerfTest, TestPerformance) - { - Size sz = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - initMatsRandU(type, sz, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::divide(sc, in_mat1, out_mat_ocv, 1.0, dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar sc1; - out = cv::gapi::divRC(sc1, in1, 1.0, dtype); - cv::GComputation c(GIn(in1, sc1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class MaskPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(MaskPerfTest, TestPerformance) - { - Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatrixRandU(type, sz_in, type, false); - in_mat2 = cv::Mat(sz_in, CV_8UC1); - cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255)); - in_mat2 = in_mat2 > 128; - - // OpenCV code /////////////////////////////////////////////////////////// - out_mat_ocv = cv::Mat::zeros(in_mat1.size(), in_mat1.type()); - in_mat1.copyTo(out_mat_ocv, in_mat2); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in, m; - auto out = cv::gapi::mask(in, m); - cv::GComputation c(cv::GIn(in, m), cv::GOut(out)); - - // Warm-up graph engine: - c.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class MeanPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(MeanPerfTest, TestPerformance) - { - Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatrixRandU(type, sz_in, false); - cv::Scalar out_norm; - cv::Scalar out_norm_ocv; - - // OpenCV code /////////////////////////////////////////////////////////// - out_norm_ocv = cv::mean(in_mat1); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::mean(in); - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - - // Warm-up graph engine: - c.apply(cv::gin(in_mat1), cv::gout(out_norm)); - - TEST_CYCLE() - { - c.apply(cv::gin(in_mat1), cv::gout(out_norm)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(out_norm[0], out_norm_ocv[0]); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class Polar2CartPerfTest : public TestPerfParams {}; - PERF_TEST_P_(Polar2CartPerfTest, TestPerformance) - { - Size sz_in = GetParam(); - - initMatsRandU(CV_32FC1, sz_in, CV_32FC1, false); - cv::Mat out_mat2; - cv::Mat out_mat_ocv2; - - // OpenCV code /////////////////////////////////////////////////////////// - cv::polarToCart(in_mat1, in_mat2, out_mat_ocv, out_mat_ocv2); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out1, out2; - std::tie(out1, out2) = cv::gapi::polarToCart(in1, in2); - cv::GComputation c(GIn(in1, in2), GOut(out1, out2)); - - // Warm-up graph engine: - c.apply(gin(in_mat1,in_mat2), gout(out_mat_gapi, out_mat2)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1,in_mat2), gout(out_mat_gapi, out_mat2)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class Cart2PolarPerfTest : public TestPerfParams {}; - PERF_TEST_P_(Cart2PolarPerfTest, TestPerformance) - { - Size sz_in = GetParam(); - - initMatsRandU(CV_32FC1, sz_in, CV_32FC1, false); - cv::Mat out_mat2(sz_in, CV_32FC1); - cv::Mat out_mat_ocv2(sz_in, CV_32FC1); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::cartToPolar(in_mat1, in_mat2, out_mat_ocv, out_mat_ocv2); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out1, out2; - std::tie(out1, out2) = cv::gapi::cartToPolar(in1, in2); - cv::GComputation c(GIn(in1, in2), GOut(out1, out2)); - - // Warm-up graph engine: - c.apply(gin(in_mat1,in_mat2), gout(out_mat_gapi, out_mat2)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1,in_mat2), gout(out_mat_gapi, out_mat2)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class CmpPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(CmpPerfTest, TestPerformance) - { - CmpTypes opType = get<0>(GetParam()); - cv::Size sz = get<1>(GetParam()); - MatType type = get<2>(GetParam()); - - initMatsRandU(type, sz, CV_8U, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::compare(in_mat1, in_mat2, out_mat_ocv, opType); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out; - switch(opType) - { - case CMP_EQ: out = cv::gapi::cmpEQ(in1, in2); break; - case CMP_GT: out = cv::gapi::cmpGT(in1, in2); break; - case CMP_GE: out = cv::gapi::cmpGE(in1, in2); break; - case CMP_LT: out = cv::gapi::cmpLT(in1, in2); break; - case CMP_LE: out = cv::gapi::cmpLE(in1, in2); break; - case CMP_NE: out = cv::gapi::cmpNE(in1, in2); break; - default: FAIL() << "no such compare operation type for two matrices!"; - } - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class CmpWithScalarPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(CmpWithScalarPerfTest, TestPerformance) - { - CmpTypes opType = get<0>(GetParam()); - cv::Size sz = get<1>(GetParam()); - MatType type = get<2>(GetParam()); - - initMatsRandU(type, sz, CV_8U, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::compare(in_mat1, sc, out_mat_ocv, opType); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar in2; - switch(opType) - { - case CMP_EQ: out = cv::gapi::cmpEQ(in1, in2); break; - case CMP_GT: out = cv::gapi::cmpGT(in1, in2); break; - case CMP_GE: out = cv::gapi::cmpGE(in1, in2); break; - case CMP_LT: out = cv::gapi::cmpLT(in1, in2); break; - case CMP_LE: out = cv::gapi::cmpLE(in1, in2); break; - case CMP_NE: out = cv::gapi::cmpNE(in1, in2); break; - default: FAIL() << "no such compare operation type for matrix and scalar!"; - } - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class BitwisePerfTest : public TestPerfParams> {}; - PERF_TEST_P_(BitwisePerfTest, TestPerformance) - { - bitwiseOp opType = get<0>(GetParam()); - cv::Size sz = get<1>(GetParam()); - MatType type = get<2>(GetParam()); - - initMatsRandU(type, sz, type, false); - - // G-API code & corresponding OpenCV code //////////////////////////////// - cv::GMat in1, in2, out; - switch(opType) - { - case AND: - { - out = cv::gapi::bitwise_and(in1, in2); - cv::bitwise_and(in_mat1, in_mat2, out_mat_ocv); - break; - } - case OR: - { - out = cv::gapi::bitwise_or(in1, in2); - cv::bitwise_or(in_mat1, in_mat2, out_mat_ocv); - break; - } - case XOR: - { - out = cv::gapi::bitwise_xor(in1, in2); - cv::bitwise_xor(in_mat1, in_mat2, out_mat_ocv); - break; - } - default: - { - FAIL() << "no such bitwise operation type!"; - } - } - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class BitwiseNotPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(BitwiseNotPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatrixRandU(type, sz_in, type, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::bitwise_not(in_mat1, out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in, out; - out = cv::gapi::bitwise_not(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class SelectPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(SelectPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatsRandU(type, sz_in, type, false); - cv::Mat in_mask(sz_in, CV_8UC1); - cv::randu(in_mask, cv::Scalar::all(0), cv::Scalar::all(255)); - - // OpenCV code /////////////////////////////////////////////////////////// - in_mat2.copyTo(out_mat_ocv); - in_mat1.copyTo(out_mat_ocv, in_mask); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, in3, out; - out = cv::gapi::select(in1, in2, in3); - cv::GComputation c(GIn(in1, in2, in3), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2, in_mask), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2, in_mask), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class MinPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(MinPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatsRandU(type, sz_in, type, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::min(in_mat1, in_mat2, out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out; - out = cv::gapi::min(in1, in2); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class MaxPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(MaxPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatsRandU(type, sz_in, type, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::max(in_mat1, in_mat2, out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out; - out = cv::gapi::max(in1, in2); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class AbsDiffPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(AbsDiffPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatsRandU(type, sz_in, type, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::absdiff(in_mat1, in_mat2, out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, out; - out = cv::gapi::absDiff(in1, in2); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class AbsDiffCPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(AbsDiffCPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatsRandU(type, sz_in, type, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::absdiff(in_mat1, sc, out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar sc1; - out = cv::gapi::absDiffC(in1, sc1); - cv::GComputation c(cv::GIn(in1, sc1), cv::GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, sc), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class SumPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(SumPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatrixRandU(type, sz_in, false); - cv::Scalar out_sum; - cv::Scalar out_sum_ocv; - - // OpenCV code /////////////////////////////////////////////////////////// - out_sum_ocv = cv::sum(in_mat1); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::sum(in); - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - - // Warm-up graph engine: - c.apply(cv::gin(in_mat1), cv::gout(out_sum)); - - TEST_CYCLE() - { - c.apply(cv::gin(in_mat1), cv::gout(out_sum)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(out_sum[0], out_sum_ocv[0]); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class AddWeightedPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(AddWeightedPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int dtype = get<2>(GetParam()); - - auto& rng = cv::theRNG(); - double alpha = rng.uniform(0.0, 1.0); - double beta = rng.uniform(0.0, 1.0); - double gamma = rng.uniform(0.0, 1.0); - initMatsRandU(type, sz_in, dtype, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::addWeighted(in_mat1, alpha, in_mat2, beta, gamma, out_mat_ocv, dtype); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2; - auto out = cv::gapi::addWeighted(in1, alpha, in2, beta, gamma, dtype); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class NormPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(NormPerfTest, TestPerformance) - { - NormTypes opType = get<0>(GetParam()); - cv::Size sz = get<1>(GetParam()); - MatType type = get<2>(GetParam()); - - initMatrixRandU(type, sz, type, false); - cv::Scalar out_norm; - cv::Scalar out_norm_ocv; - - // OpenCV code /////////////////////////////////////////////////////////// - out_norm_ocv = cv::norm(in_mat1, opType); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1; - cv::GScalar out; - switch(opType) - { - case NORM_L1: out = cv::gapi::normL1(in1); break; - case NORM_L2: out = cv::gapi::normL2(in1); break; - case NORM_INF: out = cv::gapi::normInf(in1); break; - default: FAIL() << "no such norm operation type!"; - } - cv::GComputation c(GIn(in1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1), gout(out_norm)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1), gout(out_norm)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(out_norm[0], out_norm_ocv[0]); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class IntegralPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(IntegralPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - MatType type_out = (type == CV_8U) ? CV_32SC1 : CV_64FC1; - - - in_mat1 = cv::Mat(sz_in, type); - cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255)); - - cv::Size sz_out = cv::Size(sz_in.width + 1, sz_in.height + 1); - cv::Mat out_mat1(sz_out, type_out); - cv::Mat out_mat_ocv1(sz_out, type_out); - - cv::Mat out_mat2(sz_out, CV_64FC1); - cv::Mat out_mat_ocv2(sz_out, CV_64FC1); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::integral(in_mat1, out_mat_ocv1, out_mat_ocv2); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out1, out2; - std::tie(out1, out2) = cv::gapi::integral(in1, type_out, CV_64FC1); - cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2)); - - // Warm-up graph engine: - c.apply(cv::gin(in_mat1), cv::gout(out_mat1, out_mat2)); - - TEST_CYCLE() - { - c.apply(cv::gin(in_mat1), cv::gout(out_mat1, out_mat2)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv1 != out_mat1)); - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ThresholdPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ThresholdPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int tt = get<2>(GetParam()); - - auto& rng = cv::theRNG(); - cv::Scalar thr = cv::Scalar(rng(50),rng(50),rng(50),rng(50)); - cv::Scalar maxval = cv::Scalar(50 + rng(50),50 + rng(50),50 + rng(50),50 + rng(50)); - initMatrixRandU(type, sz_in, type, false); - cv::Scalar out_scalar; - - // OpenCV code /////////////////////////////////////////////////////////// - cv::threshold(in_mat1, out_mat_ocv, thr.val[0], maxval.val[0], tt); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar th1, mv1; - out = cv::gapi::threshold(in1, th1, mv1, tt); - cv::GComputation c(GIn(in1, th1, mv1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, thr, maxval), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, thr, maxval), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ThresholdOTPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ThresholdOTPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int tt = get<2>(GetParam()); - - auto& rng = cv::theRNG(); - cv::Scalar maxval = cv::Scalar(50 + rng(50),50 + rng(50),50 + rng(50),50 + rng(50)); - initMatrixRandU(type, sz_in, type, false); - cv::Scalar out_gapi_scalar; - double ocv_res; - - // OpenCV code /////////////////////////////////////////////////////////// - ocv_res = cv::threshold(in_mat1, out_mat_ocv, maxval.val[0], maxval.val[0], tt); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out; - cv::GScalar mv1, scout; - std::tie(out, scout) = cv::gapi::threshold(in1, mv1, tt); - cv::GComputation c(cv::GIn(in1, mv1), cv::GOut(out, scout)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, maxval), gout(out_mat_gapi, out_gapi_scalar)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, maxval), gout(out_mat_gapi, out_gapi_scalar)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - EXPECT_EQ(ocv_res, out_gapi_scalar.val[0]); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class InRangePerfTest : public TestPerfParams> {}; - PERF_TEST_P_(InRangePerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - auto& rng = cv::theRNG(); - cv::Scalar thrLow = cv::Scalar(rng(100),rng(100),rng(100),rng(100)); - cv::Scalar thrUp = cv::Scalar(100 + rng(100),100 + rng(100),100 + rng(100),100 + rng(100)); - initMatrixRandU(type, sz_in, type, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::inRange(in_mat1, thrLow, thrUp, out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1; - cv::GScalar th1, mv1; - auto out = cv::gapi::inRange(in1, th1, mv1); - cv::GComputation c(GIn(in1, th1, mv1), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, thrLow, thrUp), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, thrLow, thrUp), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class Split3PerfTest : public TestPerfParams {}; - PERF_TEST_P_(Split3PerfTest, TestPerformance) - { - cv::Size sz_in = GetParam(); - - initMatrixRandU(CV_8UC3, sz_in, CV_8UC1); - cv::Mat out_mat2 = cv::Mat(sz_in, CV_8UC1); - cv::Mat out_mat3 = cv::Mat(sz_in, CV_8UC1); - cv::Mat out_mat_ocv2 = cv::Mat(sz_in, CV_8UC1); - cv::Mat out_mat_ocv3 = cv::Mat(sz_in, CV_8UC1); - - // OpenCV code /////////////////////////////////////////////////////////// - std::vector out_mats_ocv = {out_mat_ocv, out_mat_ocv2, out_mat_ocv3}; - cv::split(in_mat1, out_mats_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out1, out2, out3; - std::tie(out1, out2, out3) = cv::gapi::split3(in1); - cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2, out3)); - - // Warm-up graph engine: - c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3)); - - TEST_CYCLE() - { - c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv3 != out_mat3)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class Split4PerfTest : public TestPerfParams {}; - PERF_TEST_P_(Split4PerfTest, TestPerformance) - { - cv::Size sz_in = GetParam(); - - initMatrixRandU(CV_8UC4, sz_in, CV_8UC1); - cv::Mat out_mat2 = cv::Mat(sz_in, CV_8UC1); - cv::Mat out_mat3 = cv::Mat(sz_in, CV_8UC1); - cv::Mat out_mat4 = cv::Mat(sz_in, CV_8UC1); - cv::Mat out_mat_ocv2 = cv::Mat(sz_in, CV_8UC1); - cv::Mat out_mat_ocv3 = cv::Mat(sz_in, CV_8UC1); - cv::Mat out_mat_ocv4 = cv::Mat(sz_in, CV_8UC1); - - // OpenCV code /////////////////////////////////////////////////////////// - std::vector out_mats_ocv = {out_mat_ocv, out_mat_ocv2, out_mat_ocv3, out_mat_ocv4}; - cv::split(in_mat1, out_mats_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, out1, out2, out3, out4; - std::tie(out1, out2, out3, out4) = cv::gapi::split4(in1); - cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2, out3, out4)); - - // Warm-up graph engine: - c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3, out_mat4)); - - TEST_CYCLE() - { - c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3, out_mat4)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv3 != out_mat3)); - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv4 != out_mat4)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class Merge3PerfTest : public TestPerfParams {}; - PERF_TEST_P_(Merge3PerfTest, TestPerformance) - { - cv::Size sz_in = GetParam(); - - initMatsRandU(CV_8UC1, sz_in, CV_8UC3); - cv::Mat in_mat3(sz_in, CV_8UC1); - cv::Scalar mean = cv::Scalar::all(127); - cv::Scalar stddev = cv::Scalar::all(40.f); - cv::randn(in_mat3, mean, stddev); - - // OpenCV code /////////////////////////////////////////////////////////// - std::vector in_mats_ocv = {in_mat1, in_mat2, in_mat3}; - cv::merge(in_mats_ocv, out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, in3; - auto out = cv::gapi::merge3(in1, in2, in3); - cv::GComputation c(cv::GIn(in1, in2, in3), cv::GOut(out)); - - // Warm-up graph engine: - c.apply(cv::gin(in_mat1, in_mat2, in_mat3), cv::gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(cv::gin(in_mat1, in_mat2, in_mat3), cv::gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class Merge4PerfTest : public TestPerfParams {}; - PERF_TEST_P_(Merge4PerfTest, TestPerformance) - { - cv::Size sz_in = GetParam(); - - initMatsRandU(CV_8UC1, sz_in, CV_8UC3); - cv::Mat in_mat3(sz_in, CV_8UC1); - cv::Mat in_mat4(sz_in, CV_8UC1); - cv::Scalar mean = cv::Scalar::all(127); - cv::Scalar stddev = cv::Scalar::all(40.f); - cv::randn(in_mat3, mean, stddev); - cv::randn(in_mat4, mean, stddev); - - // OpenCV code /////////////////////////////////////////////////////////// - std::vector in_mats_ocv = {in_mat1, in_mat2, in_mat3, in_mat4}; - cv::merge(in_mats_ocv, out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2, in3, in4; - auto out = cv::gapi::merge4(in1, in2, in3, in4); - cv::GComputation c(cv::GIn(in1, in2, in3, in4), cv::GOut(out)); - - // Warm-up graph engine: - c.apply(cv::gin(in_mat1, in_mat2, in_mat3, in_mat4), cv::gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(cv::gin(in_mat1, in_mat2, in_mat3, in_mat4), cv::gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class RemapPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(RemapPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - initMatrixRandU(type, sz_in, type, false); - cv::Mat in_map1(sz_in, CV_16SC2); - cv::Mat in_map2 = cv::Mat(); - cv::randu(in_map1, cv::Scalar::all(0), cv::Scalar::all(255)); - cv::Scalar bv = cv::Scalar(); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::remap(in_mat1, out_mat_ocv, in_map1, in_map2, cv::INTER_NEAREST, cv::BORDER_REPLICATE, bv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1; - auto out = cv::gapi::remap(in1, in_map1, in_map2, cv::INTER_NEAREST, cv::BORDER_REPLICATE, bv); - cv::GComputation c(in1, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class FlipPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(FlipPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - int flipCode = get<2>(GetParam()); - - initMatrixRandU(type, sz_in, type, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::flip(in_mat1, out_mat_ocv, flipCode); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::flip(in, flipCode); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class CropPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(CropPerfTest, TestPerformance) - { - cv::Size sz_in = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - cv::Rect rect_to = get<2>(GetParam()); - - initMatrixRandU(type, sz_in, type, false); - cv::Size sz_out = cv::Size(rect_to.width, rect_to.height); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::Mat(in_mat1, rect_to).copyTo(out_mat_ocv); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::crop(in, rect_to); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_out); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ConcatHorPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ConcatHorPerfTest, TestPerformance) - { - cv::Size sz_out = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - int wpart = sz_out.width / 4; - - cv::Size sz_in1 = cv::Size(wpart, sz_out.height); - cv::Size sz_in2 = cv::Size(sz_out.width - wpart, sz_out.height); - - in_mat1 = cv::Mat(sz_in1, type); - in_mat2 = cv::Mat(sz_in2, type); - - cv::Scalar mean = cv::Scalar::all(127); - cv::Scalar stddev = cv::Scalar::all(40.f); - - cv::randn(in_mat1, mean, stddev); - cv::randn(in_mat2, mean, stddev); - - out_mat_gapi = cv::Mat(sz_out, type); - out_mat_ocv = cv::Mat(sz_out, type); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::hconcat(in_mat1, in_mat2, out_mat_ocv ); - - // G-API code //////////////////////////////////////////////////////////// - cv::GMat in1, in2; - auto out = cv::gapi::concatHor(in1, in2); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ConcatHorVecPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ConcatHorVecPerfTest, TestPerformance) - { - cv::Size sz_out = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - int wpart1 = sz_out.width / 3; - int wpart2 = sz_out.width / 2; - - cv::Size sz_in1 = cv::Size(wpart1, sz_out.height); - cv::Size sz_in2 = cv::Size(wpart2, sz_out.height); - cv::Size sz_in3 = cv::Size(sz_out.width - wpart1 - wpart2, sz_out.height); - - in_mat1 = cv::Mat(sz_in1, type); - in_mat2 = cv::Mat(sz_in2, type); - cv::Mat in_mat3(sz_in3, type); - - cv::Scalar mean = cv::Scalar::all(127); - cv::Scalar stddev = cv::Scalar::all(40.f); - - cv::randn(in_mat1, mean, stddev); - cv::randn(in_mat2, mean, stddev); - cv::randn(in_mat3, mean, stddev); - - out_mat_gapi = cv::Mat(sz_out, type); - out_mat_ocv = cv::Mat(sz_out, type); - - std::vector cvmats = {in_mat1, in_mat2, in_mat3}; - - // OpenCV code /////////////////////////////////////////////////////////// - cv::hconcat(cvmats, out_mat_ocv ); - - // G-API code ////////////////////////////////////////////////////////////// - std::vector mats(3); - auto out = cv::gapi::concatHor(mats); - cv::GComputation c({mats[0], mats[1], mats[2]}, {out}); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ConcatVertPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ConcatVertPerfTest, TestPerformance) - { - cv::Size sz_out = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - int hpart = sz_out.height * 2/3; - - cv::Size sz_in1 = cv::Size(sz_out.width, hpart); - cv::Size sz_in2 = cv::Size(sz_out.width, sz_out.height - hpart); - - in_mat1 = cv::Mat(sz_in1, type); - in_mat2 = cv::Mat(sz_in2, type); - - cv::Scalar mean = cv::Scalar::all(127); - cv::Scalar stddev = cv::Scalar::all(40.f); - - cv::randn(in_mat1, mean, stddev); - cv::randn(in_mat2, mean, stddev); - - out_mat_gapi = cv::Mat(sz_out, type); - out_mat_ocv = cv::Mat(sz_out, type); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::vconcat(in_mat1, in_mat2, out_mat_ocv ); - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in1, in2; - auto out = cv::gapi::concatVert(in1, in2); - cv::GComputation c(GIn(in1, in2), GOut(out)); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ConcatVertVecPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ConcatVertVecPerfTest, TestPerformance) - { - cv::Size sz_out = get<0>(GetParam()); - MatType type = get<1>(GetParam()); - - int hpart1 = sz_out.height * 2/5; - int hpart2 = sz_out.height / 5; - - cv::Size sz_in1 = cv::Size(sz_out.width, hpart1); - cv::Size sz_in2 = cv::Size(sz_out.width, hpart2); - cv::Size sz_in3 = cv::Size(sz_out.width, sz_out.height - hpart1 - hpart2); - - in_mat1 = cv::Mat(sz_in1, type); - in_mat2 = cv::Mat(sz_in2, type); - cv::Mat in_mat3 (sz_in3, type); - - cv::Scalar mean = cv::Scalar::all(127); - cv::Scalar stddev = cv::Scalar::all(40.f); - - cv::randn(in_mat1, mean, stddev); - cv::randn(in_mat2, mean, stddev); - cv::randn(in_mat3, mean, stddev); - - out_mat_gapi = cv::Mat(sz_out, type); - out_mat_ocv = cv::Mat(sz_out, type); - - std::vector cvmats = {in_mat1, in_mat2, in_mat3}; - - // OpenCV code /////////////////////////////////////////////////////////// - cv::vconcat(cvmats, out_mat_ocv ); - - // G-API code ////////////////////////////////////////////////////////////// - std::vector mats(3); - auto out = cv::gapi::concatVert(mats); - cv::GComputation c({mats[0], mats[1], mats[2]}, {out}); - - // Warm-up graph engine: - c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi)); - - TEST_CYCLE() - { - c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi)); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class LUTPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(LUTPerfTest, TestPerformance) - { - MatType type_mat = get<0>(GetParam()); - MatType type_lut = get<1>(GetParam()); - MatType type_out = CV_MAKETYPE(CV_MAT_DEPTH(type_lut), CV_MAT_CN(type_mat)); - cv::Size sz_in = get<2>(GetParam()); - - initMatrixRandU(type_mat, sz_in, type_out); - cv::Size sz_lut = cv::Size(1, 256); - cv::Mat in_lut (sz_lut, type_lut); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::LUT(in_mat1, in_lut, out_mat_ocv); - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::LUT(in, in_lut); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ConvertToPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ConvertToPerfTest, TestPerformance) - { - MatType type_mat = get<0>(GetParam()); - int depth_to = get<1>(GetParam()); - cv::Size sz_in = get<2>(GetParam()); - MatType type_out = CV_MAKETYPE(depth_to, CV_MAT_CN(type_mat)); - - initMatrixRandU(type_mat, sz_in, type_out); - - // OpenCV code /////////////////////////////////////////////////////////// - in_mat1.convertTo(out_mat_ocv, depth_to); - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::convertTo(in, depth_to); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); - EXPECT_EQ(out_mat_gapi.size(), sz_in); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ResizePerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ResizePerfTest, TestPerformance) - { - MatType type = get<0>(GetParam()); - int interp = get<1>(GetParam()); - cv::Size sz_in = get<2>(GetParam()); - cv::Size sz_out = get<3>(GetParam()); - double tolerance = get<4>(GetParam()); - - in_mat1 = cv::Mat(sz_in, type ); - cv::Scalar mean = cv::Scalar::all(127); - cv::Scalar stddev = cv::Scalar::all(40.f); - cv::randn(in_mat1, mean, stddev); - out_mat_gapi = cv::Mat(sz_out, type); - out_mat_ocv = cv::Mat(sz_out, type); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::resize(in_mat1, out_mat_ocv, sz_out, 0.0, 0.0, interp); - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::resize(in, sz_out, 0.0, 0.0, interp); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - cv::Mat absDiff; - cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff); - EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - - class ResizeFxFyPerfTest : public TestPerfParams> {}; - PERF_TEST_P_(ResizeFxFyPerfTest, TestPerformance) - { - MatType type = get<0>(GetParam()); - int interp = get<1>(GetParam()); - cv::Size sz_in = get<2>(GetParam()); - double fx = get<3>(GetParam()); - double fy = get<4>(GetParam()); - double tolerance = get<5>(GetParam()); - - in_mat1 = cv::Mat(sz_in, type ); - cv::Scalar mean = cv::Scalar::all(127); - cv::Scalar stddev = cv::Scalar::all(40.f); - cv::randn(in_mat1, mean, stddev); - cv::Size sz_out = cv::Size(saturate_cast(sz_in.width *fx),saturate_cast(sz_in.height*fy)); - out_mat_gapi = cv::Mat(sz_out, type); - out_mat_ocv = cv::Mat(sz_out, type); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp); - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::resize(in, sz_out, fx, fy, interp); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - cv::Mat absDiff; - cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff); - EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance)); - - SANITY_CHECK_NOTHING(); - } - -//------------------------------------------------------------------------------ - + class AddPerfTest : public TestPerfParams> {}; + class AddCPerfTest : public TestPerfParams> {}; + class SubPerfTest : public TestPerfParams> {}; + class SubCPerfTest : public TestPerfParams> {}; + class SubRCPerfTest : public TestPerfParams> {}; + class MulPerfTest : public TestPerfParams> {}; + class MulDoublePerfTest : public TestPerfParams> {}; + class MulCPerfTest : public TestPerfParams> {}; + class DivPerfTest : public TestPerfParams> {}; + class DivCPerfTest : public TestPerfParams> {}; + class DivRCPerfTest : public TestPerfParams> {}; + class MaskPerfTest : public TestPerfParams> {}; + class MeanPerfTest : public TestPerfParams> {}; + class Polar2CartPerfTest : public TestPerfParams> {}; + class Cart2PolarPerfTest : public TestPerfParams> {}; + class CmpPerfTest : public TestPerfParams> {}; + class CmpWithScalarPerfTest : public TestPerfParams> {}; + class BitwisePerfTest : public TestPerfParams> {}; + class BitwiseNotPerfTest : public TestPerfParams> {}; + class SelectPerfTest : public TestPerfParams> {}; + class MinPerfTest : public TestPerfParams> {}; + class MaxPerfTest : public TestPerfParams> {}; + class AbsDiffPerfTest : public TestPerfParams> {}; + class AbsDiffCPerfTest : public TestPerfParams> {}; + class SumPerfTest : public TestPerfParams> {}; + class AddWeightedPerfTest : public TestPerfParams> {}; + class NormPerfTest : public TestPerfParams> {}; + class IntegralPerfTest : public TestPerfParams> {}; + class ThresholdPerfTest : public TestPerfParams> {}; + class ThresholdOTPerfTest : public TestPerfParams> {}; + class InRangePerfTest : public TestPerfParams> {}; + class Split3PerfTest : public TestPerfParams> {}; + class Split4PerfTest : public TestPerfParams> {}; + class Merge3PerfTest : public TestPerfParams> {}; + class Merge4PerfTest : public TestPerfParams> {}; + class RemapPerfTest : public TestPerfParams> {}; + class FlipPerfTest : public TestPerfParams> {}; + class CropPerfTest : public TestPerfParams> {}; + class ConcatHorPerfTest : public TestPerfParams> {}; + class ConcatHorVecPerfTest : public TestPerfParams> {}; + class ConcatVertPerfTest : public TestPerfParams> {}; + class ConcatVertVecPerfTest : public TestPerfParams> {}; + class LUTPerfTest : public TestPerfParams> {}; + class ConvertToPerfTest : public TestPerfParams> {}; + class ResizePerfTest : public TestPerfParams> {}; + class ResizeFxFyPerfTest : public TestPerfParams> {}; } +#endif // OPENCV_GAPI_CORE_PERF_TESTS_HPP diff --git a/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp b/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp new file mode 100644 index 0000000000..d1b72e6b9a --- /dev/null +++ b/modules/gapi/perf/common/gapi_core_perf_tests_inl.hpp @@ -0,0 +1,1784 @@ +// This file is part of OpenCV project. +// 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 + + +#ifndef OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP +#define OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP + +#include + +#include "gapi_core_perf_tests.hpp" + +namespace opencv_test +{ +using namespace perf; + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(AddPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::add(in_mat1, in_mat2, out_mat_ocv, cv::noArray(), dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out; + out = cv::gapi::add(in1, in2, dtype); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(AddCPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::add(in_mat1, sc, out_mat_ocv, cv::noArray(), dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar sc1; + out = cv::gapi::addC(in1, sc1, dtype); + cv::GComputation c(GIn(in1, sc1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(SubPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::subtract(in_mat1, in_mat2, out_mat_ocv, cv::noArray(), dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out; + out = cv::gapi::sub(in1, in2, dtype); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(SubCPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::subtract(in_mat1, sc, out_mat_ocv, cv::noArray(), dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar sc1; + out = cv::gapi::subC(in1, sc1, dtype); + cv::GComputation c(GIn(in1, sc1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(SubRCPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::subtract(sc, in_mat1, out_mat_ocv, cv::noArray(), dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar sc1; + out = cv::gapi::subRC(sc1, in1, dtype); + cv::GComputation c(GIn(in1, sc1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(MulPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::multiply(in_mat1, in_mat2, out_mat_ocv, dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out; + out = cv::gapi::mul(in1, in2, dtype); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(MulDoublePerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + auto& rng = cv::theRNG(); + double d = rng.uniform(0.0, 10.0); + initMatrixRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::multiply(in_mat1, d, out_mat_ocv, 1, dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + out = cv::gapi::mulC(in1, d, dtype); + cv::GComputation c(in1, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(MulCPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::multiply(in_mat1, sc, out_mat_ocv, 1, dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar sc1; + out = cv::gapi::mulC(in1, sc1, dtype); + cv::GComputation c(GIn(in1, sc1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(DivPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::divide(in_mat1, in_mat2, out_mat_ocv, dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out; + out = cv::gapi::div(in1, in2, dtype); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(DivCPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::divide(in_mat1, sc, out_mat_ocv, 1.0, dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar sc1; + out = cv::gapi::divC(in1, sc1, 1.0, dtype); + cv::GComputation c(GIn(in1, sc1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(DivRCPerfTest, TestPerformance) +{ + Size sz = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::divide(sc, in_mat1, out_mat_ocv, 1.0, dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar sc1; + out = cv::gapi::divRC(sc1, in1, 1.0, dtype); + cv::GComputation c(GIn(in1, sc1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(MaskPerfTest, TestPerformance) +{ + Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatrixRandU(type, sz_in, type, false); + in_mat2 = cv::Mat(sz_in, CV_8UC1); + cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255)); + in_mat2 = in_mat2 > 128; + + // OpenCV code /////////////////////////////////////////////////////////// + out_mat_ocv = cv::Mat::zeros(in_mat1.size(), in_mat1.type()); + in_mat1.copyTo(out_mat_ocv, in_mat2); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in, m; + auto out = cv::gapi::mask(in, m); + cv::GComputation c(cv::GIn(in, m), cv::GOut(out)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1, in_mat2), cv::gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(MeanPerfTest, TestPerformance) +{ + Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatrixRandU(type, sz_in, false); + cv::Scalar out_norm; + cv::Scalar out_norm_ocv; + + // OpenCV code /////////////////////////////////////////////////////////// + out_norm_ocv = cv::mean(in_mat1); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::mean(in); + cv::GComputation c(cv::GIn(in), cv::GOut(out)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1), cv::gout(out_norm), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_norm), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(out_norm[0], out_norm_ocv[0]); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Polar2CartPerfTest, TestPerformance) +{ + Size sz_in = get<0>(GetParam()); + cv::GCompileArgs compile_args = get<1>(GetParam()); + + initMatsRandU(CV_32FC1, sz_in, CV_32FC1, false); + cv::Mat out_mat2; + cv::Mat out_mat_ocv2; + + // OpenCV code /////////////////////////////////////////////////////////// + cv::polarToCart(in_mat1, in_mat2, out_mat_ocv, out_mat_ocv2); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out1, out2; + std::tie(out1, out2) = cv::gapi::polarToCart(in1, in2); + cv::GComputation c(GIn(in1, in2), GOut(out1, out2)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Cart2PolarPerfTest, TestPerformance) +{ + Size sz_in = get<0>(GetParam()); + cv::GCompileArgs compile_args = get<1>(GetParam()); + + initMatsRandU(CV_32FC1, sz_in, CV_32FC1, false); + cv::Mat out_mat2(sz_in, CV_32FC1); + cv::Mat out_mat_ocv2(sz_in, CV_32FC1); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::cartToPolar(in_mat1, in_mat2, out_mat_ocv, out_mat_ocv2); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out1, out2; + std::tie(out1, out2) = cv::gapi::cartToPolar(in1, in2); + cv::GComputation c(GIn(in1, in2), GOut(out1, out2)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi, out_mat2), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(CmpPerfTest, TestPerformance) +{ + CmpTypes opType = get<0>(GetParam()); + cv::Size sz = get<1>(GetParam()); + MatType type = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, CV_8U, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::compare(in_mat1, in_mat2, out_mat_ocv, opType); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out; + switch (opType) + { + case CMP_EQ: out = cv::gapi::cmpEQ(in1, in2); break; + case CMP_GT: out = cv::gapi::cmpGT(in1, in2); break; + case CMP_GE: out = cv::gapi::cmpGE(in1, in2); break; + case CMP_LT: out = cv::gapi::cmpLT(in1, in2); break; + case CMP_LE: out = cv::gapi::cmpLE(in1, in2); break; + case CMP_NE: out = cv::gapi::cmpNE(in1, in2); break; + default: FAIL() << "no such compare operation type for two matrices!"; + } + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(CmpWithScalarPerfTest, TestPerformance) +{ + CmpTypes opType = get<0>(GetParam()); + cv::Size sz = get<1>(GetParam()); + MatType type = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, CV_8U, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::compare(in_mat1, sc, out_mat_ocv, opType); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar in2; + switch (opType) + { + case CMP_EQ: out = cv::gapi::cmpEQ(in1, in2); break; + case CMP_GT: out = cv::gapi::cmpGT(in1, in2); break; + case CMP_GE: out = cv::gapi::cmpGE(in1, in2); break; + case CMP_LT: out = cv::gapi::cmpLT(in1, in2); break; + case CMP_LE: out = cv::gapi::cmpLE(in1, in2); break; + case CMP_NE: out = cv::gapi::cmpNE(in1, in2); break; + default: FAIL() << "no such compare operation type for matrix and scalar!"; + } + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(BitwisePerfTest, TestPerformance) +{ + bitwiseOp opType = get<0>(GetParam()); + cv::Size sz = get<1>(GetParam()); + MatType type = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatsRandU(type, sz, type, false); + + // G-API code & corresponding OpenCV code //////////////////////////////// + cv::GMat in1, in2, out; + switch (opType) + { + case AND: + { + out = cv::gapi::bitwise_and(in1, in2); + cv::bitwise_and(in_mat1, in_mat2, out_mat_ocv); + break; + } + case OR: + { + out = cv::gapi::bitwise_or(in1, in2); + cv::bitwise_or(in_mat1, in_mat2, out_mat_ocv); + break; + } + case XOR: + { + out = cv::gapi::bitwise_xor(in1, in2); + cv::bitwise_xor(in_mat1, in_mat2, out_mat_ocv); + break; + } + default: + { + FAIL() << "no such bitwise operation type!"; + } + } + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(BitwiseNotPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatrixRandU(type, sz_in, type, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::bitwise_not(in_mat1, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in, out; + out = cv::gapi::bitwise_not(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(SelectPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandU(type, sz_in, type, false); + cv::Mat in_mask(sz_in, CV_8UC1); + cv::randu(in_mask, cv::Scalar::all(0), cv::Scalar::all(255)); + + // OpenCV code /////////////////////////////////////////////////////////// + in_mat2.copyTo(out_mat_ocv); + in_mat1.copyTo(out_mat_ocv, in_mask); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, in3, out; + out = cv::gapi::select(in1, in2, in3); + cv::GComputation c(GIn(in1, in2, in3), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2, in_mask), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2, in_mask), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(MinPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + + initMatsRandU(type, sz_in, type, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::min(in_mat1, in_mat2, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out; + out = cv::gapi::min(in1, in2); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(MaxPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + + initMatsRandU(type, sz_in, type, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::max(in_mat1, in_mat2, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out; + out = cv::gapi::max(in1, in2); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(AbsDiffPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + + initMatsRandU(type, sz_in, type, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::absdiff(in_mat1, in_mat2, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, out; + out = cv::gapi::absDiff(in1, in2); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(AbsDiffCPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + + initMatsRandU(type, sz_in, type, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::absdiff(in_mat1, sc, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar sc1; + out = cv::gapi::absDiffC(in1, sc1); + cv::GComputation c(cv::GIn(in1, sc1), cv::GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, sc), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(SumPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + + initMatrixRandU(type, sz_in, false); + cv::Scalar out_sum; + cv::Scalar out_sum_ocv; + + // OpenCV code /////////////////////////////////////////////////////////// + out_sum_ocv = cv::sum(in_mat1); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::sum(in); + cv::GComputation c(cv::GIn(in), cv::GOut(out)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1), cv::gout(out_sum), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_sum), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(out_sum[0], out_sum_ocv[0]); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(AddWeightedPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int dtype = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + auto& rng = cv::theRNG(); + double alpha = rng.uniform(0.0, 1.0); + double beta = rng.uniform(0.0, 1.0); + double gamma = rng.uniform(0.0, 1.0); + initMatsRandU(type, sz_in, dtype, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::addWeighted(in_mat1, alpha, in_mat2, beta, gamma, out_mat_ocv, dtype); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2; + auto out = cv::gapi::addWeighted(in1, alpha, in2, beta, gamma, dtype); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(NormPerfTest, TestPerformance) +{ + NormTypes opType = get<0>(GetParam()); + cv::Size sz = get<1>(GetParam()); + MatType type = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + + initMatrixRandU(type, sz, type, false); + cv::Scalar out_norm; + cv::Scalar out_norm_ocv; + + // OpenCV code /////////////////////////////////////////////////////////// + out_norm_ocv = cv::norm(in_mat1, opType); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1; + cv::GScalar out; + switch (opType) + { + case NORM_L1: out = cv::gapi::normL1(in1); break; + case NORM_L2: out = cv::gapi::normL2(in1); break; + case NORM_INF: out = cv::gapi::normInf(in1); break; + default: FAIL() << "no such norm operation type!"; + } + cv::GComputation c(GIn(in1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1), gout(out_norm), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1), gout(out_norm), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(out_norm[0], out_norm_ocv[0]); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(IntegralPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + + MatType type_out = (type == CV_8U) ? CV_32SC1 : CV_64FC1; + + + in_mat1 = cv::Mat(sz_in, type); + cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255)); + + cv::Size sz_out = cv::Size(sz_in.width + 1, sz_in.height + 1); + cv::Mat out_mat1(sz_out, type_out); + cv::Mat out_mat_ocv1(sz_out, type_out); + + cv::Mat out_mat2(sz_out, CV_64FC1); + cv::Mat out_mat_ocv2(sz_out, CV_64FC1); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::integral(in_mat1, out_mat_ocv1, out_mat_ocv2); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out1, out2; + std::tie(out1, out2) = cv::gapi::integral(in1, type_out, CV_64FC1); + cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1), cv::gout(out_mat1, out_mat2), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_mat1, out_mat2), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv1 != out_mat1)); + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ThresholdPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int tt = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + cv::Scalar thr = initScalarRandU(50); + cv::Scalar maxval = initScalarRandU(50) + cv::Scalar(50, 50, 50, 50); + initMatrixRandU(type, sz_in, type, false); + cv::Scalar out_scalar; + + // OpenCV code /////////////////////////////////////////////////////////// + cv::threshold(in_mat1, out_mat_ocv, thr.val[0], maxval.val[0], tt); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar th1, mv1; + out = cv::gapi::threshold(in1, th1, mv1, tt); + cv::GComputation c(GIn(in1, th1, mv1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, thr, maxval), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, thr, maxval), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ThresholdOTPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int tt = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + cv::Scalar maxval = initScalarRandU(50) + cv::Scalar(50, 50, 50, 50); + initMatrixRandU(type, sz_in, type, false); + cv::Scalar out_gapi_scalar; + double ocv_res; + + // OpenCV code /////////////////////////////////////////////////////////// + ocv_res = cv::threshold(in_mat1, out_mat_ocv, maxval.val[0], maxval.val[0], tt); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out; + cv::GScalar mv1, scout; + std::tie(out, scout) = cv::gapi::threshold(in1, mv1, tt); + cv::GComputation c(cv::GIn(in1, mv1), cv::GOut(out, scout)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, maxval), gout(out_mat_gapi, out_gapi_scalar), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, maxval), gout(out_mat_gapi, out_gapi_scalar), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + EXPECT_EQ(ocv_res, out_gapi_scalar.val[0]); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(InRangePerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + cv::Scalar thrLow = initScalarRandU(100); + cv::Scalar thrUp = initScalarRandU(100) + cv::Scalar(100, 100, 100, 100); + initMatrixRandU(type, sz_in, type, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::inRange(in_mat1, thrLow, thrUp, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1; + cv::GScalar th1, mv1; + auto out = cv::gapi::inRange(in1, th1, mv1); + cv::GComputation c(GIn(in1, th1, mv1), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, thrLow, thrUp), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, thrLow, thrUp), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Split3PerfTest, TestPerformance) +{ + Size sz_in = get<0>(GetParam()); + cv::GCompileArgs compile_args = get<1>(GetParam()); + + + initMatrixRandU(CV_8UC3, sz_in, CV_8UC1); + cv::Mat out_mat2 = cv::Mat(sz_in, CV_8UC1); + cv::Mat out_mat3 = cv::Mat(sz_in, CV_8UC1); + cv::Mat out_mat_ocv2 = cv::Mat(sz_in, CV_8UC1); + cv::Mat out_mat_ocv3 = cv::Mat(sz_in, CV_8UC1); + + // OpenCV code /////////////////////////////////////////////////////////// + std::vector out_mats_ocv = { out_mat_ocv, out_mat_ocv2, out_mat_ocv3 }; + cv::split(in_mat1, out_mats_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out1, out2, out3; + std::tie(out1, out2, out3) = cv::gapi::split3(in1); + cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2, out3)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv3 != out_mat3)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Split4PerfTest, TestPerformance) +{ + Size sz_in = get<0>(GetParam()); + cv::GCompileArgs compile_args = get<1>(GetParam()); + + initMatrixRandU(CV_8UC4, sz_in, CV_8UC1); + cv::Mat out_mat2 = cv::Mat(sz_in, CV_8UC1); + cv::Mat out_mat3 = cv::Mat(sz_in, CV_8UC1); + cv::Mat out_mat4 = cv::Mat(sz_in, CV_8UC1); + cv::Mat out_mat_ocv2 = cv::Mat(sz_in, CV_8UC1); + cv::Mat out_mat_ocv3 = cv::Mat(sz_in, CV_8UC1); + cv::Mat out_mat_ocv4 = cv::Mat(sz_in, CV_8UC1); + + // OpenCV code /////////////////////////////////////////////////////////// + std::vector out_mats_ocv = { out_mat_ocv, out_mat_ocv2, out_mat_ocv3, out_mat_ocv4 }; + cv::split(in_mat1, out_mats_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, out1, out2, out3, out4; + std::tie(out1, out2, out3, out4) = cv::gapi::split4(in1); + cv::GComputation c(cv::GIn(in1), cv::GOut(out1, out2, out3, out4)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3, out_mat4), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_mat_gapi, out_mat2, out_mat3, out_mat4), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv2 != out_mat2)); + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv3 != out_mat3)); + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv4 != out_mat4)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Merge3PerfTest, TestPerformance) +{ + Size sz_in = get<0>(GetParam()); + cv::GCompileArgs compile_args = get<1>(GetParam()); + + initMatsRandU(CV_8UC1, sz_in, CV_8UC3); + cv::Mat in_mat3(sz_in, CV_8UC1); + cv::Scalar mean = cv::Scalar::all(127); + cv::Scalar stddev = cv::Scalar::all(40.f); + cv::randn(in_mat3, mean, stddev); + + // OpenCV code /////////////////////////////////////////////////////////// + std::vector in_mats_ocv = { in_mat1, in_mat2, in_mat3 }; + cv::merge(in_mats_ocv, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, in3; + auto out = cv::gapi::merge3(in1, in2, in3); + cv::GComputation c(cv::GIn(in1, in2, in3), cv::GOut(out)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1, in_mat2, in_mat3), cv::gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1, in_mat2, in_mat3), cv::gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Merge4PerfTest, TestPerformance) +{ + Size sz_in = get<0>(GetParam()); + cv::GCompileArgs compile_args = get<1>(GetParam()); + + initMatsRandU(CV_8UC1, sz_in, CV_8UC3); + cv::Mat in_mat3(sz_in, CV_8UC1); + cv::Mat in_mat4(sz_in, CV_8UC1); + cv::Scalar mean = cv::Scalar::all(127); + cv::Scalar stddev = cv::Scalar::all(40.f); + cv::randn(in_mat3, mean, stddev); + cv::randn(in_mat4, mean, stddev); + + // OpenCV code /////////////////////////////////////////////////////////// + std::vector in_mats_ocv = { in_mat1, in_mat2, in_mat3, in_mat4 }; + cv::merge(in_mats_ocv, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2, in3, in4; + auto out = cv::gapi::merge4(in1, in2, in3, in4); + cv::GComputation c(cv::GIn(in1, in2, in3, in4), cv::GOut(out)); + + // Warm-up graph engine: + c.apply(cv::gin(in_mat1, in_mat2, in_mat3, in_mat4), cv::gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1, in_mat2, in_mat3, in_mat4), cv::gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(RemapPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatrixRandU(type, sz_in, type, false); + cv::Mat in_map1(sz_in, CV_16SC2); + cv::Mat in_map2 = cv::Mat(); + cv::randu(in_map1, cv::Scalar::all(0), cv::Scalar::all(255)); + cv::Scalar bv = cv::Scalar(); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::remap(in_mat1, out_mat_ocv, in_map1, in_map2, cv::INTER_NEAREST, cv::BORDER_REPLICATE, bv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1; + auto out = cv::gapi::remap(in1, in_map1, in_map2, cv::INTER_NEAREST, cv::BORDER_REPLICATE, bv); + cv::GComputation c(in1, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(FlipPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + int flipCode = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatrixRandU(type, sz_in, type, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::flip(in_mat1, out_mat_ocv, flipCode); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::flip(in, flipCode); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(CropPerfTest, TestPerformance) +{ + cv::Size sz_in = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::Rect rect_to = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatrixRandU(type, sz_in, type, false); + cv::Size sz_out = cv::Size(rect_to.width, rect_to.height); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::Mat(in_mat1, rect_to).copyTo(out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::crop(in, rect_to); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_out); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ConcatHorPerfTest, TestPerformance) +{ + cv::Size sz_out = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + int wpart = sz_out.width / 4; + + cv::Size sz_in1 = cv::Size(wpart, sz_out.height); + cv::Size sz_in2 = cv::Size(sz_out.width - wpart, sz_out.height); + + in_mat1 = cv::Mat(sz_in1, type); + in_mat2 = cv::Mat(sz_in2, type); + + cv::Scalar mean = cv::Scalar::all(127); + cv::Scalar stddev = cv::Scalar::all(40.f); + + cv::randn(in_mat1, mean, stddev); + cv::randn(in_mat2, mean, stddev); + + out_mat_gapi = cv::Mat(sz_out, type); + out_mat_ocv = cv::Mat(sz_out, type); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::hconcat(in_mat1, in_mat2, out_mat_ocv); + + // G-API code //////////////////////////////////////////////////////////// + cv::GMat in1, in2; + auto out = cv::gapi::concatHor(in1, in2); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ConcatHorVecPerfTest, TestPerformance) +{ + cv::Size sz_out = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + int wpart1 = sz_out.width / 3; + int wpart2 = sz_out.width / 2; + + cv::Size sz_in1 = cv::Size(wpart1, sz_out.height); + cv::Size sz_in2 = cv::Size(wpart2, sz_out.height); + cv::Size sz_in3 = cv::Size(sz_out.width - wpart1 - wpart2, sz_out.height); + + in_mat1 = cv::Mat(sz_in1, type); + in_mat2 = cv::Mat(sz_in2, type); + cv::Mat in_mat3(sz_in3, type); + + cv::Scalar mean = cv::Scalar::all(127); + cv::Scalar stddev = cv::Scalar::all(40.f); + + cv::randn(in_mat1, mean, stddev); + cv::randn(in_mat2, mean, stddev); + cv::randn(in_mat3, mean, stddev); + + out_mat_gapi = cv::Mat(sz_out, type); + out_mat_ocv = cv::Mat(sz_out, type); + + std::vector cvmats = { in_mat1, in_mat2, in_mat3 }; + + // OpenCV code /////////////////////////////////////////////////////////// + cv::hconcat(cvmats, out_mat_ocv); + + // G-API code ////////////////////////////////////////////////////////////// + std::vector mats(3); + auto out = cv::gapi::concatHor(mats); + cv::GComputation c({ mats[0], mats[1], mats[2] }, { out }); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ConcatVertPerfTest, TestPerformance) +{ + cv::Size sz_out = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + int hpart = sz_out.height * 2 / 3; + + cv::Size sz_in1 = cv::Size(sz_out.width, hpart); + cv::Size sz_in2 = cv::Size(sz_out.width, sz_out.height - hpart); + + in_mat1 = cv::Mat(sz_in1, type); + in_mat2 = cv::Mat(sz_in2, type); + + cv::Scalar mean = cv::Scalar::all(127); + cv::Scalar stddev = cv::Scalar::all(40.f); + + cv::randn(in_mat1, mean, stddev); + cv::randn(in_mat2, mean, stddev); + + out_mat_gapi = cv::Mat(sz_out, type); + out_mat_ocv = cv::Mat(sz_out, type); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::vconcat(in_mat1, in_mat2, out_mat_ocv); + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in1, in2; + auto out = cv::gapi::concatVert(in1, in2); + cv::GComputation c(GIn(in1, in2), GOut(out)); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ConcatVertVecPerfTest, TestPerformance) +{ + cv::Size sz_out = get<0>(GetParam()); + MatType type = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + int hpart1 = sz_out.height * 2 / 5; + int hpart2 = sz_out.height / 5; + + cv::Size sz_in1 = cv::Size(sz_out.width, hpart1); + cv::Size sz_in2 = cv::Size(sz_out.width, hpart2); + cv::Size sz_in3 = cv::Size(sz_out.width, sz_out.height - hpart1 - hpart2); + + in_mat1 = cv::Mat(sz_in1, type); + in_mat2 = cv::Mat(sz_in2, type); + cv::Mat in_mat3(sz_in3, type); + + cv::Scalar mean = cv::Scalar::all(127); + cv::Scalar stddev = cv::Scalar::all(40.f); + + cv::randn(in_mat1, mean, stddev); + cv::randn(in_mat2, mean, stddev); + cv::randn(in_mat3, mean, stddev); + + out_mat_gapi = cv::Mat(sz_out, type); + out_mat_ocv = cv::Mat(sz_out, type); + + std::vector cvmats = { in_mat1, in_mat2, in_mat3 }; + + // OpenCV code /////////////////////////////////////////////////////////// + cv::vconcat(cvmats, out_mat_ocv); + + // G-API code ////////////////////////////////////////////////////////////// + std::vector mats(3); + auto out = cv::gapi::concatVert(mats); + cv::GComputation c({ mats[0], mats[1], mats[2] }, { out }); + + // Warm-up graph engine: + c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(gin(in_mat1, in_mat2, in_mat3), gout(out_mat_gapi), std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(LUTPerfTest, TestPerformance) +{ + MatType type_mat = get<0>(GetParam()); + MatType type_lut = get<1>(GetParam()); + MatType type_out = CV_MAKETYPE(CV_MAT_DEPTH(type_lut), CV_MAT_CN(type_mat)); + cv::Size sz_in = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + + initMatrixRandU(type_mat, sz_in, type_out); + cv::Size sz_lut = cv::Size(1, 256); + cv::Mat in_lut(sz_lut, type_lut); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::LUT(in_mat1, in_lut, out_mat_ocv); + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::LUT(in, in_lut); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ConvertToPerfTest, TestPerformance) +{ + MatType type_mat = get<0>(GetParam()); + int depth_to = get<1>(GetParam()); + cv::Size sz_in = get<2>(GetParam()); + cv::GCompileArgs compile_args = get<3>(GetParam()); + MatType type_out = CV_MAKETYPE(depth_to, CV_MAT_CN(type_mat)); + + initMatrixRandU(type_mat, sz_in, type_out); + + // OpenCV code /////////////////////////////////////////////////////////// + in_mat1.convertTo(out_mat_ocv, depth_to); + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::convertTo(in, depth_to); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + EXPECT_EQ(0, cv::countNonZero(out_mat_ocv != out_mat_gapi)); + EXPECT_EQ(out_mat_gapi.size(), sz_in); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ResizePerfTest, TestPerformance) +{ + MatType type = get<0>(GetParam()); + int interp = get<1>(GetParam()); + cv::Size sz_in = get<2>(GetParam()); + cv::Size sz_out = get<3>(GetParam()); + double tolerance = get<4>(GetParam()); + cv::GCompileArgs compile_args = get<5>(GetParam()); + + in_mat1 = cv::Mat(sz_in, type); + cv::Scalar mean = cv::Scalar::all(127); + cv::Scalar stddev = cv::Scalar::all(40.f); + cv::randn(in_mat1, mean, stddev); + out_mat_gapi = cv::Mat(sz_out, type); + out_mat_ocv = cv::Mat(sz_out, type); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::resize(in_mat1, out_mat_ocv, sz_out, 0.0, 0.0, interp); + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::resize(in, sz_out, 0.0, 0.0, interp); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + cv::Mat absDiff; + cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff); + EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ResizeFxFyPerfTest, TestPerformance) +{ + MatType type = get<0>(GetParam()); + int interp = get<1>(GetParam()); + cv::Size sz_in = get<2>(GetParam()); + double fx = get<3>(GetParam()); + double fy = get<4>(GetParam()); + double tolerance = get<5>(GetParam()); + cv::GCompileArgs compile_args = get<6>(GetParam()); + + in_mat1 = cv::Mat(sz_in, type); + cv::Scalar mean = cv::Scalar::all(127); + cv::Scalar stddev = cv::Scalar::all(40.f); + cv::randn(in_mat1, mean, stddev); + cv::Size sz_out = cv::Size(saturate_cast(sz_in.width *fx), saturate_cast(sz_in.height*fy)); + out_mat_gapi = cv::Mat(sz_out, type); + out_mat_ocv = cv::Mat(sz_out, type); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::resize(in_mat1, out_mat_ocv, sz_out, fx, fy, interp); + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::resize(in, sz_out, fx, fy, interp); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison //////////////////////////////////////////////////////////// + cv::Mat absDiff; + cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff); + EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance)); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +} +#endif // OPENCV_GAPI_CORE_PERF_TESTS_INL_HPP diff --git a/modules/gapi/perf/common/gapi_imgproc_perf_tests.cpp b/modules/gapi/perf/common/gapi_imgproc_perf_tests.cpp new file mode 100644 index 0000000000..5a2ffb88a2 --- /dev/null +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests.cpp @@ -0,0 +1,9 @@ +// This file is part of OpenCV project. +// 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 + + +#include "perf_precomp.hpp" +#include "gapi_imgproc_perf_tests_inl.hpp" diff --git a/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp b/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp index 3d94480e1f..750c0692c8 100644 --- a/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp @@ -5,6 +5,11 @@ // Copyright (C) 2018 Intel Corporation +#ifndef OPENCV_GAPI_IMGPROC_PERF_TESTS_HPP +#define OPENCV_GAPI_IMGPROC_PERF_TESTS_HPP + + + #include "../../test/common/gapi_tests_common.hpp" #include "opencv2/gapi/imgproc.hpp" @@ -13,870 +18,29 @@ namespace opencv_test using namespace perf; -//------------------------------------------------------------------------------ - -class SepFilterPerfTest : public TestPerfParams> {}; -PERF_TEST_P_(SepFilterPerfTest, TestPerformance) -{ - MatType type = 0; - int kernSize = 0, dtype = 0; - cv::Size sz; - std::tie(type, kernSize, sz, dtype) = GetParam(); - - cv::Mat kernelX(kernSize, 1, CV_32F); - cv::Mat kernelY(kernSize, 1, CV_32F); - randu(kernelX, -1, 1); - randu(kernelY, -1, 1); - initMatsRandN(type, sz, dtype, false); - - cv::Point anchor = cv::Point(-1, -1); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY ); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::sepFilter(in, dtype, kernelX, kernelY, anchor, cv::Scalar() ); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); -} - -//------------------------------------------------------------------------------ - -class Filter2DPerfTest : public TestPerfParams> {}; -PERF_TEST_P_(Filter2DPerfTest, TestPerformance) -{ - MatType type = 0; - int kernSize = 0, borderType = 0, dtype = 0; - cv::Size sz; - std::tie(type, kernSize, sz, borderType, dtype) = GetParam(); - - initMatsRandN(type, sz, dtype, false); - - cv::Point anchor = {-1, -1}; - double delta = 0; - - cv::Mat kernel = cv::Mat(kernSize, kernSize, CV_32FC1 ); - cv::Scalar kernMean = cv::Scalar::all(1.0); - cv::Scalar kernStddev = cv::Scalar::all(2.0/3); - randn(kernel, kernMean, kernStddev); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::filter2D(in, dtype, kernel, anchor, delta, borderType); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class BoxFilterPerfTest : public TestPerfParams> {}; -PERF_TEST_P_(BoxFilterPerfTest, TestPerformance) -{ - MatType type = 0; - int filterSize = 0, borderType = 0, dtype = 0; - cv::Size sz; - double tolerance = 0.0; - std::tie(type, filterSize, sz, borderType, dtype, tolerance) = GetParam(); - - initMatsRandN(type, sz, dtype, false); - - cv::Point anchor = {-1, -1}; - bool normalize = true; - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::boxFilter(in, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - cv::Mat absDiff; - cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff); - EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class BlurPerfTest : public TestPerfParams> {}; -PERF_TEST_P_(BlurPerfTest, TestPerformance) -{ - MatType type = 0; - int filterSize = 0, borderType = 0; - cv::Size sz; - double tolerance = 0.0; - std::tie(type, filterSize, sz, borderType, tolerance) = GetParam(); - - initMatsRandN(type, sz, type, false); - - cv::Point anchor = {-1, -1}; - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::blur(in, cv::Size(filterSize, filterSize), anchor, borderType); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - cv::Mat absDiff; - cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff); - EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class GaussianBlurPerfTest : public TestPerfParams> {}; -PERF_TEST_P_(GaussianBlurPerfTest, TestPerformance) -{ - MatType type = 0; - int kernSize = 0; - cv::Size sz; - std::tie(type, kernSize, sz) = GetParam(); - - cv::Size kSize = cv::Size(kernSize, kernSize); - auto& rng = cv::theRNG(); - double sigmaX = rng(); - initMatsRandN(type, sz, type, false); - - // OpenCV code /////////////////////////////////////////////////////////// - cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX); - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::gaussianBlur(in, kSize, sigmaX); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison //////////////////////////////////////////////////////////// - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); -} - -//------------------------------------------------------------------------------ - -class MedianBlurPerfTest : public TestPerfParams> {}; -PERF_TEST_P_(MedianBlurPerfTest, TestPerformance) -{ - MatType type = 0; - int kernSize = 0; - cv::Size sz; - std::tie(type, kernSize, sz) = GetParam(); - - initMatsRandN(type, sz, type, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::medianBlur(in_mat1, out_mat_ocv, kernSize); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::medianBlur(in, kernSize); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class ErodePerfTest : public TestPerfParams> {}; -PERF_TEST_P_(ErodePerfTest, TestPerformance) -{ - MatType type = 0; - int kernSize = 0, kernType = 0; - cv::Size sz; - std::tie(type, kernSize, sz, kernType) = GetParam(); - - initMatsRandN(type, sz, type, false); - - cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize)); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::erode(in_mat1, out_mat_ocv, kernel); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::erode(in, kernel); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class Erode3x3PerfTest : public TestPerfParams> {}; -PERF_TEST_P_(Erode3x3PerfTest, TestPerformance) -{ - MatType type = 0; - int numIters = 0; - cv::Size sz; - std::tie(type, sz, numIters) = GetParam(); - - initMatsRandN(type, sz, type, false); - - cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3)); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::erode3x3(in, numIters); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class DilatePerfTest : public TestPerfParams> {}; -PERF_TEST_P_(DilatePerfTest, TestPerformance) -{ - MatType type = 0; - int kernSize = 0, kernType = 0; - cv::Size sz; - std::tie(type, kernSize, sz, kernType) = GetParam(); - - initMatsRandN(type, sz, type, false); - - cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize)); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::dilate(in_mat1, out_mat_ocv, kernel); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::dilate(in, kernel); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class Dilate3x3PerfTest : public TestPerfParams> {}; -PERF_TEST_P_(Dilate3x3PerfTest, TestPerformance) -{ - MatType type = 0; - int numIters = 0; - cv::Size sz; - std::tie(type, sz, numIters) = GetParam(); - - initMatsRandN(type, sz, type, false); - - cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3)); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::dilate3x3(in, numIters); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class SobelPerfTest : public TestPerfParams> {}; -PERF_TEST_P_(SobelPerfTest, TestPerformance) -{ - MatType type = 0; - int kernSize = 0, dtype = 0, dx = 0, dy = 0; - cv::Size sz; - std::tie(type, kernSize, sz, dtype, dx, dy) = GetParam(); - - initMatsRandN(type, sz, dtype, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::Sobel(in, dtype, dx, dy, kernSize ); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class CannyPerfTest : public TestPerfParams> {}; -PERF_TEST_P_(CannyPerfTest, TestPerformance) -{ - MatType type; - int apSize = 0; - double thrLow = 0.0, thrUp = 0.0; - cv::Size sz; - bool l2gr = false; - std::tie(type, sz, thrLow, thrUp, apSize, l2gr) = GetParam(); - - initMatsRandN(type, sz, CV_8UC1, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::Canny(in, thrLow, thrUp, apSize, l2gr); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class EqHistPerfTest : public TestPerfParams {}; -PERF_TEST_P_(EqHistPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - - initMatsRandN(CV_8UC1, sz, CV_8UC1, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::equalizeHist(in_mat1, out_mat_ocv); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::equalizeHist(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class RGB2GrayPerfTest : public TestPerfParams {}; -PERF_TEST_P_(RGB2GrayPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - - initMatsRandN(CV_8UC3, sz, CV_8UC1, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::RGB2Gray(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class BGR2GrayPerfTest : public TestPerfParams {}; -PERF_TEST_P_(BGR2GrayPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - - initMatsRandN(CV_8UC3, sz, CV_8UC1, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::BGR2Gray(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class RGB2YUVPerfTest : public TestPerfParams {}; -PERF_TEST_P_(RGB2YUVPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - - initMatsRandN(CV_8UC3, sz, CV_8UC3, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::RGB2YUV(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class YUV2RGBPerfTest : public TestPerfParams {}; -PERF_TEST_P_(YUV2RGBPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - - initMatsRandN(CV_8UC3, sz, CV_8UC3, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::YUV2RGB(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class RGB2LabPerfTest : public TestPerfParams {}; -PERF_TEST_P_(RGB2LabPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - - initMatsRandN(CV_8UC3, sz, CV_8UC3, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::RGB2Lab(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class BGR2LUVPerfTest : public TestPerfParams {}; -PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - - initMatsRandN(CV_8UC3, sz, CV_8UC3, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::BGR2LUV(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class LUV2BGRPerfTest : public TestPerfParams {}; -PERF_TEST_P_(LUV2BGRPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - - initMatsRandN(CV_8UC3, sz, CV_8UC3, false); - - // OpenCV code ///////////////////////////////////////////////////////////// - { - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::LUV2BGR(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - } - - SANITY_CHECK_NOTHING(); - -} - -//------------------------------------------------------------------------------ - -class BGR2YUVPerfTest : public TestPerfParams {}; -PERF_TEST_P_(BGR2YUVPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - initMatsRandN(CV_8UC3, sz, CV_8UC3, false); - - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV); - - cv::GMat in; - auto out = cv::gapi::BGR2YUV(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); -} - -//------------------------------------------------------------------------------ - -class YUV2BGRPerfTest : public TestPerfParams {}; -PERF_TEST_P_(YUV2BGRPerfTest, TestPerformance) -{ - cv::Size sz = GetParam(); - initMatsRandN(CV_8UC3, sz, CV_8UC3, false); - - cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR); - - cv::GMat in; - auto out = cv::gapi::YUV2BGR(in); - cv::GComputation c(in, out); - - // Warm-up graph engine: - c.apply(in_mat1, out_mat_gapi); - - TEST_CYCLE() - { - c.apply(in_mat1, out_mat_gapi); - } - - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), sz); - - SANITY_CHECK_NOTHING(); -} - -//------------------------------------------------------------------------------ - -} + //------------------------------------------------------------------------------ + +class SepFilterPerfTest : public TestPerfParams> {}; +class Filter2DPerfTest : public TestPerfParams> {}; +class BoxFilterPerfTest : public TestPerfParams> {}; +class BlurPerfTest : public TestPerfParams> {}; +class GaussianBlurPerfTest : public TestPerfParams> {}; +class MedianBlurPerfTest : public TestPerfParams> {}; +class ErodePerfTest : public TestPerfParams> {}; +class Erode3x3PerfTest : public TestPerfParams> {}; +class DilatePerfTest : public TestPerfParams> {}; +class Dilate3x3PerfTest : public TestPerfParams> {}; +class SobelPerfTest : public TestPerfParams> {}; +class CannyPerfTest : public TestPerfParams> {}; +class EqHistPerfTest : public TestPerfParams> {}; +class RGB2GrayPerfTest : public TestPerfParams> {}; +class BGR2GrayPerfTest : public TestPerfParams> {}; +class RGB2YUVPerfTest : public TestPerfParams> {}; +class YUV2RGBPerfTest : public TestPerfParams> {}; +class RGB2LabPerfTest : public TestPerfParams> {}; +class BGR2LUVPerfTest : public TestPerfParams> {}; +class LUV2BGRPerfTest : public TestPerfParams> {}; +class BGR2YUVPerfTest : public TestPerfParams> {}; +class YUV2BGRPerfTest : public TestPerfParams> {}; +} +#endif //OPENCV_GAPI_IMGPROC_PERF_TESTS_HPP diff --git a/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp b/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp new file mode 100644 index 0000000000..671f54e962 --- /dev/null +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp @@ -0,0 +1,910 @@ +// This file is part of OpenCV project. +// 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 + + +#ifndef OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP +#define OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP + + +#include + +#include "gapi_imgproc_perf_tests.hpp" + +namespace opencv_test +{ + + using namespace perf; + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(SepFilterPerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int kernSize = 0, dtype = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, kernSize, sz, dtype, compile_args) = GetParam(); + + cv::Mat kernelX(kernSize, 1, CV_32F); + cv::Mat kernelY(kernSize, 1, CV_32F); + randu(kernelX, -1, 1); + randu(kernelY, -1, 1); + initMatsRandN(type, sz, dtype, false); + + cv::Point anchor = cv::Point(-1, -1); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::sepFilter2D(in_mat1, out_mat_ocv, dtype, kernelX, kernelY ); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::sepFilter(in, dtype, kernelX, kernelY, anchor, cv::Scalar() ); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Filter2DPerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int kernSize = 0, borderType = 0, dtype = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, kernSize, sz, borderType, dtype, compile_args) = GetParam(); + + initMatsRandN(type, sz, dtype, false); + + cv::Point anchor = {-1, -1}; + double delta = 0; + + cv::Mat kernel = cv::Mat(kernSize, kernSize, CV_32FC1 ); + cv::Scalar kernMean = cv::Scalar::all(1.0); + cv::Scalar kernStddev = cv::Scalar::all(2.0/3); + randn(kernel, kernMean, kernStddev); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::filter2D(in_mat1, out_mat_ocv, dtype, kernel, anchor, delta, borderType); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::filter2D(in, dtype, kernel, anchor, delta, borderType); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(BoxFilterPerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int filterSize = 0, borderType = 0, dtype = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, filterSize, sz, borderType, dtype, compile_args) = GetParam(); + + initMatsRandN(type, sz, dtype, false); + + cv::Point anchor = {-1, -1}; + bool normalize = true; + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::boxFilter(in_mat1, out_mat_ocv, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::boxFilter(in, dtype, cv::Size(filterSize, filterSize), anchor, normalize, borderType); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(BlurPerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int filterSize = 0, borderType = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, filterSize, sz, borderType, compile_args) = GetParam(); + + initMatsRandN(type, sz, type, false); + + cv::Point anchor = {-1, -1}; + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::blur(in_mat1, out_mat_ocv, cv::Size(filterSize, filterSize), anchor, borderType); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::blur(in, cv::Size(filterSize, filterSize), anchor, borderType); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(GaussianBlurPerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int kernSize = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, kernSize, sz, compile_args) = GetParam(); + + cv::Size kSize = cv::Size(kernSize, kernSize); + auto& rng = cv::theRNG(); + double sigmaX = rng(); + initMatsRandN(type, sz, type, false); + + // OpenCV code /////////////////////////////////////////////////////////// + cv::GaussianBlur(in_mat1, out_mat_ocv, kSize, sigmaX); + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::gaussianBlur(in, kSize, sigmaX); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(MedianBlurPerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int kernSize = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, kernSize, sz, compile_args) = GetParam(); + + initMatsRandN(type, sz, type, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::medianBlur(in_mat1, out_mat_ocv, kernSize); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::medianBlur(in, kernSize); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(ErodePerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int kernSize = 0, kernType = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam(); + + initMatsRandN(type, sz, type, false); + + cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize)); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::erode(in_mat1, out_mat_ocv, kernel); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::erode(in, kernel); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Erode3x3PerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int numIters = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, sz, numIters, compile_args) = GetParam(); + + initMatsRandN(type, sz, type, false); + + cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3)); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::erode(in_mat1, out_mat_ocv, kernel, cv::Point(-1, -1), numIters); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::erode3x3(in, numIters); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(DilatePerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int kernSize = 0, kernType = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, kernSize, sz, kernType, compile_args) = GetParam(); + + initMatsRandN(type, sz, type, false); + + cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize)); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::dilate(in_mat1, out_mat_ocv, kernel); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::dilate(in, kernel); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(Dilate3x3PerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int numIters = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, sz, numIters, compile_args) = GetParam(); + + initMatsRandN(type, sz, type, false); + + cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3, 3)); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::dilate(in_mat1, out_mat_ocv, kernel, cv::Point(-1,-1), numIters); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::dilate3x3(in, numIters); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(SobelPerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type = 0; + int kernSize = 0, dtype = 0, dx = 0, dy = 0; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, compile_args) = GetParam(); + + initMatsRandN(type, sz, dtype, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::Sobel(in_mat1, out_mat_ocv, dtype, dx, dy, kernSize); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::Sobel(in, dtype, dx, dy, kernSize ); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(CannyPerfTest, TestPerformance) +{ + compare_f cmpF; + MatType type; + int apSize = 0; + double thrLow = 0.0, thrUp = 0.0; + cv::Size sz; + bool l2gr = false; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, compile_args) = GetParam(); + + initMatsRandN(type, sz, CV_8UC1, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::Canny(in_mat1, out_mat_ocv, thrLow, thrUp, apSize, l2gr); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::Canny(in, thrLow, thrUp, apSize, l2gr); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(EqHistPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC1, sz, CV_8UC1, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::equalizeHist(in_mat1, out_mat_ocv); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::equalizeHist(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(RGB2GrayPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC1, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2GRAY); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::RGB2Gray(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(BGR2GrayPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC1, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2GRAY); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::BGR2Gray(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(RGB2YUVPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC3, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::RGB2YUV(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(YUV2RGBPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC3, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::YUV2RGB(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(RGB2LabPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC3, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2Lab); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::RGB2Lab(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(BGR2LUVPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC3, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2Luv); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::BGR2LUV(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(LUV2BGRPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC3, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_Luv2BGR); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::LUV2BGR(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + } + + SANITY_CHECK_NOTHING(); + +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(BGR2YUVPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC3, false); + + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV); + + cv::GMat in; + auto out = cv::gapi::BGR2YUV(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(YUV2BGRPerfTest, TestPerformance) +{ + compare_f cmpF = get<0>(GetParam()); + Size sz = get<1>(GetParam()); + cv::GCompileArgs compile_args = get<2>(GetParam()); + + initMatsRandN(CV_8UC3, sz, CV_8UC3, false); + + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR); + + cv::GMat in; + auto out = cv::gapi::YUV2BGR(in); + cv::GComputation c(in, out); + + // Warm-up graph engine: + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + + TEST_CYCLE() + { + c.apply(in_mat1, out_mat_gapi, std::move(compile_args)); + } + + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), sz); + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +} +#endif //OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP 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 52e17b250c..aa358783b9 100644 --- a/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp +++ b/modules/gapi/perf/cpu/gapi_core_perf_tests_cpu.cpp @@ -7,214 +7,271 @@ #include "../perf_precomp.hpp" #include "../common/gapi_core_perf_tests.hpp" +#include "opencv2/gapi/cpu/core.hpp" + +#define CORE_CPU cv::gapi::core::cpu::kernels() namespace opencv_test { - INSTANTIATE_TEST_CASE_P(AddPerfTestCPU, AddPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(AddCPerfTestCPU, AddCPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(SubPerfTestCPU, SubPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(SubCPerfTestCPU, SubCPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(SubRCPerfTestCPU, SubRCPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(MulPerfTestCPU, MulPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(MulDoublePerfTestCPU, MulDoublePerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(MulCPerfTestCPU, MulCPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(DivPerfTestCPU, DivPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(DivCPerfTestCPU, DivCPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(DivRCPerfTestCPU, DivRCPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(MaskPerfTestCPU, MaskPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_16UC1, CV_16SC1))); - - INSTANTIATE_TEST_CASE_P(MeanPerfTestCPU, MeanPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(Polar2CartPerfTestCPU, Polar2CartPerfTest, Values( szSmall128, szVGA, sz720p, sz1080p )); - - INSTANTIATE_TEST_CASE_P(Cart2PolarPerfTestCPU, Cart2PolarPerfTest, Values( szSmall128, szVGA, sz720p, sz1080p )); - - INSTANTIATE_TEST_CASE_P(CmpPerfTestCPU, CmpPerfTest, - Combine(Values(CMP_EQ, CMP_GE, CMP_NE, CMP_GT, CMP_LT, CMP_LE), - Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(CmpWithScalarPerfTestCPU, CmpWithScalarPerfTest, - Combine(Values(CMP_EQ, CMP_GE, CMP_NE, CMP_GT, CMP_LT, CMP_LE), - Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(BitwisePerfTestCPU, BitwisePerfTest, - Combine(Values(AND, OR, XOR), - Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1))); - - INSTANTIATE_TEST_CASE_P(BitwiseNotPerfTestCPU, BitwiseNotPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(SelectPerfTestCPU, SelectPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(MinPerfTestCPU, MinPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(MaxPerfTestCPU, MaxPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(AbsDiffPerfTestCPU, AbsDiffPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(AbsDiffCPerfTestCPU, AbsDiffCPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(SumPerfTestCPU, SumPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(AddWeightedPerfTestCPU, AddWeightedPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values( -1, CV_8U, CV_16U, CV_32F ))); - - INSTANTIATE_TEST_CASE_P(NormPerfTestCPU, NormPerfTest, - Combine(Values(NORM_INF, NORM_L1, NORM_L2), - Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(IntegralPerfTestCPU, IntegralPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(ThresholdPerfTestCPU, ThresholdPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values(cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV))); - - INSTANTIATE_TEST_CASE_P(ThresholdPerfTestCPU, ThresholdOTPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1 ), - Values(cv::THRESH_OTSU, cv::THRESH_TRIANGLE))); - - INSTANTIATE_TEST_CASE_P(InRangePerfTestCPU, InRangePerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1 ))); - - INSTANTIATE_TEST_CASE_P(Split3PerfTestCPU, Split3PerfTest, Values( szSmall128, szVGA, sz720p, sz1080p )); - - INSTANTIATE_TEST_CASE_P(Split4PerfTestCPU, Split4PerfTest, Values( szSmall128, szVGA, sz720p, sz1080p )); - - INSTANTIATE_TEST_CASE_P(Merge3PerfTestCPU, Merge3PerfTest, Values( szSmall128, szVGA, sz720p, sz1080p )); - - INSTANTIATE_TEST_CASE_P(Merge4PerfTestCPU, Merge4PerfTest, Values( szSmall128, szVGA, sz720p, sz1080p )); - - INSTANTIATE_TEST_CASE_P(RemapPerfTestCPU, RemapPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(FlipPerfTestCPU, FlipPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values(0,1,-1))); - - INSTANTIATE_TEST_CASE_P(CropPerfTestCPU, CropPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ), - Values(cv::Rect(10, 8, 20, 35), cv::Rect(4, 10, 37, 50)))); - - INSTANTIATE_TEST_CASE_P(ConcatHorPerfTestCPU, ConcatHorPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(ConcatHorVecPerfTestCPU, ConcatHorVecPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(ConcatVertPerfTestCPU, ConcatVertPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(ConcatVertVecPerfTestCPU, ConcatVertVecPerfTest, - Combine(Values( szSmall128, szVGA, sz720p, sz1080p ), - Values( CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1 ))); - - INSTANTIATE_TEST_CASE_P(LUTPerfTestCPU, LUTPerfTest, - Combine(Values(CV_8UC1, CV_8UC3), - Values(CV_8UC1), - Values( szSmall128, szVGA, sz720p, sz1080p ))); - - INSTANTIATE_TEST_CASE_P(LUTPerfTestCustomCPU, LUTPerfTest, - Combine(Values(CV_8UC3), - Values(CV_8UC3), - Values( szSmall128, szVGA, sz720p, sz1080p ))); - - INSTANTIATE_TEST_CASE_P(ConvertToPerfTestCPU, ConvertToPerfTest, - Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1), - Values(CV_8U, CV_16U, CV_16S, CV_32F), - Values( szSmall128, szVGA, sz720p, sz1080p ))); - - INSTANTIATE_TEST_CASE_P(ResizePerfTestCPU, ResizePerfTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), - Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA), - Values( szSmall128, szVGA, sz720p, sz1080p ), - Values(cv::Size(64,64), - cv::Size(30,30)), - Values(0.0))); - - INSTANTIATE_TEST_CASE_P(ResizeFxFyPerfTestCPU, ResizeFxFyPerfTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), - Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA), - Values( szSmall128, szVGA, sz720p, sz1080p ), - Values(0.5, 0.1), - Values(0.5, 0.1), - Values(0.0))); + INSTANTIATE_TEST_CASE_P(AddPerfTestCPU, AddPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(AddCPerfTestCPU, AddCPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(SubPerfTestCPU, SubPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(SubCPerfTestCPU, SubCPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(SubRCPerfTestCPU, SubRCPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(MulPerfTestCPU, MulPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(MulDoublePerfTestCPU, MulDoublePerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(MulCPerfTestCPU, MulCPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(DivPerfTestCPU, DivPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(DivCPerfTestCPU, DivCPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(DivRCPerfTestCPU, DivRCPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(MaskPerfTestCPU, MaskPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_16UC1, CV_16SC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(MeanPerfTestCPU, MeanPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(Polar2CartPerfTestCPU, Polar2CartPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(Cart2PolarPerfTestCPU, Cart2PolarPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(CmpPerfTestCPU, CmpPerfTest, + Combine(Values(CMP_EQ, CMP_GE, CMP_NE, CMP_GT, CMP_LT, CMP_LE), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(CmpWithScalarPerfTestCPU, CmpWithScalarPerfTest, + Combine(Values(CMP_EQ, CMP_GE, CMP_NE, CMP_GT, CMP_LT, CMP_LE), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(BitwisePerfTestCPU, BitwisePerfTest, + Combine(Values(AND, OR, XOR), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(BitwiseNotPerfTestCPU, BitwiseNotPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(SelectPerfTestCPU, SelectPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(MinPerfTestCPU, MinPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(MaxPerfTestCPU, MaxPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(AbsDiffPerfTestCPU, AbsDiffPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(AbsDiffCPerfTestCPU, AbsDiffCPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(SumPerfTestCPU, SumPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(AddWeightedPerfTestCPU, AddWeightedPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(-1, CV_8U, CV_16U, CV_32F), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(NormPerfTestCPU, NormPerfTest, + Combine(Values(NORM_INF, NORM_L1, NORM_L2), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(IntegralPerfTestCPU, IntegralPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(ThresholdPerfTestCPU, ThresholdPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::THRESH_BINARY, cv::THRESH_BINARY_INV, cv::THRESH_TRUNC, cv::THRESH_TOZERO, cv::THRESH_TOZERO_INV), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(ThresholdPerfTestCPU, ThresholdOTPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1), + Values(cv::THRESH_OTSU, cv::THRESH_TRIANGLE), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(InRangePerfTestCPU, InRangePerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(Split3PerfTestCPU, Split3PerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(Split4PerfTestCPU, Split4PerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(Merge3PerfTestCPU, Merge3PerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(Merge4PerfTestCPU, Merge4PerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(RemapPerfTestCPU, RemapPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(FlipPerfTestCPU, FlipPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(0, 1, -1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(CropPerfTestCPU, CropPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::Rect(10, 8, 20, 35), cv::Rect(4, 10, 37, 50)), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(ConcatHorPerfTestCPU, ConcatHorPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(ConcatHorVecPerfTestCPU, ConcatHorVecPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(ConcatVertPerfTestCPU, ConcatVertPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(ConcatVertVecPerfTestCPU, ConcatVertVecPerfTest, + Combine(Values(szSmall128, szVGA, sz720p, sz1080p), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(LUTPerfTestCPU, LUTPerfTest, + Combine(Values(CV_8UC1, CV_8UC3), + Values(CV_8UC1), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(LUTPerfTestCustomCPU, LUTPerfTest, + Combine(Values(CV_8UC3), + Values(CV_8UC3), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + + INSTANTIATE_TEST_CASE_P(ConvertToPerfTestCPU, ConvertToPerfTest, + Combine(Values(CV_8UC3, CV_8UC1, CV_16UC1, CV_32FC1), + Values(CV_8U, CV_16U, CV_16S, CV_32F), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(ResizePerfTestCPU, ResizePerfTest, + Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(cv::Size(64, 64), + cv::Size(30, 30)), + Values(0.0), + Values(cv::compile_args(CORE_CPU)))); + + INSTANTIATE_TEST_CASE_P(ResizeFxFyPerfTestCPU, ResizeFxFyPerfTest, + Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Values(cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_AREA), + Values(szSmall128, szVGA, sz720p, sz1080p), + Values(0.5, 0.1), + Values(0.5, 0.1), + Values(0.0), + Values(cv::compile_args(CORE_CPU)))); } diff --git a/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp b/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp index 5d42d8b5e5..23180123ed 100644 --- a/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp +++ b/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp @@ -7,114 +7,196 @@ #include "../perf_precomp.hpp" #include "../common/gapi_imgproc_perf_tests.hpp" +#include "opencv2/gapi/cpu/imgproc.hpp" + + +#define IMGPROC_CPU cv::gapi::imgproc::cpu::kernels() namespace opencv_test { - INSTANTIATE_TEST_CASE_P(SepFilterPerfTestCPU_8U, SepFilterPerfTest, - Combine(Values(CV_8UC1, CV_8UC3), - Values(3), - Values(szVGA, sz720p, sz1080p), - Values(-1, CV_16S, CV_32F))); - - INSTANTIATE_TEST_CASE_P(SepFilterPerfTestCPU_other, SepFilterPerfTest, - Combine(Values(CV_16UC1, CV_16SC1, CV_32FC1), - Values(3), - Values(szVGA, sz720p, sz1080p), - Values(-1, CV_32F))); - - INSTANTIATE_TEST_CASE_P(Filter2DPerfTestCPU, Filter2DPerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(3, 4, 5, 7), - Values(szVGA, sz720p, sz1080p), - Values(cv::BORDER_DEFAULT), - Values(-1, CV_32F))); - - INSTANTIATE_TEST_CASE_P(BoxFilterPerfTestCPU, BoxFilterPerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(3,5), - Values(szVGA, sz720p, sz1080p), - Values(cv::BORDER_DEFAULT), - Values(-1, CV_32F), - Values(0.0))); - - INSTANTIATE_TEST_CASE_P(BlurPerfTestCPU, BlurPerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(3, 5), - Values(szVGA, sz720p, sz1080p), - Values(cv::BORDER_DEFAULT), - Values(0.0))); - - INSTANTIATE_TEST_CASE_P(GaussianBlurPerfTestCPU, GaussianBlurPerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(3, 5), - Values(szVGA, sz720p, sz1080p))); - - INSTANTIATE_TEST_CASE_P(MedianBlurPerfTestCPU, MedianBlurPerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(3, 5), - Values(szVGA, sz720p, sz1080p))); - - INSTANTIATE_TEST_CASE_P(ErodePerfTestCPU, ErodePerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(3, 5), - Values(szVGA, sz720p, sz1080p), - Values(cv::MorphShapes::MORPH_RECT, - cv::MorphShapes::MORPH_CROSS, - cv::MorphShapes::MORPH_ELLIPSE))); - - INSTANTIATE_TEST_CASE_P(Erode3x3PerfTestCPU, Erode3x3PerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(szVGA, sz720p, sz1080p), - Values(1,2,4))); - - INSTANTIATE_TEST_CASE_P(DilatePerfTestCPU, DilatePerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(3, 5), - Values(szVGA, sz720p, sz1080p), - Values(cv::MorphShapes::MORPH_RECT, - cv::MorphShapes::MORPH_CROSS, - cv::MorphShapes::MORPH_ELLIPSE))); + class AbsExact : public Wrappable + { + public: + AbsExact() {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const { return cv::countNonZero(in1 != in2) == 0; } + private: + }; + + class AbsTolerance : public Wrappable + { + public: + AbsTolerance(double tol) : _tol(tol) {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const + { + cv::Mat absDiff; cv::absdiff(in1, in2, absDiff); + return cv::countNonZero(absDiff > _tol) == 0; + } + private: + double _tol; + }; + + + INSTANTIATE_TEST_CASE_P(SepFilterPerfTestCPU_8U, SepFilterPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3), + Values(3), + Values(szVGA, sz720p, sz1080p), + Values(-1, CV_16S, CV_32F), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(SepFilterPerfTestCPU_other, SepFilterPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(CV_16UC1, CV_16SC1, CV_32FC1), + Values(3), + Values(szVGA, sz720p, sz1080p), + Values(-1, CV_32F), + Values(cv::compile_args(IMGPROC_CPU)))); + + + + INSTANTIATE_TEST_CASE_P(Filter2DPerfTestCPU, Filter2DPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(3, 4, 5, 7), + Values(szVGA, sz720p, sz1080p), + Values(cv::BORDER_DEFAULT), + Values(-1, CV_32F), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(BoxFilterPerfTestCPU, BoxFilterPerfTest, + Combine(Values(AbsTolerance(1e-6).to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(3, 5), + Values(szVGA, sz720p, sz1080p), + Values(cv::BORDER_DEFAULT), + Values(-1, CV_32F), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(BlurPerfTestCPU, BlurPerfTest, + Combine(Values(AbsTolerance(1e-6).to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(3, 5), + Values(szVGA, sz720p, sz1080p), + Values(cv::BORDER_DEFAULT), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(GaussianBlurPerfTestCPU, GaussianBlurPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(3, 5), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(MedianBlurPerfTestCPU, MedianBlurPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(3, 5), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(ErodePerfTestCPU, ErodePerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(3, 5), + Values(szVGA, sz720p, sz1080p), + Values(cv::MorphShapes::MORPH_RECT, + cv::MorphShapes::MORPH_CROSS, + cv::MorphShapes::MORPH_ELLIPSE), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(Erode3x3PerfTestCPU, Erode3x3PerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(szVGA, sz720p, sz1080p), + Values(1, 2, 4), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(DilatePerfTestCPU, DilatePerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(3, 5), + Values(szVGA, sz720p, sz1080p), + Values(cv::MorphShapes::MORPH_RECT, + cv::MorphShapes::MORPH_CROSS, + cv::MorphShapes::MORPH_ELLIPSE), + Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(Dilate3x3PerfTestCPU, Dilate3x3PerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(szVGA, sz720p, sz1080p), - Values(1,2,4))); + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(szVGA, sz720p, sz1080p), + Values(1, 2, 4), + Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(SobelPerfTestCPU, SobelPerfTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), - Values(3, 5), - Values(szVGA, sz720p, sz1080p), - Values(-1, CV_32F), - Values(0, 1), - Values(1, 2))); + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Values(3, 5), + Values(szVGA, sz720p, sz1080p), + Values(-1, CV_32F), + Values(0, 1), + Values(1, 2), + Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(CannyPerfTestCPU, CannyPerfTest, - Combine(Values(CV_8UC1, CV_8UC3), - Values(szVGA, sz720p, sz1080p), - Values(3.0, 120.0), - Values(125.0, 240.0), - Values(3, 5), - Values(true, false))); - - INSTANTIATE_TEST_CASE_P(EqHistPerfTestCPU, EqHistPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(RGB2GrayPerfTestCPU, RGB2GrayPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(BGR2GrayPerfTestCPU, BGR2GrayPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(RGB2YUVPerfTestCPU, RGB2YUVPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(YUV2RGBPerfTestCPU, YUV2RGBPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(RGB2LabPerfTestCPU, RGB2LabPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(BGR2LUVPerfTestCPU, BGR2LUVPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(LUV2BGRPerfTestCPU, LUV2BGRPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(BGR2YUVPerfTestCPU, BGR2YUVPerfTest, Values(szVGA, sz720p, sz1080p)); - - INSTANTIATE_TEST_CASE_P(YUV2BGRPerfTestCPU, YUV2BGRPerfTest, Values(szVGA, sz720p, sz1080p)); + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3), + Values(szVGA, sz720p, sz1080p), + Values(3.0, 120.0), + Values(125.0, 240.0), + Values(3, 5), + Values(true, false), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(EqHistPerfTestCPU, EqHistPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(RGB2GrayPerfTestCPU, RGB2GrayPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(BGR2GrayPerfTestCPU, BGR2GrayPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(RGB2YUVPerfTestCPU, RGB2YUVPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(YUV2RGBPerfTestCPU, YUV2RGBPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(RGB2LabPerfTestCPU, RGB2LabPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(BGR2LUVPerfTestCPU, BGR2LUVPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(LUV2BGRPerfTestCPU, LUV2BGRPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(BGR2YUVPerfTestCPU, BGR2YUVPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + + INSTANTIATE_TEST_CASE_P(YUV2BGRPerfTestCPU, YUV2BGRPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); } diff --git a/modules/gapi/test/common/gapi_core_tests_inl.hpp b/modules/gapi/test/common/gapi_core_tests_inl.hpp index c1a8190196..7d413ca0c7 100644 --- a/modules/gapi/test/common/gapi_core_tests_inl.hpp +++ b/modules/gapi/test/common/gapi_core_tests_inl.hpp @@ -878,8 +878,7 @@ TEST_P(ThresholdOTTest, AccuracyTestOtsu) int tt = std::get<2>(param); auto compile_args = std::get<4>(param); - auto& rng = cv::theRNG(); - cv::Scalar maxval = cv::Scalar(50 + rng(50),50 + rng(50),50 + rng(50),50 + rng(50)); + cv::Scalar maxval = initScalarRandU(50) + cv::Scalar(50, 50, 50, 50); initMatrixRandU(type, sz_in, type, std::get<3>(param)); cv::Scalar out_gapi_scalar; double ocv_res; @@ -911,9 +910,8 @@ TEST_P(InRangeTest, AccuracyTest) cv::Size sz_in = std::get<1>(param); auto compile_args = std::get<3>(param); - auto& rng = cv::theRNG(); - cv::Scalar thrLow = cv::Scalar(rng(100),rng(100),rng(100),rng(100)); - cv::Scalar thrUp = cv::Scalar(100 + rng(100),100 + rng(100),100 + rng(100),100 + rng(100)); + cv::Scalar thrLow = initScalarRandU(100); + cv::Scalar thrUp = initScalarRandU(100) + cv::Scalar(100, 100, 100, 100); initMatrixRandU(type, sz_in, type, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// diff --git a/modules/gapi/test/common/gapi_imgproc_tests.hpp b/modules/gapi/test/common/gapi_imgproc_tests.hpp index 517c1253e3..c21b26b686 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests.hpp +++ b/modules/gapi/test/common/gapi_imgproc_tests.hpp @@ -14,28 +14,29 @@ namespace opencv_test { -struct Filter2DTest : public TestParams > {}; -struct BoxFilterTest : public TestParams > {}; -struct SepFilterTest : public TestParams > {}; -struct BlurTest : public TestParams > {}; -struct GaussianBlurTest : public TestParams > {}; -struct MedianBlurTest : public TestParams > {}; -struct ErodeTest : public TestParams > {}; -struct Erode3x3Test : public TestParams > {}; -struct DilateTest : public TestParams > {}; -struct Dilate3x3Test : public TestParams > {}; -struct SobelTest : public TestParams > {}; -struct EqHistTest : public TestParams > {}; -struct CannyTest : public TestParams > {}; -struct RGB2GrayTest : public TestParams> {}; -struct BGR2GrayTest : public TestParams> {}; -struct RGB2YUVTest : public TestParams> {}; -struct YUV2RGBTest : public TestParams> {}; -struct RGB2LabTest : public TestParams> {}; -struct BGR2LUVTest : public TestParams> {}; -struct LUV2BGRTest : public TestParams> {}; -struct BGR2YUVTest : public TestParams> {}; -struct YUV2BGRTest : public TestParams> {}; + +struct Filter2DTest : public TestParams > {}; +struct BoxFilterTest : public TestParams > {}; +struct SepFilterTest : public TestParams > {}; +struct BlurTest : public TestParams > {}; +struct GaussianBlurTest : public TestParams > {}; +struct MedianBlurTest : public TestParams > {}; +struct ErodeTest : public TestParams > {}; +struct Erode3x3Test : public TestParams > {}; +struct DilateTest : public TestParams > {}; +struct Dilate3x3Test : public TestParams > {}; +struct SobelTest : public TestParams > {}; +struct EqHistTest : public TestParams > {}; +struct CannyTest : public TestParams > {}; +struct RGB2GrayTest : public TestParams> {}; +struct BGR2GrayTest : public TestParams> {}; +struct RGB2YUVTest : public TestParams> {}; +struct YUV2RGBTest : public TestParams> {}; +struct RGB2LabTest : public TestParams> {}; +struct BGR2LUVTest : public TestParams> {}; +struct LUV2BGRTest : public TestParams> {}; +struct BGR2YUVTest : public TestParams> {}; +struct YUV2BGRTest : public TestParams> {}; } // opencv_test #endif //OPENCV_GAPI_IMGPROC_TESTS_HPP diff --git a/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp b/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp index 0185f65fbf..3de4289222 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp +++ b/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp @@ -15,12 +15,13 @@ namespace opencv_test { TEST_P(Filter2DTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int kernSize = 0, borderType = 0, dtype = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, kernSize, sz, borderType, dtype, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, kernSize, sz, borderType, dtype, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, dtype, initOut); cv::Point anchor = {-1, -1}; @@ -43,36 +44,20 @@ TEST_P(Filter2DTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: Control this choice with test's especial parameter - #if 1 - // Allow some rounding error - if (CV_MAT_DEPTH(out_mat_gapi.type()) == CV_32F) - { - // 6 decimal digits is nearly best accuracy we can expect of FP32 arithmetic here - EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 1e-6*cv::abs(out_mat_ocv))); - } - else - { - // allow wrong rounding if result fractional part is nearly 0.5, - // assume there would be not more than 0.01% of such cases - EXPECT_LE(cv::countNonZero(out_mat_gapi != out_mat_ocv), 1e-4*out_mat_ocv.total()); - } - #else - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(BoxFilterTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int filterSize = 0, borderType = 0, dtype = 0; cv::Size sz; - double tolerance = 0.0; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, filterSize, sz, borderType, dtype, tolerance, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, filterSize, sz, borderType, dtype, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, dtype, initOut); cv::Point anchor = {-1, -1}; @@ -90,37 +75,20 @@ TEST_P(BoxFilterTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: Control this choice with test's especial parameter - #if 1 - // Allow some rounding error - if (CV_MAT_DEPTH(out_mat_gapi.type()) == CV_32F) - { - // 6 decimal digits is nearly best accuracy we can expect of FP32 arithmetic here - EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 1e-6*cv::abs(out_mat_ocv))); - } - else - { - // allow wrong rounding if result fractional part is nearly 0.5, - // assume there would be not more than 0.01% of such cases - EXPECT_LE(cv::countNonZero(out_mat_gapi != out_mat_ocv), 1e-4*out_mat_ocv.total()); - } - #else - cv::Mat absDiff; - cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff); - EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance)); - #endif + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(SepFilterTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int kernSize = 0, dtype = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, kernSize, sz, dtype, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, kernSize, sz, dtype, initOut, compile_args) = GetParam(); cv::Mat kernelX(kernSize, 1, CV_32F); cv::Mat kernelY(kernSize, 1, CV_32F); @@ -142,27 +110,20 @@ TEST_P(SepFilterTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: Control this choice with test's especial parameter - #if 1 - // Expect some rounding error - EXPECT_LE(cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 1e-5 * cv::abs(out_mat_ocv)), - 0.01 * out_mat_ocv.total()); - #else - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(BlurTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int filterSize = 0, borderType = 0; cv::Size sz; - double tolerance = 0.0; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, filterSize, sz, borderType, tolerance, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, filterSize, sz, borderType, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, type, initOut); cv::Point anchor = {-1, -1}; @@ -179,21 +140,20 @@ TEST_P(BlurTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - cv::Mat absDiff; - cv::absdiff(out_mat_gapi, out_mat_ocv, absDiff); - EXPECT_EQ(0, cv::countNonZero(absDiff > tolerance)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(GaussianBlurTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int kernSize = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, kernSize, sz, initOut, compile_args) = GetParam(); + std::tie(cmpF,type, kernSize, sz, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, type, initOut); cv::Size kSize = cv::Size(kernSize, kernSize); @@ -211,42 +171,20 @@ TEST_P(GaussianBlurTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: Control this choice with test's especial parameter - #if 1 - // Expect some rounding error - if (CV_MAT_DEPTH(out_mat_gapi.type()) == CV_32F || - CV_MAT_DEPTH(out_mat_gapi.type()) == CV_64F) - { - // Note that 1e-6 is nearly best accuracy we can expect of FP32 arithetic - EXPECT_EQ(0, cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > - 1e-6*cv::abs(out_mat_ocv))); - } - else if (CV_MAT_DEPTH(out_mat_gapi.type()) == CV_8U) - { - // OpenCV uses 16-bits fixed-point for 8U data, so may produce wrong results - EXPECT_LE(cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 1), - 0.05*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(cv::abs(out_mat_gapi - out_mat_ocv) > 2), 0); - } - else - { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - } - #else - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(MedianBlurTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int kernSize = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, kernSize, sz, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, kernSize, sz, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, type, initOut); // G-API code ////////////////////////////////////////////////////////////// @@ -261,19 +199,20 @@ TEST_P(MedianBlurTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(ErodeTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int kernSize = 0, kernType = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, kernSize, sz, kernType, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, kernSize, sz, kernType, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, type, initOut); cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize)); @@ -290,19 +229,20 @@ TEST_P(ErodeTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(Erode3x3Test, AccuracyTest) { + compare_f cmpF; MatType type = 0; int numIters = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, sz, initOut, numIters, compile_args) = GetParam(); + std::tie(cmpF, type, sz, initOut, numIters, compile_args) = GetParam(); initMatsRandN(type, sz, type, initOut); cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3)); @@ -319,19 +259,20 @@ TEST_P(Erode3x3Test, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(DilateTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int kernSize = 0, kernType = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, kernSize, sz, kernType, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, kernSize, sz, kernType, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, type, initOut); cv::Mat kernel = cv::getStructuringElement(kernType, cv::Size(kernSize, kernSize)); @@ -348,19 +289,20 @@ TEST_P(DilateTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(Dilate3x3Test, AccuracyTest) { + compare_f cmpF; MatType type = 0; int numIters = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, sz, initOut, numIters, compile_args) = GetParam(); + std::tie(cmpF, type, sz, initOut, numIters, compile_args) = GetParam(); initMatsRandN(type, sz, type, initOut); cv::Mat kernel = cv::getStructuringElement(cv::MorphShapes::MORPH_RECT, cv::Size(3,3)); @@ -377,7 +319,7 @@ TEST_P(Dilate3x3Test, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } @@ -385,12 +327,13 @@ TEST_P(Dilate3x3Test, AccuracyTest) TEST_P(SobelTest, AccuracyTest) { + compare_f cmpF; MatType type = 0; int kernSize = 0, dtype = 0, dx = 0, dy = 0; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(type, kernSize, sz, dtype, dx, dy, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, kernSize, sz, dtype, dx, dy, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, dtype, initOut); // G-API code ////////////////////////////////////////////////////////////// @@ -405,17 +348,18 @@ TEST_P(SobelTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } TEST_P(EqHistTest, AccuracyTest) { + compare_f cmpF; cv::Size sz; bool initOut = false; cv::GCompileArgs compile_args; - std::tie(sz, initOut, compile_args) = GetParam(); + std::tie(cmpF, sz, initOut, compile_args) = GetParam(); initMatsRandN(CV_8UC1, sz, CV_8UC1, initOut); // G-API code ////////////////////////////////////////////////////////////// @@ -430,20 +374,21 @@ TEST_P(EqHistTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(GetParam())); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(GetParam())); } } TEST_P(CannyTest, AccuracyTest) { + compare_f cmpF; MatType type; int apSize = 0; double thrLow = 0.0, thrUp = 0.0; cv::Size sz; bool l2gr = false, initOut = false; cv::GCompileArgs compile_args; - std::tie(type, sz, thrLow, thrUp, apSize, l2gr, initOut, compile_args) = GetParam(); + std::tie(cmpF, type, sz, thrLow, thrUp, apSize, l2gr, initOut, compile_args) = GetParam(); initMatsRandN(type, sz, CV_8UC1, initOut); @@ -459,7 +404,7 @@ TEST_P(CannyTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); EXPECT_EQ(out_mat_gapi.size(), sz); } } @@ -467,8 +412,9 @@ TEST_P(CannyTest, AccuracyTest) TEST_P(RGB2GrayTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC1, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -482,26 +428,17 @@ TEST_P(RGB2GrayTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: control this choice with especial parameter of this test - #if 1 - // allow faithful rounding if result's fractional part is nearly 0.5 - // - assume not more than 0.1% of pixels may deviate this way - // - deviation must not exceed 1 unit anyway - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.001*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0); - #else - // insist of bit-exact results - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } TEST_P(BGR2GrayTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC1, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC1, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -515,26 +452,17 @@ TEST_P(BGR2GrayTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: control this choice with especial parameter of this test - #if 1 - // allow faithful rounding if result's fractional part is nearly 0.5 - // - assume not more than 0.1% of pixels may deviate this way - // - deviation must not exceed 1 unit anyway - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.001*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0); - #else - // insist of bit-exact results - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } TEST_P(RGB2YUVTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -548,26 +476,18 @@ TEST_P(RGB2YUVTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: control this choice with especial parameter of this test - #if 1 - // allow faithful rounding if result's fractional part is nearly 0.5 - // - assume not more than 15% of pixels may deviate this way - // - deviation must not exceed 1 unit anyway - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.15*3*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0); - #else - // insist of bit-exact results - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } TEST_P(YUV2RGBTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param)); + // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -581,26 +501,17 @@ TEST_P(YUV2RGBTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: control this choice with especial parameter of this test - #if 1 - // allow faithful rounding if result's fractional part is nearly 0.5 - // - assume not more than 1% of pixels may deviate this way - // - deviation must not exceed 1 unit anyway - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.01*3*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0); - #else - // insist of bit-exact results - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } TEST_P(RGB2LabTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -614,28 +525,17 @@ TEST_P(RGB2LabTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: control this choice with especial parameter of this test - #if 1 - // allow faithful rounding, if result's fractional part is nearly 0.5 - // - assume not more than 25% of pixels may deviate this way - // - not more than 1% of pixels may deviate by 1 unit - // - deviation must not exceed 2 units anyway - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.25*3*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0.01*3*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 2), 1e-5*3*out_mat_ocv.total()); - #else - // insist on bit-exact results - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } TEST_P(BGR2LUVTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -649,28 +549,17 @@ TEST_P(BGR2LUVTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: control this choice with especial parameter of this test - #if 1 - // allow faithful rounding, if result's fractional part is nearly 0.5 - // - assume not more than 25% of pixels may deviate this way - // - not more than 1% of pixels may deviate by 2+ units - // - not more than 0.01% pixels may deviate by 5+ units - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.25 * 3 * out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0.01 * 3 * out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 5), 0.0001 * 3 * out_mat_ocv.total()); - #else - // insist on bit-exact results - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } TEST_P(LUV2BGRTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -684,16 +573,17 @@ TEST_P(LUV2BGRTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } TEST_P(BGR2YUVTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -707,16 +597,17 @@ TEST_P(BGR2YUVTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } TEST_P(YUV2BGRTest, AccuracyTest) { auto param = GetParam(); - auto compile_args = std::get<2>(param); - initMatsRandN(CV_8UC3, std::get<0>(param), CV_8UC3, std::get<1>(param)); + auto compile_args = std::get<3>(param); + compare_f cmpF = std::get<0>(param); + initMatsRandN(CV_8UC3, std::get<1>(param), CV_8UC3, std::get<2>(param)); // G-API code ////////////////////////////////////////////////////////////// cv::GMat in; @@ -730,20 +621,8 @@ TEST_P(YUV2BGRTest, AccuracyTest) } // Comparison ////////////////////////////////////////////////////////////// { - // TODO: control this choice with especial parameter of this test - #if 1 - // allow faithful rounding, if result's fractional part is nearly 0.5 - // - assume not more than 25% of pixels may deviate this way - // - not more than 1% of pixels may deviate by 1 unit - // - deviation must not exceed 2 units anyway - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 0), 0.25*3*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 1), 0.01*3*out_mat_ocv.total()); - EXPECT_LE(cv::countNonZero(out_mat_gapi - out_mat_ocv > 2), 1e-5*3*out_mat_ocv.total()); - #else - // insist on bit-exact results - EXPECT_EQ(0, cv::countNonZero(out_mat_gapi != out_mat_ocv)); - #endif - EXPECT_EQ(out_mat_gapi.size(), std::get<0>(param)); + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), std::get<1>(param)); } } } // opencv_test diff --git a/modules/gapi/test/common/gapi_tests_common.hpp b/modules/gapi/test/common/gapi_tests_common.hpp index 0c9e375f8c..2a9b3f5dfa 100644 --- a/modules/gapi/test/common/gapi_tests_common.hpp +++ b/modules/gapi/test/common/gapi_tests_common.hpp @@ -31,13 +31,22 @@ public: cv::Scalar sc; + cv::Scalar initScalarRandU(unsigned upper) + { + auto& rng = cv::theRNG(); + double s1 = rng(upper); + double s2 = rng(upper); + double s3 = rng(upper); + double s4 = rng(upper); + return cv::Scalar(s1, s2, s3, s4); + } + void initMatsRandU(int type, cv::Size sz_in, int dtype, bool createOutputMatrices = true) { in_mat1 = cv::Mat(sz_in, type); in_mat2 = cv::Mat(sz_in, type); - auto& rng = cv::theRNG(); - sc = cv::Scalar(rng(100),rng(100),rng(100),rng(100)); + sc = initScalarRandU(100); cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255)); cv::randu(in_mat2, cv::Scalar::all(0), cv::Scalar::all(255)); @@ -52,8 +61,7 @@ public: { in_mat1 = cv::Mat(sz_in, type); - auto& rng = cv::theRNG(); - sc = cv::Scalar(rng(100),rng(100),rng(100),rng(100)); + sc = initScalarRandU(100); cv::randu(in_mat1, cv::Scalar::all(0), cv::Scalar::all(255)); @@ -105,4 +113,19 @@ class TestParams: public TestFunctional, public TestWithParam{}; template class TestPerfParams: public TestFunctional, public perf::TestBaseWithParam{}; +using compare_f = std::function; + +template +struct Wrappable +{ + compare_f to_compare_f() + { + T t = *static_cast(this); + return [t](const cv::Mat &a, const cv::Mat &b) + { + return t(a, b); + }; + } +}; + } diff --git a/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp b/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp index dc6a560908..d5b3169f2f 100644 --- a/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp +++ b/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp @@ -15,8 +15,30 @@ namespace opencv_test { +class AbsExact : public Wrappable +{ +public: + AbsExact() {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const { return cv::countNonZero(in1 != in2)==0; } +private: +}; + +class AbsTolerance : public Wrappable +{ +public: + AbsTolerance(double tol) : _tol(tol) {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const + { + cv::Mat absDiff; cv::absdiff(in1, in2, absDiff); + return cv::countNonZero(absDiff > _tol) == 0; + } +private: + double _tol; +}; + INSTANTIATE_TEST_CASE_P(Filter2DTestCPU, Filter2DTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(3, 4, 5, 7), Values(cv::Size(1280, 720), cv::Size(640, 480), @@ -27,18 +49,19 @@ INSTANTIATE_TEST_CASE_P(Filter2DTestCPU, Filter2DTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(BoxFilterTestCPU, BoxFilterTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsTolerance(1e-6).to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(3,5), Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(cv::BORDER_DEFAULT), Values(-1, CV_32F), - Values(0.0), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(SepFilterTestCPU_8U, SepFilterTest, - Combine(Values(CV_8UC1, CV_8UC3), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3), Values(3), Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -47,7 +70,8 @@ INSTANTIATE_TEST_CASE_P(SepFilterTestCPU_8U, SepFilterTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(SepFilterTestCPU_other, SepFilterTest, - Combine(Values(CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_16UC1, CV_16SC1, CV_32FC1), Values(3), Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -56,17 +80,18 @@ INSTANTIATE_TEST_CASE_P(SepFilterTestCPU_other, SepFilterTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(BlurTestCPU, BlurTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsTolerance(0.0).to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(3,5), Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(cv::BORDER_DEFAULT), - Values(0.0), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(gaussBlurTestCPU, GaussianBlurTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(3, 5), Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -74,7 +99,8 @@ INSTANTIATE_TEST_CASE_P(gaussBlurTestCPU, GaussianBlurTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(MedianBlurTestCPU, MedianBlurTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(3, 5), Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -82,7 +108,8 @@ INSTANTIATE_TEST_CASE_P(MedianBlurTestCPU, MedianBlurTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(ErodeTestCPU, ErodeTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(3, 5), Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -93,7 +120,8 @@ INSTANTIATE_TEST_CASE_P(ErodeTestCPU, ErodeTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(Erode3x3TestCPU, Erode3x3Test, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), @@ -101,7 +129,8 @@ INSTANTIATE_TEST_CASE_P(Erode3x3TestCPU, Erode3x3Test, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(DilateTestCPU, DilateTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(3, 5), Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -112,7 +141,8 @@ INSTANTIATE_TEST_CASE_P(DilateTestCPU, DilateTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(Dilate3x3TestCPU, Dilate3x3Test, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), @@ -120,7 +150,8 @@ INSTANTIATE_TEST_CASE_P(Dilate3x3TestCPU, Dilate3x3Test, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(SobelTestCPU, SobelTest, - Combine(Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3, CV_16UC1, CV_16SC1, CV_32FC1), Values(3, 5), Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -131,13 +162,15 @@ INSTANTIATE_TEST_CASE_P(SobelTestCPU, SobelTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(EqHistTestCPU, EqHistTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(CannyTestCPU, CannyTest, - Combine(Values(CV_8UC1, CV_8UC3), + Combine(Values(AbsExact().to_compare_f()), + Values(CV_8UC1, CV_8UC3), Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(3.0, 120.0), @@ -148,55 +181,64 @@ INSTANTIATE_TEST_CASE_P(CannyTestCPU, CannyTest, Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(RGB2GrayTestCPU, RGB2GrayTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(BGR2GrayTestCPU, BGR2GrayTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(RGB2YUVTestCPU, RGB2YUVTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(YUV2RGBTestCPU, YUV2RGBTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), -/*init output matrices or not*/ testing::Bool(), + /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(RGB2LabTestCPU, RGB2LabTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(BGR2LUVTestCPU, BGR2LUVTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(LUV2BGRTestCPU, LUV2BGRTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(BGR2YUVTestCPU, BGR2YUVTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); INSTANTIATE_TEST_CASE_P(YUV2BGRTestCPU, YUV2BGRTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsExact().to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), /*init output matrices or not*/ testing::Bool(), Values(cv::compile_args(IMGPROC_CPU)))); diff --git a/modules/gapi/test/cpu/gapi_imgproc_tests_fluid.cpp b/modules/gapi/test/cpu/gapi_imgproc_tests_fluid.cpp index 387967fc9f..dd78c08d36 100644 --- a/modules/gapi/test/cpu/gapi_imgproc_tests_fluid.cpp +++ b/modules/gapi/test/cpu/gapi_imgproc_tests_fluid.cpp @@ -14,55 +14,163 @@ namespace opencv_test { +class AbsExactFluid : public Wrappable +{ +public: + AbsExactFluid() {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const { return cv::countNonZero(in1 != in2) == 0; } +private: +}; + + +class AbsToleranceFluid : public Wrappable +{ +public: + AbsToleranceFluid(double tol) : _tol(tol) {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const + { + cv::Mat absDiff; cv::absdiff(in1, in2, absDiff); + return cv::countNonZero(absDiff > _tol) == 0; + } +private: + double _tol; +}; + +class AbsTolerance32FFluid : public Wrappable +{ +public: + AbsTolerance32FFluid(double tol) : _tol(tol) {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const + { + if (CV_MAT_DEPTH(in1.type()) == CV_32F) + return ((cv::countNonZero(cv::abs(in1 - in2) > (_tol)*cv::abs(in2))) ? false : true); + else + return ((cv::countNonZero(in1 != in2) <= (_tol * 100) * in2.total()) ? true : false); + } +private: + double _tol; +}; + +class AbsToleranceSepFilterFluid : public Wrappable +{ +public: + AbsToleranceSepFilterFluid(double tol) : _tol(tol) {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const + { + return ((cv::countNonZero(cv::abs(in1 - in2) > (_tol)* cv::abs(in2)) <= 0.01 * in2.total()) ? true : false); + } +private: + double _tol; +}; + +class AbsToleranceGaussianBlurFluid : public Wrappable +{ +public: + AbsToleranceGaussianBlurFluid(double tol) : _tol(tol) {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const + { + if (CV_MAT_DEPTH(in1.type()) == CV_32F || CV_MAT_DEPTH(in1.type()) == CV_64F) + { + return ((cv::countNonZero(cv::abs(in1 - in2) > (_tol)*cv::abs(in2))) ? false : true); + } + else + { + if (CV_MAT_DEPTH(in1.type()) == CV_8U) + { + bool a = (cv::countNonZero(cv::abs(in1 - in2) > 1) <= _tol * in2.total()); + return ((a == 1 ? 0 : 1) && ((cv::countNonZero(cv::abs(in1 - in2) > 2) <= 0) == 1 ? 0 : 1)) == 1 ? false : true; + } + else return cv::countNonZero(in1 != in2)==0; + } + } +private: + double _tol; +}; + +class AbsToleranceRGBBGRFluid : public Wrappable +{ +public: + AbsToleranceRGBBGRFluid(double tol) : _tol(tol) {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const + { + bool a = (cv::countNonZero((in1 - in2) > 0) <= _tol * in2.total()); + return ((a == 1 ? 0 : 1) && ((cv::countNonZero((in1 - in2) > 1) <= 0) == 1 ? 0 : 1)) == 1 ? false : true; + } +private: + double _tol; +}; + +class ToleranceTripleFluid : public Wrappable +{ +public: + ToleranceTripleFluid(double tol1, double tol2, double tol3) : _tol1(tol1), _tol2(tol2), _tol3(tol3) {} + bool operator() (const cv::Mat& in1, const cv::Mat& in2) const + { + bool a = (cv::countNonZero((in1 - in2) > 0) <= _tol1 * in2.total()); + return (((a == 1 ? 0 : 1) && + ((cv::countNonZero((in1 - in2) > 1) <= _tol2 * in2.total()) == 1 ? 0 : 1) && + ((cv::countNonZero((in1 - in2) > 2) <= _tol3 * in2.total()) == 1 ? 0 : 1))) == 1 ? false : true; + } +private: + double _tol1, _tol2, _tol3; +}; + INSTANTIATE_TEST_CASE_P(RGB2GrayTestFluid, RGB2GrayTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsToleranceRGBBGRFluid(0.001).to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(BGR2GrayTestFluid, BGR2GrayTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsToleranceRGBBGRFluid(0.001).to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(RGB2YUVTestFluid, RGB2YUVTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(AbsToleranceRGBBGRFluid(0.15*3).to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(YUV2RGBTestFluid, YUV2RGBTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(ToleranceTripleFluid(0.25 * 3, 0.01 * 3, 1e-5 * 3).to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(RGB2LabTestFluid, RGB2LabTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(ToleranceTripleFluid(0.25 * 3, 0.0, 1e-5 * 3).to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); // FIXME: Not supported by Fluid yet (no kernel implemented) INSTANTIATE_TEST_CASE_P(BGR2LUVTestFluid, BGR2LUVTest, - Combine(Values(cv::Size(1280, 720), + Combine(Values(ToleranceTripleFluid(0.25 * 3, 0.01 * 3, 0.0001 * 3).to_compare_f()), + Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(blurTestFluid, BlurTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(AbsToleranceFluid(0.0).to_compare_f()), + Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(3), // add kernel size=5 when implementation is ready Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(cv::BORDER_DEFAULT), - Values(0.0), Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(gaussBlurTestFluid, GaussianBlurTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(AbsToleranceGaussianBlurFluid(1e-6).to_compare_f()), + Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(3), // add kernel size=5 when implementation is ready Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -70,7 +178,8 @@ INSTANTIATE_TEST_CASE_P(gaussBlurTestFluid, GaussianBlurTest, Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(medianBlurTestFluid, MedianBlurTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(AbsExactFluid().to_compare_f()), + Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(3), // add kernel size=5 when implementation is ready Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -78,7 +187,8 @@ INSTANTIATE_TEST_CASE_P(medianBlurTestFluid, MedianBlurTest, Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(erodeTestFluid, ErodeTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(AbsExactFluid().to_compare_f()), + Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(3), // add kernel size=5 when implementation is ready Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -89,7 +199,8 @@ INSTANTIATE_TEST_CASE_P(erodeTestFluid, ErodeTest, Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(dilateTestFluid, DilateTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(AbsExactFluid().to_compare_f()), + Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(3), // add kernel size=5 when implementation is ready Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -100,7 +211,8 @@ INSTANTIATE_TEST_CASE_P(dilateTestFluid, DilateTest, Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(SobelTestFluid, SobelTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(AbsExactFluid().to_compare_f()), + Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(3), // add kernel size=5 when implementation is ready Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -110,20 +222,20 @@ INSTANTIATE_TEST_CASE_P(SobelTestFluid, SobelTest, Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); -INSTANTIATE_TEST_CASE_P(boxFilterTestFluid, BoxFilterTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), +INSTANTIATE_TEST_CASE_P(boxFilterTestFluid32, BoxFilterTest, + Combine(Values(AbsTolerance32FFluid(1e-6).to_compare_f()), + Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(3), // add kernel size=5 when implementation is ready Values(cv::Size(1280, 720), cv::Size(640, 480)), Values(cv::BORDER_DEFAULT), Values(-1, CV_32F), - Values(0.0), Values(true, false), Values(cv::compile_args(IMGPROC_FLUID)))); -// FIXME: Tests are failing on Fluid backend (accuracy issue?) INSTANTIATE_TEST_CASE_P(sepFilterTestFluid, SepFilterTest, - Combine(Values(CV_32FC1), + Combine(Values(AbsToleranceSepFilterFluid(1e-5f).to_compare_f()), + Values(CV_32FC1), Values(3), // add kernel size=5 when implementation is ready Values(cv::Size(1280, 720), cv::Size(640, 480)), @@ -132,7 +244,8 @@ INSTANTIATE_TEST_CASE_P(sepFilterTestFluid, SepFilterTest, Values(cv::compile_args(IMGPROC_FLUID)))); INSTANTIATE_TEST_CASE_P(filter2DTestFluid, Filter2DTest, - Combine(Values(CV_8UC1, CV_16UC1, CV_16SC1), + Combine(Values(AbsTolerance32FFluid(1e-6).to_compare_f()), + Values(CV_8UC1, CV_16UC1, CV_16SC1), Values(3), // add kernel size=4,5,7 when implementation ready Values(cv::Size(1280, 720), cv::Size(640, 480),