Commit cbb699ef authored by atalaman's avatar atalaman Committed by Alexander Alekhin

Merge pull request #14151 from TolyaTalamanov:at/own-mat-output-doesnt-support

G-API: own::Mat as output computation doesn't work (#14151)

* Fix bug with output own::Mat

* Fix comments to review

* Fix preprocess condition

* Fix comments to review
parent d9dac9cd
......@@ -152,17 +152,31 @@ void cv::gimpl::GExecutor::run(cv::gimpl::GRuntimeArgs &&args)
{
using cv::util::get;
const auto desc = get<cv::GMatDesc>(d.meta);
auto check_own_mat = [&desc, &args, &index]()
{
auto& out_mat = *get<cv::gapi::own::Mat*>(args.outObjs.at(index));
GAPI_Assert(out_mat.data != nullptr &&
desc.canDescribe(out_mat));
};
#if !defined(GAPI_STANDALONE)
// Building as part of OpenCV - follow OpenCV behavior
// if output buffer is not enough to hold the result, reallocate it
auto& out_mat = *get<cv::Mat*>(args.outObjs.at(index));
createMat(desc, out_mat);
// In the case of cv::Mat if output buffer is not enough to hold the result, reallocate it
if (cv::util::holds_alternative<cv::Mat*>(args.outObjs.at(index)))
{
auto& out_mat = *get<cv::Mat*>(args.outObjs.at(index));
createMat(desc, out_mat);
}
// In the case of own::Mat never reallocated, checked to perfectly fit required meta
else
{
check_own_mat();
}
#else
// Building standalone - output buffer should always exist,
// and _exact_ match our inferred metadata
auto& out_mat = *get<cv::gapi::own::Mat*>(args.outObjs.at(index));
GAPI_Assert(out_mat.data != nullptr &&
desc.canDescribe(out_mat))
check_own_mat();
#endif // !defined(GAPI_STANDALONE)
}
}
......
......@@ -298,4 +298,20 @@ TEST(GAPI_Pipeline, PipelineAllocatingKernel)
EXPECT_THROW(comp.apply(in_mat, out_mat, cv::compile_args(pkg)), std::logic_error);
}
TEST(GAPI_Pipeline, CanUseOwnMatAsOutput)
{
cv::GMat in;
cv::GComputation comp(in, cv::gapi::bitwise_not(in));
cv::Mat in_mat(3, 3, CV_8UC1);
cv::Mat out_mat(3, 3, CV_8UC1);
cv::gapi::own::Mat in_own_mat(in_mat.rows, in_mat.cols, CV_8UC1, in_mat.data);
cv::gapi::own::Mat out_own_mat(out_mat.rows, out_mat.cols, CV_8UC1, out_mat.data);
// FIXME add overload for apply(cv::gapi::own::Mat in, cv::gapi::own::Mat& out)
EXPECT_NO_THROW(comp.apply({in_own_mat}, {out_own_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