From fcdd69fd972d96cfc7861948a4b2bc5d20d3cf42 Mon Sep 17 00:00:00 2001 From: Orest Chura Date: Tue, 15 Dec 2020 01:45:41 +0300 Subject: [PATCH] Merge pull request #19103 from OrestChura:oc/cvtI420_perftests [G-API]: Performance tests for color conversion kernels * Performance tests for 5 new color conversion kernels: - BGR2RGB - BGR2I420 - RGB2I420 - I4202BGR - I4202RGB * Addressing comment --- .../perf/common/gapi_imgproc_perf_tests.hpp | 5 + .../common/gapi_imgproc_perf_tests_inl.hpp | 190 ++++++++++++++++++ .../perf/cpu/gapi_imgproc_perf_tests_cpu.cpp | 25 +++ .../gapi/test/common/gapi_imgproc_tests.hpp | 4 +- 4 files changed, 222 insertions(+), 2 deletions(-) diff --git a/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp b/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp index b2591907cf..c6efe8b8ac 100644 --- a/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests.hpp @@ -42,10 +42,15 @@ class GoodFeaturesPerfTest : public TestPerfParams> {}; class EqHistPerfTest : public TestPerfParams> {}; +class BGR2RGBPerfTest : public TestPerfParams> {}; class RGB2GrayPerfTest : public TestPerfParams> {}; class BGR2GrayPerfTest : public TestPerfParams> {}; class RGB2YUVPerfTest : public TestPerfParams> {}; class YUV2RGBPerfTest : public TestPerfParams> {}; +class BGR2I420PerfTest : public TestPerfParams> {}; +class RGB2I420PerfTest : public TestPerfParams> {}; +class I4202BGRPerfTest : public TestPerfParams> {}; +class I4202RGBPerfTest : public TestPerfParams> {}; class RGB2LabPerfTest : public TestPerfParams> {}; class BGR2LUVPerfTest : public TestPerfParams> {}; class LUV2BGRPerfTest : 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 f71e435a2b..3d00298988 100644 --- a/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp @@ -788,6 +788,44 @@ PERF_TEST_P_(EqHistPerfTest, TestPerformance) //------------------------------------------------------------------------------ +PERF_TEST_P_(BGR2RGBPerfTest, TestPerformance) +{ + compare_f cmpF; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, compile_args) = GetParam(); + + initMatrixRandN(CV_8UC3, sz, CV_8UC3, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2RGB); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::BGR2RGB(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); + } + + // 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()); @@ -940,6 +978,158 @@ PERF_TEST_P_(YUV2RGBPerfTest, TestPerformance) //------------------------------------------------------------------------------ +PERF_TEST_P_(BGR2I420PerfTest, TestPerformance) +{ + compare_f cmpF; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, compile_args) = GetParam(); + + initMatrixRandN(CV_8UC3, sz, CV_8UC1, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_BGR2YUV_I420); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::BGR2I420(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); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 3 / 2)); + } + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(RGB2I420PerfTest, TestPerformance) +{ + compare_f cmpF; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, compile_args) = GetParam(); + + initMatrixRandN(CV_8UC3, sz, CV_8UC1, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_RGB2YUV_I420); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::RGB2I420(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); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 3 / 2)); + } + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(I4202BGRPerfTest, TestPerformance) +{ + compare_f cmpF; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, compile_args) = GetParam(); + + initMatrixRandN(CV_8UC1, sz, CV_8UC3, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2BGR_I420); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::I4202BGR(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); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 2 / 3)); + } + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + +PERF_TEST_P_(I4202RGBPerfTest, TestPerformance) +{ + compare_f cmpF; + cv::Size sz; + cv::GCompileArgs compile_args; + std::tie(cmpF, sz, compile_args) = GetParam(); + + initMatrixRandN(CV_8UC1, sz, CV_8UC3, false); + + // OpenCV code ///////////////////////////////////////////////////////////// + { + cv::cvtColor(in_mat1, out_mat_ocv, cv::COLOR_YUV2RGB_I420); + } + + // G-API code ////////////////////////////////////////////////////////////// + cv::GMat in; + auto out = cv::gapi::I4202RGB(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); + } + + // Comparison ////////////////////////////////////////////////////////////// + { + EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv)); + EXPECT_EQ(out_mat_gapi.size(), Size(sz.width, sz.height * 2 / 3)); + } + + SANITY_CHECK_NOTHING(); +} + +//------------------------------------------------------------------------------ + PERF_TEST_P_(RGB2LabPerfTest, 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 4de1b18308..0548f6c277 100644 --- a/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp +++ b/modules/gapi/perf/cpu/gapi_imgproc_perf_tests_cpu.cpp @@ -179,6 +179,11 @@ INSTANTIATE_TEST_CASE_P(EqHistPerfTestCPU, EqHistPerfTest, Values(szVGA, sz720p, sz1080p), Values(cv::compile_args(IMGPROC_CPU)))); +INSTANTIATE_TEST_CASE_P(BGR2RGBPerfTestCPU, BGR2RGBPerfTest, + 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), @@ -199,6 +204,26 @@ INSTANTIATE_TEST_CASE_P(YUV2RGBPerfTestCPU, YUV2RGBPerfTest, Values(szVGA, sz720p, sz1080p), Values(cv::compile_args(IMGPROC_CPU)))); +INSTANTIATE_TEST_CASE_P(BGR2I420PerfTestCPU, BGR2I420PerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(RGB2I420PerfTestCPU, RGB2I420PerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(I4202BGRPerfTestCPU, I4202BGRPerfTest, + Combine(Values(AbsExact().to_compare_f()), + Values(szVGA, sz720p, sz1080p), + Values(cv::compile_args(IMGPROC_CPU)))); + +INSTANTIATE_TEST_CASE_P(I4202RGBPerfTestCPU, I4202RGBPerfTest, + 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), diff --git a/modules/gapi/test/common/gapi_imgproc_tests.hpp b/modules/gapi/test/common/gapi_imgproc_tests.hpp index b48b7b6732..2d929f12ec 100644 --- a/modules/gapi/test/common/gapi_imgproc_tests.hpp +++ b/modules/gapi/test/common/gapi_imgproc_tests.hpp @@ -81,8 +81,6 @@ GAPI_TEST_FIXTURE(BoundingRectMatVector32STest, initNothing, FIXTURE_API(Compare GAPI_TEST_FIXTURE(BoundingRectMatVector32FTest, initNothing, FIXTURE_API(CompareRects), 1, cmpF) GAPI_TEST_FIXTURE(BoundingRectVector32STest, initNothing, FIXTURE_API(CompareRects), 1, cmpF) GAPI_TEST_FIXTURE(BoundingRectVector32FTest, initNothing, FIXTURE_API(CompareRects), 1, cmpF) -GAPI_TEST_FIXTURE(BGR2RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF) -GAPI_TEST_FIXTURE(RGB2GrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF) GAPI_TEST_FIXTURE(FitLine2DMatVectorTest, initMatByPointsVectorRandU, FIXTURE_API(CompareVecs,cv::DistanceTypes), 2, cmpF, distType) GAPI_TEST_FIXTURE(FitLine2DVector32STest, initNothing, @@ -99,6 +97,8 @@ GAPI_TEST_FIXTURE(FitLine3DVector32FTest, initNothing, FIXTURE_API(CompareVecs,cv::DistanceTypes), 2, cmpF, distType) GAPI_TEST_FIXTURE(FitLine3DVector64FTest, initNothing, FIXTURE_API(CompareVecs,cv::DistanceTypes), 2, cmpF, distType) +GAPI_TEST_FIXTURE(BGR2RGBTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF) +GAPI_TEST_FIXTURE(RGB2GrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF) GAPI_TEST_FIXTURE(BGR2GrayTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF) GAPI_TEST_FIXTURE(RGB2YUVTest, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF) GAPI_TEST_FIXTURE(BGR2I420Test, initMatrixRandN, FIXTURE_API(CompareMats), 1, cmpF)