From fb326a35897cd0b6677410101a1f066fbfb4f379 Mon Sep 17 00:00:00 2001 From: Ruslan Garnov Date: Fri, 26 Apr 2019 17:33:50 +0300 Subject: [PATCH 1/2] Added a reproducer --- modules/gapi/test/gapi_fluid_resize_test.cpp | 61 +++++++++++++ modules/gapi/test/gapi_fluid_test_kernels.cpp | 87 ++++++++++++++++--- modules/gapi/test/gapi_fluid_test_kernels.hpp | 18 ++++ 3 files changed, 155 insertions(+), 11 deletions(-) diff --git a/modules/gapi/test/gapi_fluid_resize_test.cpp b/modules/gapi/test/gapi_fluid_resize_test.cpp index dbffd394bc..7dcf0d0b6e 100644 --- a/modules/gapi/test/gapi_fluid_resize_test.cpp +++ b/modules/gapi/test/gapi_fluid_resize_test.cpp @@ -790,4 +790,65 @@ INSTANTIATE_TEST_CASE_P(Fluid, NV12PlusResizeTest, cv::Size{ 32, 64}, cv::Rect{0, 48, 32, 16}) )); +struct Preproc4lpiTest : public TestWithParam >{}; +TEST_P(Preproc4lpiTest, Test) +{ + using namespace gapi_test_kernels; + cv::Size in_sz, out_sz; + cv::Rect roi; + std::tie(in_sz, out_sz, roi) = GetParam(); + int interp = cv::INTER_LINEAR; + + cv::Mat in_mat = cv::Mat(in_sz, CV_8UC3); + cv::randn(in_mat, cv::Scalar::all(127.0f), cv::Scalar::all(40.f)); + + cv::Mat out_mat, out_mat_ocv; + + cv::GMat in; + auto splitted = split3_4lpi(in); + + cv::GMat resized[3] = { cv::gapi::resize(std::get<0>(splitted), out_sz, 0, 0, interp) + , cv::gapi::resize(std::get<1>(splitted), out_sz, 0, 0, interp) + , cv::gapi::resize(std::get<2>(splitted), out_sz, 0, 0, interp) }; + + auto out = merge3_4lpi(resized[0], resized[1], resized[2]); + + cv::GComputation c(cv::GIn(in), cv::GOut(out)); + + auto pkg = cv::gapi::combine(cv::gapi::core::fluid::kernels(), + fluidResizeTestPackage(interp, in_sz, out_sz, 4), + cv::unite_policy::REPLACE); + + c.apply(cv::gin(in_mat), cv::gout(out_mat) + ,cv::compile_args(pkg, cv::GFluidOutputRois{{to_own(roi)}})); + + cv::resize(in_mat, out_mat_ocv, out_sz, 0, 0, interp); + + EXPECT_EQ(0, cv::countNonZero(out_mat(roi) != out_mat_ocv(roi))); +} + +INSTANTIATE_TEST_CASE_P(Fluid, Preproc4lpiTest, + Values(std::make_tuple(cv::Size{8, 8}, + cv::Size{4, 4}, cv::Rect{0, 0, 4, 4}) + ,std::make_tuple(cv::Size{8, 8}, + cv::Size{4, 4}, cv::Rect{0, 0, 4, 1}) + ,std::make_tuple(cv::Size{8, 8}, + cv::Size{4, 4}, cv::Rect{0, 1, 4, 2}) + ,std::make_tuple(cv::Size{8, 8}, + cv::Size{4, 4}, cv::Rect{0, 2, 4, 2}) + ,std::make_tuple(cv::Size{24, 24}, + cv::Size{12, 12}, cv::Rect{0, 0, 12, 3}) + ,std::make_tuple(cv::Size{24, 24}, + cv::Size{12, 12}, cv::Rect{0, 3, 12, 3}) + ,std::make_tuple(cv::Size{64, 64}, + cv::Size{49, 49}, cv::Rect{0, 0, 49, 49}) + ,std::make_tuple(cv::Size{64, 64}, + cv::Size{49, 49}, cv::Rect{0, 0, 49, 12}) + ,std::make_tuple(cv::Size{64, 64}, + cv::Size{49, 49}, cv::Rect{0, 11, 49, 15}) + ,std::make_tuple(cv::Size{64, 64}, + cv::Size{49, 49}, cv::Rect{0, 39, 49, 10}) + )); + + } // namespace opencv_test diff --git a/modules/gapi/test/gapi_fluid_test_kernels.cpp b/modules/gapi/test/gapi_fluid_test_kernels.cpp index d490bafe2c..fcc8d9b058 100644 --- a/modules/gapi/test/gapi_fluid_test_kernels.cpp +++ b/modules/gapi/test/gapi_fluid_test_kernels.cpp @@ -359,14 +359,12 @@ GAPI_FLUID_KERNEL(FPlusRow0, TPlusRow0, true) } }; -GAPI_FLUID_KERNEL(FTestSplit3, cv::gapi::core::GSplit3, false) +static void split3Row(const cv::gapi::fluid::View &in, + cv::gapi::fluid::Buffer &o1, + cv::gapi::fluid::Buffer &o2, + cv::gapi::fluid::Buffer &o3) { - static const int Window = 1; - - static void run(const cv::gapi::fluid::View &in, - cv::gapi::fluid::Buffer &o1, - cv::gapi::fluid::Buffer &o2, - cv::gapi::fluid::Buffer &o3) + for (int l = 0; l < o1.lpi(); l++) { // std::cout << "Split3 {{{\n"; // std::cout << " a - "; in.debug(std::cout); @@ -375,10 +373,10 @@ GAPI_FLUID_KERNEL(FTestSplit3, cv::gapi::core::GSplit3, false) // std::cout << " 3 - "; o3.debug(std::cout); // std::cout << "}}} " << std::endl;; - const uint8_t* in_rgb = in.InLine(0); - uint8_t* out_r = o1.OutLine(); - uint8_t* out_g = o2.OutLine(); - uint8_t* out_b = o3.OutLine(); + const uint8_t* in_rgb = in.InLine(l); + uint8_t* out_r = o1.OutLine(l); + uint8_t* out_g = o2.OutLine(l); + uint8_t* out_b = o3.OutLine(l); for (int i = 0, w = in.length(); i < w; i++) { @@ -387,8 +385,40 @@ GAPI_FLUID_KERNEL(FTestSplit3, cv::gapi::core::GSplit3, false) out_b[i] = in_rgb[3*i+2]; } } +} + +GAPI_FLUID_KERNEL(FTestSplit3, cv::gapi::core::GSplit3, false) +{ + static const int Window = 1; + + static void run(const cv::gapi::fluid::View &in, + cv::gapi::fluid::Buffer &o1, + cv::gapi::fluid::Buffer &o2, + cv::gapi::fluid::Buffer &o3) + { + split3Row(in, o1, o2, o3); + } }; +GAPI_FLUID_KERNEL(FTestSplit3_4lpi, TSplit3_4lpi, false) +{ + static const int Window = 1; + static const int LPI = 4; + + static void run(const cv::gapi::fluid::View &in, + cv::gapi::fluid::Buffer &o1, + cv::gapi::fluid::Buffer &o2, + cv::gapi::fluid::Buffer &o3) + { + split3Row(in, o1, o2, o3); + } +}; + +std::tuple split3_4lpi(const GMat& src) +{ + return TSplit3_4lpi::on(src); +} + GAPI_FLUID_KERNEL(FSum2MatsAndScalar, TSum2MatsAndScalar, false) { static const int Window = 1; @@ -486,6 +516,39 @@ GAPI_FLUID_KERNEL(FNV12toRGB, cv::gapi::imgproc::GNV12toRGB, false) } }; + +GAPI_FLUID_KERNEL(FMerge3_4lpi, TMerge3_4lpi, false) +{ + static const int Window = 1; + static const int LPI = 4; + + static void run(const cv::gapi::fluid::View &src1, + const cv::gapi::fluid::View &src2, + const cv::gapi::fluid::View &src3, + cv::gapi::fluid::Buffer &dst) + { + for (int l = 0; l < dst.lpi(); l++) + { + const auto *in1 = src1.InLine(l); + const auto *in2 = src2.InLine(l); + const auto *in3 = src3.InLine(l); + auto *out = dst.OutLine(l); + + for (int w = 0; w < dst.length(); w++) + { + out[3*w ] = in1[w]; + out[3*w + 1] = in2[w]; + out[3*w + 2] = in3[w]; + } + } + } +}; + +GMat merge3_4lpi(const GMat& src1, const GMat& src2, const GMat& src3) +{ + return TMerge3_4lpi::on(src1, src2, src3); +} + cv::gapi::GKernelPackage fluidTestPackage = cv::gapi::kernels (); } // namespace gapi_test_kernels } // namespace cv diff --git a/modules/gapi/test/gapi_fluid_test_kernels.hpp b/modules/gapi/test/gapi_fluid_test_kernels.hpp index f5d83edf5d..567dddd5d3 100644 --- a/modules/gapi/test/gapi_fluid_test_kernels.hpp +++ b/modules/gapi/test/gapi_fluid_test_kernels.hpp @@ -14,6 +14,7 @@ namespace cv { namespace gapi_test_kernels { +using cv::gapi::core::GMat3; G_TYPED_KERNEL(TAddSimple, , "test.fluid.add_simple") { static cv::GMatDesc outMeta(cv::GMatDesc a, cv::GMatDesc) { @@ -84,6 +85,12 @@ G_TYPED_KERNEL(TId7x7, , "test.fluid.identity7x7") { } }; +G_TYPED_KERNEL(TMerge3_4lpi, , "test.fluid.merge3_4lpi") { + static GMatDesc outMeta(GMatDesc in, GMatDesc, GMatDesc) { + return in.withType(in.depth, 3); + } +}; + G_TYPED_KERNEL(TPlusRow0, , "test.fluid.plus_row0") { static cv::GMatDesc outMeta(cv::GMatDesc a) { return a; @@ -97,6 +104,17 @@ G_TYPED_KERNEL(TSum2MatsAndScalar, , "test.fluid.sum_2_ } }; +G_TYPED_KERNEL_M(TSplit3_4lpi, , "test.fluid.split3_4lpi") { + static std::tuple outMeta(GMatDesc in) { + const auto out_depth = in.depth; + const auto out_desc = in.withType(out_depth, 1); + return std::make_tuple(out_desc, out_desc, out_desc); + } +}; + +GMat merge3_4lpi(const GMat& src1, const GMat& src2, const GMat& src3); +std::tuple split3_4lpi(const GMat& src); + extern cv::gapi::GKernelPackage fluidTestPackage; } // namespace gapi_test_kernels From ffaf4d5da4baf4ab4bcd8b2b819c72034ba81c89 Mon Sep 17 00:00:00 2001 From: Ruslan Garnov Date: Fri, 26 Apr 2019 17:34:44 +0300 Subject: [PATCH 2/2] Fixed incorrect first window setting for fluid FilterAgent --- modules/gapi/src/backends/fluid/gfluidbackend.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/gapi/src/backends/fluid/gfluidbackend.cpp b/modules/gapi/src/backends/fluid/gfluidbackend.cpp index 52a9a497ff..d9c91e476d 100644 --- a/modules/gapi/src/backends/fluid/gfluidbackend.cpp +++ b/modules/gapi/src/backends/fluid/gfluidbackend.cpp @@ -371,7 +371,8 @@ std::pair cv::gimpl::FluidUpscaleMapper::linesReadAndNextWindow(int out int cv::gimpl::FluidFilterAgent::firstWindow(std::size_t) const { - return k.m_window + k.m_lpi - 1; + int lpi = std::min(k.m_lpi, m_outputLines - m_producedLines); + return k.m_window + lpi - 1; } std::pair cv::gimpl::FluidFilterAgent::linesReadAndnextWindow(std::size_t) const