OpenCV
4.9.0
Open Source Computer Vision
|
Represents a compiled computation (graph). Can only be used with image / data formats & resolutions it was compiled for, with some exceptions. More...
#include <opencv2/gapi/gcompiled.hpp>
Public Member Functions | |
GCompiled () | |
Constructs an empty object. More... | |
bool | canReshape () const |
Check if the underlying backends support reshape or not. More... | |
const GMetaArgs & | metas () const |
Vector of metadata this graph was compiled for. More... | |
operator bool () const | |
Check if compiled object is valid (non-empty) More... | |
void | operator() (GRunArgs &&ins, GRunArgsP &&outs) |
Run the compiled computation, a generic version. More... | |
void | operator() (cv::Mat in, cv::Mat &out) |
Execute an unary computation. More... | |
void | operator() (cv::Mat in, cv::Scalar &out) |
Execute an unary computation. More... | |
void | operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out) |
Execute a binary computation. More... | |
void | operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out) |
Execute an binary computation. More... | |
void | operator() (const std::vector< cv::Mat > &ins, const std::vector< cv::Mat > &outs) |
Execute a computation with arbitrary number of inputs/outputs. More... | |
const GMetaArgs & | outMetas () const |
Vector of metadata descriptions of graph outputs. More... | |
void | prepareForNewStream () |
Prepare inner kernels states for a new video-stream. More... | |
void | reshape (const GMetaArgs &inMetas, const GCompileArgs &args) |
Reshape a compiled graph to support new image resolutions. More... | |
Represents a compiled computation (graph). Can only be used with image / data formats & resolutions it was compiled for, with some exceptions.
This class represents a product of graph compilation (calling cv::GComputation::compile()). Objects of this class actually do data processing, and graph execution is incapsulated into objects of this class. Execution model itself depends on kernels and backends which were using during the compilation, see G-API Graph Compilation Arguments for details.
In a general case, GCompiled objects can be applied to data only in that formats/resolutions they were compiled for (see G-API Metadata Descriptors). However, if the underlying backends allow, a compiled object can be reshaped to handle data (images) of different resolution, though formats and types must remain the same.
GCompiled is very similar to std::function<>
in its semantics – running it looks like a function call in the user code.
At the moment, GCompiled objects are not reentrant – generally, the objects are stateful since graph execution itself is a stateful process and this state is now maintained in GCompiled's own memory (not on the process stack).
At the same time, two different GCompiled objects produced from the single cv::GComputation are completely independent and can be used concurrently.
cv::GCompiled::GCompiled | ( | ) |
Constructs an empty object.
bool cv::GCompiled::canReshape | ( | ) | const |
Check if the underlying backends support reshape or not.
const GMetaArgs& cv::GCompiled::metas | ( | ) | const |
Vector of metadata this graph was compiled for.
|
explicit |
Check if compiled object is valid (non-empty)
Run the compiled computation, a generic version.
ins | vector of inputs to process. |
outs | vector of outputs to produce. |
Input/output vectors must have the same number of elements as defined in the cv::GComputation protocol (at the moment of its construction). Shapes of elements also must conform to protocol (e.g. cv::Mat needs to be passed where cv::GMat has been declared as input, and so on). Run-time exception is generated otherwise.
Objects in output vector may remain empty (like cv::Mat) – G-API will automatically initialize output objects to proper formats.
void cv::GCompiled::operator() | ( | cv::Mat | in, |
cv::Scalar & | out | ||
) |
Execute an unary computation.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
in | input cv::Mat for unary computation |
out | output cv::Scalar for unary computation process. |
Execute a binary computation.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void cv::GCompiled::operator() | ( | cv::Mat | in1, |
cv::Mat | in2, | ||
cv::Scalar & | out | ||
) |
Execute an binary computation.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
in1 | first input cv::Mat for binary computation |
in2 | second input cv::Mat for binary computation |
out | output cv::Scalar for binary computation process. |
void cv::GCompiled::operator() | ( | const std::vector< cv::Mat > & | ins, |
const std::vector< cv::Mat > & | outs | ||
) |
Execute a computation with arbitrary number of inputs/outputs.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
ins | vector of input cv::Mat objects to process by the computation. |
outs | vector of output cv::Mat objects to produce by the computation. |
Numbers of elements in ins/outs vectors must match numbers of inputs/outputs which were used to define the source GComputation.
const GMetaArgs& cv::GCompiled::outMetas | ( | ) | const |
Vector of metadata descriptions of graph outputs.
void cv::GCompiled::prepareForNewStream | ( | ) |
Prepare inner kernels states for a new video-stream.
GCompiled objects may be used to process video streams frame by frame. In this case, a GCompiled is called on every image frame individually. Starting OpenCV 4.4, some kernels in the graph may have their internal states (see GAPI_OCV_KERNEL_ST for the OpenCV backend). In this case, if user starts processing another video stream with this GCompiled, this method needs to be called to let kernels re-initialize their internal states to a new video stream.
void cv::GCompiled::reshape | ( | const GMetaArgs & | inMetas, |
const GCompileArgs & | args | ||
) |
Reshape a compiled graph to support new image resolutions.
Throws an exception if an error occurs.
inMetas | new metadata to reshape on. Vector size and metadata shapes must match the computation's protocol. |
args | compilation arguments to use. |