OpenCV  4.10.0-dev
Open Source Computer Vision
Loading...
Searching...
No Matches
Public Member Functions | List of all members
cv::GCompiled Class Reference

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>

Collaboration diagram for cv::GCompiled:

Public Member Functions

 GCompiled ()
 Constructs an empty object.
 
bool canReshape () const
 Check if the underlying backends support reshape or not.
 
const GMetaArgsmetas () const
 Vector of metadata this graph was compiled for.
 
 operator bool () const
 Check if compiled object is valid (non-empty)
 
void operator() (const std::vector< cv::Mat > &ins, const std::vector< cv::Mat > &outs)
 Execute a computation with arbitrary number of inputs/outputs.
 
void operator() (cv::Mat in, cv::Mat &out)
 Execute an unary computation.
 
void operator() (cv::Mat in, cv::Scalar &out)
 Execute an unary computation.
 
void operator() (cv::Mat in1, cv::Mat in2, cv::Mat &out)
 Execute a binary computation.
 
void operator() (cv::Mat in1, cv::Mat in2, cv::Scalar &out)
 Execute an binary computation.
 
void operator() (GRunArgs &&ins, GRunArgsP &&outs)
 Run the compiled computation, a generic version.
 
const GMetaArgsoutMetas () const
 Vector of metadata descriptions of graph outputs.
 
void prepareForNewStream ()
 Prepare inner kernels states for a new video-stream.
 
void reshape (const GMetaArgs &inMetas, const GCompileArgs &args)
 Reshape a compiled graph to support new image resolutions.
 

Detailed Description

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.

See also
GStreamingCompiled

Constructor & Destructor Documentation

◆ GCompiled()

cv::GCompiled::GCompiled ( )

Constructs an empty object.

Member Function Documentation

◆ canReshape()

bool cv::GCompiled::canReshape ( ) const

Check if the underlying backends support reshape or not.

Returns
true if supported, false otherwise.

◆ metas()

const GMetaArgs & cv::GCompiled::metas ( ) const

Vector of metadata this graph was compiled for.

Returns
Unless reshape is not supported, return value is the same vector which was passed to cv::GComputation::compile() to produce this compiled object. Otherwise, it is the latest metadata vector passed to reshape() (if that call was successful).

◆ operator bool()

cv::GCompiled::operator bool ( ) const
explicit

Check if compiled object is valid (non-empty)

Returns
true if the object is runnable (valid), false otherwise

◆ operator()() [1/6]

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.

Parameters
insvector of input cv::Mat objects to process by the computation.
outsvector 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.

◆ operator()() [2/6]

void cv::GCompiled::operator() ( cv::Mat  in,
cv::Mat 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.

Parameters
ininput cv::Mat for unary computation
outoutput cv::Mat for unary computation process.

◆ operator()() [3/6]

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.

Parameters
ininput cv::Mat for unary computation
outoutput cv::Scalar for unary computation process.

◆ operator()() [4/6]

void cv::GCompiled::operator() ( cv::Mat  in1,
cv::Mat  in2,
cv::Mat out 
)

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.

Parameters
in1first input cv::Mat for binary computation
in2second input cv::Mat for binary computation
outoutput cv::Mat for binary computation process.

◆ operator()() [5/6]

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.

Parameters
in1first input cv::Mat for binary computation
in2second input cv::Mat for binary computation
outoutput cv::Scalar for binary computation process.

◆ operator()() [6/6]

void cv::GCompiled::operator() ( GRunArgs &&  ins,
GRunArgsP &&  outs 
)

Run the compiled computation, a generic version.

Parameters
insvector of inputs to process.
outsvector 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.

Note
Don't construct GRunArgs/GRunArgsP objects manually, use cv::gin()/cvgout() wrappers instead.

◆ outMetas()

const GMetaArgs & cv::GCompiled::outMetas ( ) const

Vector of metadata descriptions of graph outputs.

Returns
vector with formats/resolutions of graph's output objects, auto-inferred from input metadata vector by operations which form this computation.
Note
GCompiled objects produced from the same cv::GComputiation graph with different input metas may return different values in this vector.

◆ prepareForNewStream()

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.

◆ reshape()

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.

Parameters
inMetasnew metadata to reshape on. Vector size and metadata shapes must match the computation's protocol.
argscompilation arguments to use.

The documentation for this class was generated from the following file: