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 3b131e9158..f71e435a2b 100644 --- a/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp +++ b/modules/gapi/perf/common/gapi_imgproc_perf_tests_inl.hpp @@ -9,8 +9,6 @@ #define OPENCV_GAPI_IMGPROC_PERF_TESTS_INL_HPP -#include - #include "gapi_imgproc_perf_tests.hpp" namespace opencv_test diff --git a/modules/gapi/perf/common/gapi_render_perf_tests.cpp b/modules/gapi/perf/common/gapi_render_perf_tests.cpp new file mode 100644 index 0000000000..339a7bcfb3 --- /dev/null +++ b/modules/gapi/perf/common/gapi_render_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) 2020 Intel Corporation + + +#include "../perf_precomp.hpp" +#include "gapi_render_perf_tests_inl.hpp" diff --git a/modules/gapi/perf/common/gapi_render_perf_tests.hpp b/modules/gapi/perf/common/gapi_render_perf_tests.hpp new file mode 100644 index 0000000000..df14422d21 --- /dev/null +++ b/modules/gapi/perf/common/gapi_render_perf_tests.hpp @@ -0,0 +1,43 @@ +// 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_RENDER_PERF_TESTS_HPP +#define OPENCV_GAPI_RENDER_PERF_TESTS_HPP + + +#include "../../test/common/gapi_tests_common.hpp" +#include + +namespace opencv_test +{ + +using namespace perf; + +class RenderTestFTexts : public TestPerfParams> {}; +class RenderTestTexts : public TestPerfParams> {}; +class RenderTestRects : public TestPerfParams> {}; +class RenderTestCircles : public TestPerfParams> {}; +class RenderTestLines : public TestPerfParams> {}; +class RenderTestMosaics : public TestPerfParams> {}; +class RenderTestImages : public TestPerfParams> {}; +class RenderTestPolylines : public TestPerfParams, + cv::Scalar, int, int, int, + cv::GCompileArgs>> {}; +class RenderTestPolyItems : public TestPerfParams> {}; + +} +#endif //OPENCV_GAPI_RENDER_PERF_TESTS_HPP diff --git a/modules/gapi/perf/common/gapi_render_perf_tests_inl.hpp b/modules/gapi/perf/common/gapi_render_perf_tests_inl.hpp new file mode 100644 index 0000000000..66e8c37319 --- /dev/null +++ b/modules/gapi/perf/common/gapi_render_perf_tests_inl.hpp @@ -0,0 +1,827 @@ +// 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 + + +#include "gapi_render_perf_tests.hpp" + +namespace opencv_test +{ + +namespace { +void create_rand_mats(const cv::Size &size, MatType type, cv::Mat &ref_mat, cv::Mat &gapi_mat) +{ + ref_mat.create(size, type); + cv::randu(ref_mat, cv::Scalar::all(0), cv::Scalar::all(255)); + ref_mat.copyTo(gapi_mat); +}; + +} // namespace + +PERF_TEST_P_(RenderTestFTexts, RenderFTextsPerformanceBGROCVTest) +{ + std::wstring text; + cv::Size sz; + cv::Point org; + int fh = 0; + cv::Scalar color; + cv::GCompileArgs comp_args; + std::tie(text ,sz ,org ,fh ,color, comp_args) = GetParam(); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::FText{text, org, fh, color}); + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestFTexts, RenderFTextsPerformanceNV12OCVTest) +{ + std::wstring text; + cv::Size sz; + cv::Point org; + int fh = 0; + cv::Scalar color; + cv::GCompileArgs comp_args; + std::tie(text ,sz ,org ,fh ,color, comp_args) = GetParam(); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::FText{text, org, fh, color}); + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestTexts, RenderTextsPerformanceBGROCVTest) +{ + cv::Point org; + int ff = 0; + int thick = 0; + int lt = 0; + double fs = 2.0; + cv::Scalar color; + bool blo = false; + std::string text; + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(text, sz, org, ff, color, thick, lt, blo, comp_args) = GetParam(); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Text{text, org, ff, fs, color, thick, lt, blo}); + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestTexts, RenderTextsPerformanceNV12OCVTest) +{ + cv::Point org; + int ff = 0; + int thick = 0; + int lt = 0; + double fs = 2.0; + cv::Scalar color; + bool blo = false; + std::string text; + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(text, sz, org, ff, color, thick, lt, blo, comp_args) = GetParam(); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Text{text, org, ff, fs, color, thick, lt, blo}); + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestRects, RenderRectsPerformanceBGROCVTest) +{ + cv::Rect rect; + cv::Scalar color; + int thick = 0; + int lt = 0; + int shift = 0; + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, rect, color, thick, lt, shift, comp_args) = GetParam(); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift}); + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestRects, RenderRectsPerformanceNV12OCVTest) +{ + cv::Rect rect; + cv::Scalar color; + int thick = 0; + int lt = 0; + int shift = 0; + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, rect, color, thick, lt, shift, comp_args) = GetParam(); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Rect{rect, color, thick, lt, shift}); + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestCircles, RenderCirclesPerformanceBGROCVTest) +{ + cv::Point center; + int radius; + cv::Scalar color; + int thick = 0; + int lt = 0; + int shift = 0; + + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, center, radius, color, thick, lt, shift, comp_args) = GetParam(); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Circle{center, radius, color, thick, lt, shift}); + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestCircles, RenderCirclesPerformanceNV12OCVTest) +{ + cv::Point center; + int radius; + cv::Scalar color; + int thick = 0; + int lt = 0; + int shift = 0; + + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, center, radius, color, thick, lt, shift, comp_args) = GetParam(); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Circle{center, radius, color, thick, lt, shift}); + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestLines, RenderLinesPerformanceBGROCVTest) +{ + cv::Point pt1; + cv::Point pt2; + cv::Scalar color; + int thick = 0; + int lt = 0; + int shift = 0; + + compare_f cmpF; + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, pt1, pt2, color, thick, lt, shift, comp_args) = GetParam(); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Line{pt1, pt2, color, thick, lt, shift}); + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestLines, RenderLinesPerformanceNV12OCVTest) +{ + cv::Point pt1; + cv::Point pt2; + cv::Scalar color; + int thick = 0; + int lt = 0; + int shift = 0; + + compare_f cmpF; + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, pt1, pt2, color, thick, lt, shift, comp_args) = GetParam(); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Line{pt1, pt2, color, thick, lt, shift}); + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestMosaics, RenderMosaicsPerformanceBGROCVTest) +{ + cv::Rect mos; + int cellsz = 0; + int decim = 0; + + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, mos, cellsz, decim, comp_args) = GetParam(); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Mosaic{mos, cellsz, decim}); + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + + +PERF_TEST_P_(RenderTestMosaics, RenderMosaicsPerformanceNV12OCVTest) +{ + cv::Rect mos; + int cellsz = 0; + int decim = 0; + + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, mos, cellsz, decim, comp_args) = GetParam(); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Mosaic{mos, cellsz, decim}); + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestImages, RenderImagesPerformanceBGROCVTest) +{ + cv::Rect rect; + cv::Scalar color; + double transparency = 0.0; + + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, rect, color, transparency, comp_args) = GetParam(); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + + cv::Mat img(rect.size(), CV_8UC3, color); + cv::Mat alpha(rect.size(), CV_32FC1, transparency); + auto tl = rect.tl(); + cv::Point org = {tl.x, tl.y + rect.size().height}; + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Image{org, img, alpha}); + cv::gapi::wip::draw::render(gapi_mat, prims); + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestImages, RenderImagesPerformanceNV12OCVTest) +{ + cv::Rect rect; + cv::Scalar color; + double transparency = 0.0; + + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, rect, color, transparency, comp_args) = GetParam(); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + cv::Mat img(rect.size(), CV_8UC3, color); + cv::Mat alpha(rect.size(), CV_32FC1, transparency); + auto tl = rect.tl(); + cv::Point org = {tl.x, tl.y + rect.size().height}; + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Image{org, img, alpha}); + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestPolylines, RenderPolylinesPerformanceBGROCVTest) +{ + std::vector points; + cv::Scalar color; + int thick = 0; + int lt = 0; + int shift = 0; + + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, points, color, thick, lt, shift, comp_args) = GetParam(); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Poly{points, color, thick, lt, shift}); + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestPolylines, RenderPolylinesPerformanceNV12OCVTest) +{ + std::vector points; + cv::Scalar color; + int thick = 0; + int lt = 0; + int shift = 0; + + cv::Size sz; + cv::GCompileArgs comp_args; + std::tie(sz, points, color, thick, lt, shift, comp_args) = GetParam(); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + prims.emplace_back(cv::gapi::wip::draw::Poly{points, color, thick, lt, shift}); + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestPolyItems, RenderPolyItemsPerformanceBGROCVTest) +{ + cv::Size sz; + int rects_num = 0; + int text_num = 0; + int image_num = 0; + cv::GCompileArgs comp_args; + std::tie(sz, rects_num, text_num, image_num, comp_args) = GetParam(); + + int thick = 2; + int lt = LINE_8; + cv::Scalar color(100, 50, 150); + + MatType type = CV_8UC3; + cv::Mat gapi_mat, ref_mat; + create_rand_mats(sz, type, ref_mat, gapi_mat); + cv::Mat gapi_out_mat(sz, type); + gapi_mat.copyTo(gapi_out_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + + // Rects + int shift = 0; + for (int i = 0; i < rects_num; ++i) { + cv::Rect rect(200 + i, 200 + i, 200, 200); + prims.emplace_back(cv::gapi::wip::draw::Rect(rect, color, thick, lt, shift)); + } + + // Mosaic + int cellsz = 25; + int decim = 0; + for (int i = 0; i < rects_num; ++i) { + cv::Rect mos(200 + i, 200 + i, 200, 200); + prims.emplace_back(cv::gapi::wip::draw::Mosaic(mos, cellsz, decim)); + } + + // Text + std::string text = "Some text"; + int ff = FONT_HERSHEY_SIMPLEX; + double fs = 2.0; + bool blo = false; + for (int i = 0; i < text_num; ++i) { + cv::Point org(200 + i, 200 + i); + prims.emplace_back(cv::gapi::wip::draw::Text(text, org, ff, fs, color, thick, lt, blo)); + } + + // Image + double transparency = 1.0; + cv::Rect rect_img(0 ,0 , 50, 50); + cv::Mat img(rect_img.size(), CV_8UC3, color); + cv::Mat alpha(rect_img.size(), CV_32FC1, transparency); + auto tl = rect_img.tl(); + for (int i = 0; i < image_num; ++i) { + cv::Point org_img = {tl.x + i, tl.y + rect_img.size().height + i}; + + prims.emplace_back(cv::gapi::wip::draw::Image({org_img, img, alpha})); + } + + cv::GMat in; + cv::GArray arr; + + cv::GComputation comp(cv::GIn(in, arr), + cv::GOut(cv::gapi::wip::draw::render3ch(in, arr))); + + // Warm-up graph engine: + comp.apply(gin(gapi_mat, prims), gout(gapi_out_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(gin(gapi_mat, prims), gout(gapi_out_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +PERF_TEST_P_(RenderTestPolyItems, RenderPolyItemsPerformanceNV12OCVTest) +{ + cv::Size sz; + int rects_num = 0; + int text_num = 0; + int image_num = 0; + cv::GCompileArgs comp_args; + std::tie(sz, rects_num, text_num, image_num, comp_args) = GetParam(); + + int thick = 2; + int lt = LINE_8; + cv::Scalar color(100, 50, 150); + + cv::Mat y_ref_mat, uv_ref_mat; + + cv::Mat y_in_gapi_mat, uv_in_gapi_mat, + y_out_gapi_mat, uv_out_gapi_mat; + + create_rand_mats(sz, CV_8UC1, y_ref_mat, y_in_gapi_mat); + create_rand_mats(sz / 2, CV_8UC2, uv_ref_mat, uv_in_gapi_mat); + + // G-API code ////////////////////////////////////////////////////////////// + cv::gapi::wip::draw::Prims prims; + + // Rects + int shift = 0; + for (int i = 0; i < rects_num; ++i) { + cv::Rect rect(200 + i, 200 + i, 200, 200); + prims.emplace_back(cv::gapi::wip::draw::Rect(rect, color, thick, lt, shift)); + } + + // Mosaic + int cellsz = 25; + int decim = 0; + for (int i = 0; i < rects_num; ++i) { + cv::Rect mos(200 + i, 200 + i, 200, 200); + prims.emplace_back(cv::gapi::wip::draw::Mosaic(mos, cellsz, decim)); + } + + // Text + std::string text = "Some text"; + int ff = FONT_HERSHEY_SIMPLEX; + double fs = 2.0; + bool blo = false; + for (int i = 0; i < text_num; ++i) { + cv::Point org(200 + i, 200 + i); + prims.emplace_back(cv::gapi::wip::draw::Text(text, org, ff, fs, color, thick, lt, blo)); + } + + // Image + double transparency = 1.0; + cv::Rect rect_img(0 ,0 , 50, 50); + cv::Mat img(rect_img.size(), CV_8UC3, color); + cv::Mat alpha(rect_img.size(), CV_32FC1, transparency); + auto tl = rect_img.tl(); + for (int i = 0; i < image_num; ++i) { + cv::Point org_img = {tl.x + i, tl.y + rect_img.size().height + i}; + + prims.emplace_back(cv::gapi::wip::draw::Image({org_img, img, alpha})); + } + + cv::GMat y_in, uv_in, y_out, uv_out; + cv::GArray arr; + std::tie(y_out, uv_out) = cv::gapi::wip::draw::renderNV12(y_in, uv_in, arr); + + cv::GComputation comp(cv::GIn(y_in, uv_in, arr), cv::GOut(y_out, uv_out)); + + // Warm-up graph engine: + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat), std::move(comp_args)); + + TEST_CYCLE() + { + comp.apply(cv::gin(y_in_gapi_mat, uv_in_gapi_mat, prims), + cv::gout(y_out_gapi_mat, uv_out_gapi_mat)); + } + + SANITY_CHECK_NOTHING(); +} + +} // namespace opencv_test diff --git a/modules/gapi/perf/render/gapi_render_perf_tests_ocv.cpp b/modules/gapi/perf/render/gapi_render_perf_tests_ocv.cpp new file mode 100644 index 0000000000..2b51c083ea --- /dev/null +++ b/modules/gapi/perf/render/gapi_render_perf_tests_ocv.cpp @@ -0,0 +1,95 @@ +// 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 + + +#include "../perf_precomp.hpp" +#include "../common/gapi_render_perf_tests.hpp" + +#define RENDER_OCV cv::gapi::render::ocv::kernels() + +namespace opencv_test +{ + +#ifdef HAVE_FREETYPE +INSTANTIATE_TEST_CASE_P(RenderTestFTexts, RenderTestFTexts, + Combine(Values(L"\xe4\xbd\xa0\xe5\xa5\xbd"), + Values(szVGA, sz720p, sz1080p), + Values(cv::Point(50, 50)), + Values(60), + Values(cv::Scalar(200, 100, 25)), + Values(cv::compile_args(RENDER_OCV)))); +#endif // HAVE_FREETYPE + +INSTANTIATE_TEST_CASE_P(RenderTestTexts, RenderTestTexts, + Combine(Values(std::string("Some text")), + Values(szVGA, sz720p, sz1080p), + Values(cv::Point(200, 200)), + Values(FONT_HERSHEY_SIMPLEX), + Values(cv::Scalar(0, 255, 0)), + Values(2), + Values(LINE_8), + Values(false), + Values(cv::compile_args(RENDER_OCV)))); + +INSTANTIATE_TEST_CASE_P(RenderTestRects, RenderTestRects, + Combine(Values(szVGA, sz720p, sz1080p), + Values(cv::Rect(100, 100, 200, 200)), + Values(cv::Scalar(100, 50, 150)), + Values(2), + Values(LINE_8), + Values(0), + Values(cv::compile_args(RENDER_OCV)))); + +INSTANTIATE_TEST_CASE_P(RenderTestCircles, RenderTestCircles, + Combine(Values(szVGA, sz720p, sz1080p), + Values(cv::Point(100, 100)), + Values(10), + Values(cv::Scalar(100, 50, 150)), + Values(2), + Values(LINE_8), + Values(0), + Values(cv::compile_args(RENDER_OCV)))); + +INSTANTIATE_TEST_CASE_P(RenderTestLines, RenderTestLines, + Combine(Values(szVGA, sz720p, sz1080p), + Values(cv::Point(100, 100)), + Values(cv::Point(200, 200)), + Values(cv::Scalar(100, 50, 150)), + Values(2), + Values(LINE_8), + Values(0), + Values(cv::compile_args(RENDER_OCV)))); + +INSTANTIATE_TEST_CASE_P(RenderTestMosaics, RenderTestMosaics, + Combine(Values(szVGA, sz720p, sz1080p), + Values(cv::Rect(100, 100, 200, 200)), + Values(25), + Values(0), + Values(cv::compile_args(RENDER_OCV)))); + +INSTANTIATE_TEST_CASE_P(RenderTestImages, RenderTestImages, + Combine(Values(szVGA, sz720p, sz1080p), + Values(cv::Rect(50, 50, 100, 100)), + Values(cv::Scalar(100, 150, 60)), + Values(1.0), + Values(cv::compile_args(RENDER_OCV)))); + +INSTANTIATE_TEST_CASE_P(RenderTestPolylines, RenderTestPolylines, + Combine(Values(szVGA, sz720p, sz1080p), + Values(std::vector{{100, 100}, {200, 200}, {150, 300}, {400, 150}}), + Values(cv::Scalar(100, 150, 60)), + Values(2), + Values(LINE_8), + Values(0), + Values(cv::compile_args(RENDER_OCV)))); + +INSTANTIATE_TEST_CASE_P(RenderTestPolyItems, RenderTestPolyItems, + Combine(Values(szVGA, sz720p, sz1080p), + Values(50), + Values(50), + Values(50), + Values(cv::compile_args(RENDER_OCV)))); +}