mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #18493 from TolyaTalamanov:at/wrap-streaming
[G-API Wrap streaming * Wrap streaming * Fix build * Add comments * Remove comment * Fix comments to review * Add test for python pull overload
This commit is contained in:
committed by
GitHub
parent
06a09d5991
commit
0d3e05f9b3
@@ -448,6 +448,14 @@ cv::GStreamingCompiled cv::gimpl::GCompiler::produceStreamingCompiled(GPtr &&pg)
|
||||
outMetas = GModel::ConstGraph(*pg).metadata().get<OutputMeta>().outMeta;
|
||||
}
|
||||
|
||||
auto out_desc = GModel::ConstGraph(*pg).metadata().get<cv::gimpl::Protocol>().outputs;
|
||||
GShapes out_shapes;
|
||||
for (auto&& desc : out_desc)
|
||||
{
|
||||
out_shapes.push_back(desc.shape);
|
||||
}
|
||||
compiled.priv().setOutShapes(std::move(out_shapes));
|
||||
|
||||
std::unique_ptr<GStreamingExecutor> pE(new GStreamingExecutor(std::move(pg),
|
||||
m_args));
|
||||
if (!m_metas.empty() && !outMetas.empty())
|
||||
|
||||
@@ -111,6 +111,39 @@ bool cv::GStreamingCompiled::pull(cv::GRunArgsP &&outs)
|
||||
return m_priv->pull(std::move(outs));
|
||||
}
|
||||
|
||||
std::tuple<bool, cv::GRunArgs> cv::GStreamingCompiled::pull()
|
||||
{
|
||||
GRunArgs run_args;
|
||||
GRunArgsP outs;
|
||||
const auto& out_shapes = m_priv->outShapes();
|
||||
run_args.reserve(out_shapes.size());
|
||||
outs.reserve(out_shapes.size());
|
||||
|
||||
for (auto&& shape : out_shapes)
|
||||
{
|
||||
switch (shape)
|
||||
{
|
||||
case cv::GShape::GMAT:
|
||||
{
|
||||
run_args.emplace_back(cv::Mat{});
|
||||
outs.emplace_back(&cv::util::get<cv::Mat>(run_args.back()));
|
||||
break;
|
||||
}
|
||||
case cv::GShape::GSCALAR:
|
||||
{
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
bool is_over = m_priv->pull(std::move(outs));
|
||||
return std::make_tuple(is_over, run_args);
|
||||
}
|
||||
|
||||
bool cv::GStreamingCompiled::try_pull(cv::GRunArgsP &&outs)
|
||||
{
|
||||
return m_priv->try_pull(std::move(outs));
|
||||
|
||||
@@ -27,6 +27,7 @@ class GAPI_EXPORTS GStreamingCompiled::Priv
|
||||
GMetaArgs m_metas; // passed by user
|
||||
GMetaArgs m_outMetas; // inferred by compiler
|
||||
std::unique_ptr<cv::gimpl::GStreamingExecutor> m_exec;
|
||||
GShapes m_out_shapes;
|
||||
|
||||
public:
|
||||
void setup(const GMetaArgs &metaArgs,
|
||||
@@ -45,6 +46,11 @@ public:
|
||||
void stop();
|
||||
|
||||
bool running() const;
|
||||
|
||||
// NB: std::tuple<bool, cv::GRunArgs> pull() creates GRunArgs for outputs,
|
||||
// so need to know out shapes to create corresponding GRunArg
|
||||
void setOutShapes(GShapes shapes) { m_out_shapes = std::move(shapes); }
|
||||
const GShapes& outShapes() const { return m_out_shapes; }
|
||||
};
|
||||
|
||||
} // namespace cv
|
||||
|
||||
Reference in New Issue
Block a user