From: Orest Chura Date: Tue, 12 Jan 2021 21:33:05 +0000 (+0300) Subject: Merge pull request #19215 from OrestChura:oc/bRect_perftests X-Git-Tag: accepted/tizen/unified/20220125.121719~1^2~257 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d34a34f3287759d6c6fd114a340f8dedb84b9bc4;p=platform%2Fupstream%2Fopencv.git Merge pull request #19215 from OrestChura:oc/bRect_perftests [G-API]: Performance tests for boundingRect * Update boundingRect() tests with the changes from fitLine() PR * Add performance tests for boundingRect * Applying comment about g_type_of_t * Addressing comments * Addressing comment: replace cmp_f by CompareF in perf.tests + add the default constructor for CompareF * Fix typo --- diff --git a/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp b/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp index 3b29246..931637d 100644 --- a/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp @@ -43,6 +43,12 @@ class CannyPerfTest : public TestPerfParams, std::string, int,int,double,double,int,bool, cv::GCompileArgs>> {}; +class BoundingRectMatPerfTest : + public TestPerfParams> {}; +class BoundingRectVector32SPerfTest : + public TestPerfParams> {}; +class BoundingRectVector32FPerfTest : + public TestPerfParams> {}; class EqHistPerfTest : public TestPerfParams> {}; class BGR2RGBPerfTest : public TestPerfParams> {}; class RGB2GrayPerfTest : public TestPerfParams> {}; diff --git a/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp b/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp index 8567f52..626cecc 100644 --- a/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp @@ -11,6 +11,8 @@ #include "gapi_imgproc_perf_tests.hpp" +#include "../../test/common/gapi_imgproc_tests_common.hpp" + namespace opencv_test { @@ -793,6 +795,82 @@ PERF_TEST_P_(GoodFeaturesPerfTest, TestPerformance) //------------------------------------------------------------------------------ +PERF_TEST_P_(BoundingRectMatPerfTest, TestPerformance) +{ + CompareRects cmpF; + cv::Size sz; + MatType type; + bool initByVector = false; + cv::GCompileArgs compile_args; + std::tie(cmpF, type, sz, initByVector, compile_args) = GetParam(); + + if (initByVector) + { + initMatByPointsVectorRandU(type, sz, -1); + } + else + { + initMatrixRandU(type, sz, -1, false); + } + + cv::Rect out_rect_gapi; + cv::GComputation c(boundingRectTestGAPI(in_mat1, std::move(compile_args), out_rect_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi)); + } + + boundingRectTestOpenCVCompare(in_mat1, out_rect_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(BoundingRectVector32SPerfTest, TestPerformance) +{ + CompareRects cmpF; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, compile_args) = GetParam(); + + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); + + cv::Rect out_rect_gapi; + cv::GComputation c(boundingRectTestGAPI(in_vector, std::move(compile_args), out_rect_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_vector), cv::gout(out_rect_gapi)); + } + + boundingRectTestOpenCVCompare(in_vector, out_rect_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(BoundingRectVector32FPerfTest, TestPerformance) +{ + CompareRects cmpF; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, compile_args) = GetParam(); + + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); + + cv::Rect out_rect_gapi; + cv::GComputation c(boundingRectTestGAPI(in_vector, std::move(compile_args), out_rect_gapi)); + + TEST_CYCLE() + { + c.apply(cv::gin(in_vector), cv::gout(out_rect_gapi)); + } + + boundingRectTestOpenCVCompare(in_vector, out_rect_gapi, cmpF); + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + PERF_TEST_P_(EqHistPerfTest, TestPerformance) { compare_f cmpF = get<0>(GetParam()); 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 dbc50d2..dcb78b7 100644 --- a/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp +++ b/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp @@ -194,6 +194,30 @@ INSTANTIATE_TEST_CASE_P(GoodFeaturesInternalPerfTestCPU, GoodFeaturesPerfTest, Values(true), Values(cv::compile_args(IMGPROC_CPU)))); +INSTANTIATE_TEST_CASE_P(BoundingRectMatPerfTestCPU, BoundingRectMatPerfTest, + Combine(Values(IoUToleranceRect(0).to_compare_obj()), + Values(CV_8UC1), + Values(szVGA, sz720p, sz1080p), + Values(false), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(BoundingRectMatVectorPerfTestCPU, BoundingRectMatPerfTest, + Combine(Values(IoUToleranceRect(1e-5).to_compare_obj()), + Values(CV_32S, CV_32F), + Values(szVGA, sz720p, sz1080p), + Values(true), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(BoundingRectVector32SPerfTestCPU, BoundingRectVector32SPerfTest, + Combine(Values(IoUToleranceRect(0).to_compare_obj()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(BoundingRectVector32FPerfTestCPU, BoundingRectVector32FPerfTest, + Combine(Values(IoUToleranceRect(1e-5).to_compare_obj()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + INSTANTIATE_TEST_CASE_P(EqHistPerfTestCPU, EqHistPerfTest, Combine(Values(AbsExact().to_compare_f()), Values(szVGA, sz720p, sz1080p), diff --git a/modules/gapi/test/common/gapi_imgproc_tests.hpp b/modules/gapi/test/common/gapi_imgproc_tests.hpp index dfd5e74..892629b 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests.hpp +++ b/modules/gapi/test/common/gapi_imgproc_tests.hpp @@ -76,9 +76,8 @@ GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursHNoOffsetTest, cv::ContourApproximationModes), 4, sz, type, mode, method) GAPI_TEST_FIXTURE_SPEC_PARAMS(FindContoursHOffsetTest, <>, 0) -GAPI_TEST_FIXTURE(BoundingRectMatTest, initMatrixRandU, FIXTURE_API(CompareRects), 1, cmpF) -GAPI_TEST_FIXTURE(BoundingRectMatVector32STest, initNothing, FIXTURE_API(CompareRects), 1, cmpF) -GAPI_TEST_FIXTURE(BoundingRectMatVector32FTest, initNothing, FIXTURE_API(CompareRects), 1, cmpF) +GAPI_TEST_FIXTURE(BoundingRectMatTest, initNothing, FIXTURE_API(CompareRects,bool), + 2, cmpF, initByVector) GAPI_TEST_FIXTURE(BoundingRectVector32STest, initNothing, FIXTURE_API(CompareRects), 1, cmpF) GAPI_TEST_FIXTURE(BoundingRectVector32FTest, initNothing, FIXTURE_API(CompareRects), 1, cmpF) GAPI_TEST_FIXTURE(FitLine2DMatVectorTest, initMatByPointsVectorRandU, diff --git a/modules/gapi/test/common/gapi_imgproc_tests_common.hpp b/modules/gapi/test/common/gapi_imgproc_tests_common.hpp new file mode 100644 index 0000000..796a0e9 --- /dev/null +++ b/modules/gapi/test/common/gapi_imgproc_tests_common.hpp @@ -0,0 +1,49 @@ +// 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) 2020 Intel Corporation + +#ifndef OPENCV_GAPI_IMGPROC_TESTS_COMMON_HPP +#define OPENCV_GAPI_IMGPROC_TESTS_COMMON_HPP + +#include "gapi_tests_common.hpp" +#include "../../include/opencv2/gapi/imgproc.hpp" + +#include + +namespace opencv_test +{ +template +static cv::GComputation boundingRectTestGAPI(const In& in, cv::GCompileArgs&& args, + cv::Rect& out_rect_gapi) +{ + cv::detail::g_type_of_t g_in; + auto out = cv::gapi::boundingRect(g_in); + cv::GComputation c(cv::GIn(g_in), cv::GOut(out)); + c.apply(cv::gin(in), cv::gout(out_rect_gapi), std::move(args)); + return c; +} + +template +static void boundingRectTestOpenCVCompare(const In& in, const cv::Rect& out_rect_gapi, + const CompareRects& cmpF) +{ + // OpenCV code ///////////////////////////////////////////////////////////// + cv::Rect out_rect_ocv = cv::boundingRect(in); + // Comparison ////////////////////////////////////////////////////////////// + EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv)); +} + +template +static void boundingRectTestBody(const In& in, const CompareRects& cmpF, cv::GCompileArgs&& args) +{ + cv::Rect out_rect_gapi; + boundingRectTestGAPI(in, std::move(args), out_rect_gapi); + + boundingRectTestOpenCVCompare(in, out_rect_gapi, cmpF); +} + +} // namespace opencv_test + +#endif // OPENCV_GAPI_VIDEO_TESTS_COMMON_HPP diff --git a/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp b/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp index dc77093..9b076f6 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp +++ b/modules/gapi/test/common/gapi_imgproc_tests_inl.hpp @@ -11,6 +11,8 @@ #include #include "gapi_imgproc_tests.hpp" +#include "gapi_imgproc_tests_common.hpp" + namespace opencv_test { @@ -623,133 +625,32 @@ TEST_P(FindContoursHOffsetTest, AccuracyTest) TEST_P(BoundingRectMatTest, AccuracyTest) { - cv::Rect out_rect_gapi, out_rect_ocv; - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::boundingRect(in); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - out_rect_ocv = cv::boundingRect(in_mat1); - } - // Comparison ////////////////////////////////////////////////////////////// + if (initByVector) { - EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv)); + initMatByPointsVectorRandU(type, sz, dtype); } -} - -TEST_P(BoundingRectMatVector32STest, AccuracyTest) -{ - cv::Rect out_rect_gapi, out_rect_ocv; - - std::vector in_vectorS(sz.width); - cv::randu(in_vectorS, cv::Scalar::all(0), cv::Scalar::all(255)); - in_mat1 = cv::Mat(in_vectorS); - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::boundingRect(in); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - out_rect_ocv = cv::boundingRect(in_mat1); - } - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv)); - } -} - -TEST_P(BoundingRectMatVector32FTest, AccuracyTest) -{ - cv::RNG& rng = theRNG(); - cv::Rect out_rect_gapi, out_rect_ocv; - - std::vector in_vectorF(sz.width); - const int fscale = 256; // avoid bits near ULP, generate stable test input - for (int i = 0; i < sz.width; i++) - { - cv::Point2f pt(rng.uniform(0, 255 * fscale) / static_cast(fscale), - rng.uniform(0, 255 * fscale) / static_cast(fscale)); - in_vectorF.push_back(pt); - } - in_mat1 = cv::Mat(in_vectorF); - - // G-API code ////////////////////////////////////////////////////////////// - cv::GMat in; - auto out = cv::gapi::boundingRect(in); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_mat1), cv::gout(out_rect_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - out_rect_ocv = cv::boundingRect(in_mat1); - } - // Comparison ////////////////////////////////////////////////////////////// + else { - EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv)); + initMatrixRandU(type, sz, dtype); } + boundingRectTestBody(in_mat1, cmpF, getCompileArgs()); } - TEST_P(BoundingRectVector32STest, AccuracyTest) -{ - cv::Rect out_rect_gapi, out_rect_ocv; - - std::vector in_vectorS(sz.width); - cv::randu(in_vectorS, cv::Scalar::all(0), cv::Scalar::all(255)); - // G-API code ////////////////////////////////////////////////////////////// - cv::GArray in; - auto out = cv::gapi::boundingRect(in); - - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_vectorS), cv::gout(out_rect_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - out_rect_ocv = cv::boundingRect(in_vectorS); - } +{ + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv)); - } + boundingRectTestBody(in_vector, cmpF, getCompileArgs()); } TEST_P(BoundingRectVector32FTest, AccuracyTest) { - cv::RNG& rng = theRNG(); - cv::Rect out_rect_gapi, out_rect_ocv; - - std::vector in_vectorF(sz.width); - const int fscale = 256; // avoid bits near ULP, generate stable test input - for (int i = 0; i < sz.width; i++) - { - cv::Point2f pt(rng.uniform(0, 255 * fscale) / static_cast(fscale), - rng.uniform(0, 255 * fscale) / static_cast(fscale)); - in_vectorF.push_back(pt); - } - - // G-API code ////////////////////////////////////////////////////////////// - cv::GArray in; - auto out = cv::gapi::boundingRect(in); + std::vector in_vector; + initPointsVectorRandU(sz.width, in_vector); - cv::GComputation c(cv::GIn(in), cv::GOut(out)); - c.apply(cv::gin(in_vectorF), cv::gout(out_rect_gapi), getCompileArgs()); - // OpenCV code ///////////////////////////////////////////////////////////// - { - out_rect_ocv = cv::boundingRect(in_vectorF); - } - - // Comparison ////////////////////////////////////////////////////////////// - { - EXPECT_TRUE(cmpF(out_rect_gapi, out_rect_ocv)); - } + boundingRectTestBody(in_vector, cmpF, getCompileArgs()); } TEST_P(FitLine2DMatVectorTest, AccuracyTest) diff --git a/modules/gapi/test/common/gapi_tests_common.hpp b/modules/gapi/test/common/gapi_tests_common.hpp index 6d11881..1da0844 100644 --- a/modules/gapi/test/common/gapi_tests_common.hpp +++ b/modules/gapi/test/common/gapi_tests_common.hpp @@ -593,6 +593,8 @@ using compare_vec_f = std::function &a, const cv::V template struct CompareF { + CompareF() = default; + using callable_t = std::function; CompareF(callable_t&& cmp, std::string&& cmp_name) : _comparator(std::move(cmp)), _name(std::move(cmp_name)) {} diff --git a/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp b/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp index 884bf0d..3b8e5f3 100644 --- a/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp +++ b/modules/gapi/test/cpu/gapi_imgproc_tests_cpu.cpp @@ -303,23 +303,17 @@ INSTANTIATE_TEST_CASE_P(BoundingRectMatTestCPU, BoundingRectMatTest, cv::Size(128, 128)), Values(-1), Values(IMGPROC_CPU), - Values(IoUToleranceRect(0).to_compare_obj()))); + Values(IoUToleranceRect(0).to_compare_obj()), + Values(false))); -INSTANTIATE_TEST_CASE_P(BoundingRectMatVector32STestCPU, BoundingRectMatVector32STest, - Combine(Values(-1), +INSTANTIATE_TEST_CASE_P(BoundingRectMatVectorTestCPU, BoundingRectMatTest, + Combine(Values(CV_32S, CV_32F), Values(cv::Size(1280, 1), cv::Size(128, 1)), Values(-1), Values(IMGPROC_CPU), - Values(IoUToleranceRect(0).to_compare_obj()))); - - INSTANTIATE_TEST_CASE_P(BoundingRectMatVector32FTestCPU, BoundingRectMatVector32FTest, - Combine(Values(-1), - Values(cv::Size(1280, 1), - cv::Size(128, 1)), - Values(-1), - Values(IMGPROC_CPU), - Values(IoUToleranceRect(1e-5).to_compare_obj()))); + Values(IoUToleranceRect(1e-5).to_compare_obj()), + Values(true))); INSTANTIATE_TEST_CASE_P(BoundingRectVector32STestCPU, BoundingRectVector32STest, Combine(Values(-1),