Commit 304e3ac1 authored by Andrey Golubev's avatar Andrey Golubev Committed by Maksim Shabunin

G-API: fix Fluid reshape with unused nodes (Merge pull request #15115)

* G-API: fix fluid reshape with unused nodes

* Update test names

* Add FIXME for future improvement
parent 778f42ad
......@@ -1145,7 +1145,16 @@ void cv::gimpl::GFluidExecutable::makeReshape(const std::vector<gapi::own::Rect>
// 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<FluidUnit>().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());
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment