diff --git a/modules/gapi/src/backends/fluid/gfluidbackend.cpp b/modules/gapi/src/backends/fluid/gfluidbackend.cpp index 49bc5845c3..10bf244f5d 100644 --- a/modules/gapi/src/backends/fluid/gfluidbackend.cpp +++ b/modules/gapi/src/backends/fluid/gfluidbackend.cpp @@ -1145,7 +1145,16 @@ void cv::gimpl::GFluidExecutable::makeReshape(const std::vector // Introduce Storage::INTERNAL_GRAPH and Storage::INTERNAL_ISLAND? if (fd.internal == true) { - m_buffers[id].priv().allocate(fd.border, fd.border_size, fd.max_consumption, fd.skew); + // FIXME: do max_consumption calculation properly (e.g. in initLineConsumption) + int max_consumption = 0; + if (nh->outNodes().empty()) { + // nh is always a DATA node, so it is safe to get inNodes().front() since there's + // always a single writer (OP node) + max_consumption = fg.metadata(nh->inNodes().front()).get().k.m_lpi; + } else { + max_consumption = fd.max_consumption; + } + m_buffers[id].priv().allocate(fd.border, fd.border_size, max_consumption, fd.skew); std::stringstream stream; m_buffers[id].debug(stream); GAPI_LOG_INFO(NULL, stream.str()); diff --git a/modules/gapi/test/gapi_fluid_test.cpp b/modules/gapi/test/gapi_fluid_test.cpp index b919d99114..f2d8432c3f 100644 --- a/modules/gapi/test/gapi_fluid_test.cpp +++ b/modules/gapi/test/gapi_fluid_test.cpp @@ -752,7 +752,7 @@ INSTANTIATE_TEST_CASE_P(Fluid, NV12RoiTest, ,std::make_pair(cv::Size{1920, 1080}, cv::Rect{0, 710, 1920, 270}) )); -TEST(Fluid, UnusedNodeTest) { +TEST(Fluid, UnusedNodeOutputCompileTest) { cv::GMat in; cv::GMat a, b, c, d; std::tie(a, b, c, d) = cv::gapi::split4(in); @@ -767,4 +767,28 @@ TEST(Fluid, UnusedNodeTest) { cv::compile_args(cv::gapi::core::fluid::kernels()))); } +TEST(Fluid, UnusedNodeOutputReshapeTest) { + const auto test_size = cv::Size(8, 8); + const auto get_compile_args = + [] () { return cv::compile_args(cv::gapi::core::fluid::kernels()); }; + + cv::GMat in; + cv::GMat a, b, c, d; + std::tie(a, b, c, d) = cv::gapi::split4(in); + cv::GMat out = cv::gapi::resize(cv::gapi::merge3(a, b, c), test_size, 0.0, 0.0, + cv::INTER_LINEAR); + cv::GComputation comp(cv::GIn(in), cv::GOut(out)); + + cv::Mat in_mat(test_size, CV_8UC4); + cv::Mat out_mat(test_size, CV_8UC3); + + cv::GCompiled compiled; + ASSERT_NO_THROW(compiled = comp.compile(descr_of(in_mat), get_compile_args())); + + in_mat = cv::Mat(test_size * 2, CV_8UC4); + ASSERT_TRUE(compiled.canReshape()); + ASSERT_NO_THROW(compiled.reshape(descr_of(gin(in_mat)), get_compile_args())); + ASSERT_NO_THROW(compiled(in_mat, out_mat)); +} + } // namespace opencv_test