Implement cv.gin and multiple output for python

This commit is contained in:
Anatoliy Talamanov
2020-09-29 13:45:40 +03:00
parent 295afd5882
commit e998d89e88
9 changed files with 269 additions and 14 deletions
+43 -4
View File
@@ -129,15 +129,14 @@ static bool formats_are_same(const cv::GMetaArgs& metas1, const cv::GMetaArgs& m
});
}
void cv::GComputation::apply(GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args)
void cv::GComputation::recompile(GMetaArgs&& in_metas, GCompileArgs &&args)
{
const auto in_metas = descr_of(ins);
// FIXME Graph should be recompiled when GCompileArgs have changed
if (m_priv->m_lastMetas != in_metas)
{
if (m_priv->m_lastCompiled &&
m_priv->m_lastCompiled.canReshape() &&
formats_are_same(m_priv->m_lastMetas, in_metas))
m_priv->m_lastCompiled.canReshape() &&
formats_are_same(m_priv->m_lastMetas, in_metas))
{
m_priv->m_lastCompiled.reshape(in_metas, args);
}
@@ -148,6 +147,11 @@ void cv::GComputation::apply(GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&ar
}
m_priv->m_lastMetas = in_metas;
}
}
void cv::GComputation::apply(GRunArgs &&ins, GRunArgsP &&outs, GCompileArgs &&args)
{
recompile(descr_of(ins), std::move(args));
m_priv->m_lastCompiled(std::move(ins), std::move(outs));
}
@@ -165,6 +169,41 @@ void cv::GComputation::apply(const std::vector<cv::Mat> &ins,
apply(std::move(call_ins), std::move(call_outs), std::move(args));
}
// NB: This overload is called from python code
cv::GRunArgs cv::GComputation::apply(GRunArgs &&ins, GCompileArgs &&args)
{
recompile(descr_of(ins), std::move(args));
const auto& out_metas = m_priv->m_lastCompiled.outMetas();
GRunArgs run_args;
GRunArgsP outs;
run_args.reserve(out_metas.size());
outs.reserve(out_metas.size());
for (auto&& meta : out_metas)
{
switch (meta.index())
{
case cv::GMetaArg::index_of<cv::GMatDesc>():
{
run_args.emplace_back(cv::Mat{});
outs.emplace_back(&cv::util::get<cv::Mat>(run_args.back()));
break;
}
case cv::GMetaArg::index_of<cv::GScalarDesc>():
{
run_args.emplace_back(cv::Scalar{});
outs.emplace_back(&cv::util::get<cv::Scalar>(run_args.back()));
break;
}
default:
util::throw_error(std::logic_error("Only cv::GMat and cv::GScalar are supported for python output"));
}
}
m_priv->m_lastCompiled(std::move(ins), std::move(outs));
return run_args;
}
#if !defined(GAPI_STANDALONE)
void cv::GComputation::apply(cv::Mat in, cv::Mat &out, GCompileArgs &&args)
{