pub struct GComputation { /* private fields */ }
Expand description
GComputation class represents a captured computation graph. GComputation objects form boundaries for expression code user writes with G-API, allowing to compile and execute it.
G-API computations are defined with input/output data
objects. G-API will track automatically which operations connect
specified outputs to the inputs, forming up a call graph to be
executed. The below example expresses calculation of Sobel operator
for edge detection ():
Full pipeline can be now captured with this object declaration:
Input/output data objects on which a call graph should be reconstructed are passed using special wrappers cv::GIn and cv::GOut. G-API will track automatically which operations form a path from inputs to outputs and build the execution graph appropriately.
Note that cv::GComputation doesn’t take ownership on data objects it is defined. Moreover, multiple GComputation objects may be defined on the same expressions, e.g. a smaller pipeline which expects that image gradients are already pre-calculated may be defined like this:
The resulting graph would expect two inputs and produce one output. In this case, it doesn’t matter if gx/gy data objects are results of cv::gapi::Sobel operators – G-API will stop unrolling expressions and building the underlying graph one reaching this data objects.
The way how GComputation is defined is important as its definition specifies graph protocol – the way how the graph should be used. Protocol is defined by number of inputs, number of outputs, and shapes of inputs and outputs.
In the above example, sobelEdge expects one Mat on input and produces one Mat; while sobelEdgeSub expects two Mats on input and produces one Mat. GComputation’s protocol defines how other computation methods should be used – cv::GComputation::compile() and cv::GComputation::apply(). For example, if a graph is defined on two GMat inputs, two cv::Mat objects have to be passed to apply() for execution. GComputation checks protocol correctness in runtime so passing a different number of objects in apply() or passing cv::Scalar instead of cv::Mat there would compile well as a C++ source but raise an exception in run-time. G-API also comes with a typed wrapper cv::GComputationT<> which introduces this type-checking in compile-time.
cv::GComputation itself is a thin object which just captures what the graph is. The compiled graph (which actually process data) is represented by class GCompiled. Use compile() method to generate a compiled graph with given compile options. cv::GComputation can also be used to process data with implicit graph compilation on-the-fly, see apply() for details.
GComputation is a reference-counted object – once defined, all its copies will refer to the same instance.
§See also
GCompiled
Implementations§
Source§impl GComputation
impl GComputation
Sourcepub fn new(in_: impl GMatTrait, out: impl GMatTrait) -> Result<GComputation>
pub fn new(in_: impl GMatTrait, out: impl GMatTrait) -> Result<GComputation>
Defines an unary (one input – one output) computation
Generic GComputation constructor.
Constructs a new graph with a given protocol, specified as a flow of operations connecting input/output objects. Throws if the passed boundaries are invalid, e.g. if there’s no functional dependency (path) between given outputs and inputs.
§Parameters
- ins: Input data vector.
- outs: Output data vector.
Note: Don’t construct GProtoInputArgs/GProtoOutputArgs objects directly, use cv::GIn()/cv::GOut() wrapper functions instead.
§See also
[gapi_data_objects]
§Overloaded parameters
- in: input GMat of the defined unary computation
- out: output GMat of the defined unary computation
Sourcepub fn new_1(
in_: impl GMatTrait,
out: impl GScalarTrait,
) -> Result<GComputation>
pub fn new_1( in_: impl GMatTrait, out: impl GScalarTrait, ) -> Result<GComputation>
Defines an unary (one input – one output) computation
Generic GComputation constructor.
Constructs a new graph with a given protocol, specified as a flow of operations connecting input/output objects. Throws if the passed boundaries are invalid, e.g. if there’s no functional dependency (path) between given outputs and inputs.
§Parameters
- ins: Input data vector.
- outs: Output data vector.
Note: Don’t construct GProtoInputArgs/GProtoOutputArgs objects directly, use cv::GIn()/cv::GOut() wrapper functions instead.
§See also
[gapi_data_objects]
§Overloaded parameters
- in: input GMat of the defined unary computation
- out: output GScalar of the defined unary computation
Sourcepub fn new_2(
in1: impl GMatTrait,
in2: impl GMatTrait,
out: impl GMatTrait,
) -> Result<GComputation>
pub fn new_2( in1: impl GMatTrait, in2: impl GMatTrait, out: impl GMatTrait, ) -> Result<GComputation>
Defines a binary (two inputs – one output) computation
Generic GComputation constructor.
Constructs a new graph with a given protocol, specified as a flow of operations connecting input/output objects. Throws if the passed boundaries are invalid, e.g. if there’s no functional dependency (path) between given outputs and inputs.
§Parameters
- ins: Input data vector.
- outs: Output data vector.
Note: Don’t construct GProtoInputArgs/GProtoOutputArgs objects directly, use cv::GIn()/cv::GOut() wrapper functions instead.
§See also
[gapi_data_objects]
§Overloaded parameters
- in1: first input GMat of the defined binary computation
- in2: second input GMat of the defined binary computation
- out: output GMat of the defined binary computation
Sourcepub fn new_3(
in1: impl GMatTrait,
in2: impl GMatTrait,
out: impl GScalarTrait,
) -> Result<GComputation>
pub fn new_3( in1: impl GMatTrait, in2: impl GMatTrait, out: impl GScalarTrait, ) -> Result<GComputation>
Defines a binary (two inputs – one output) computation
Generic GComputation constructor.
Constructs a new graph with a given protocol, specified as a flow of operations connecting input/output objects. Throws if the passed boundaries are invalid, e.g. if there’s no functional dependency (path) between given outputs and inputs.
§Parameters
- ins: Input data vector.
- outs: Output data vector.
Note: Don’t construct GProtoInputArgs/GProtoOutputArgs objects directly, use cv::GIn()/cv::GOut() wrapper functions instead.
§See also
[gapi_data_objects]
§Overloaded parameters
- in1: first input GMat of the defined binary computation
- in2: second input GMat of the defined binary computation
- out: output GScalar of the defined binary computation
Sourcepub fn new_4(ins: &Vector<GMat>, outs: &Vector<GMat>) -> Result<GComputation>
pub fn new_4(ins: &Vector<GMat>, outs: &Vector<GMat>) -> Result<GComputation>
Defines a computation with arbitrary input/output number.
Generic GComputation constructor.
Constructs a new graph with a given protocol, specified as a flow of operations connecting input/output objects. Throws if the passed boundaries are invalid, e.g. if there’s no functional dependency (path) between given outputs and inputs.
§Parameters
- ins: Input data vector.
- outs: Output data vector.
Note: Don’t construct GProtoInputArgs/GProtoOutputArgs objects directly, use cv::GIn()/cv::GOut() wrapper functions instead.
§See also
[gapi_data_objects]
§Overloaded parameters
- ins: vector of inputs GMats for this computation
- outs: vector of outputs GMats for this computation
Use this overload for cases when number of computation inputs/outputs is not known in compile-time – e.g. when graph is programmatically generated to build an image pyramid with the given number of levels, etc.
Trait Implementations§
Source§impl Boxed for GComputation
impl Boxed for GComputation
Source§unsafe fn from_raw(
ptr: <GComputation as OpenCVFromExtern>::ExternReceive,
) -> Self
unsafe fn from_raw( ptr: <GComputation as OpenCVFromExtern>::ExternReceive, ) -> Self
Source§fn into_raw(self) -> <GComputation as OpenCVTypeExternContainer>::ExternSendMut
fn into_raw(self) -> <GComputation as OpenCVTypeExternContainer>::ExternSendMut
Source§fn as_raw(&self) -> <GComputation as OpenCVTypeExternContainer>::ExternSend
fn as_raw(&self) -> <GComputation as OpenCVTypeExternContainer>::ExternSend
Source§fn as_raw_mut(
&mut self,
) -> <GComputation as OpenCVTypeExternContainer>::ExternSendMut
fn as_raw_mut( &mut self, ) -> <GComputation as OpenCVTypeExternContainer>::ExternSendMut
Source§impl Debug for GComputation
impl Debug for GComputation
Source§impl Drop for GComputation
impl Drop for GComputation
Source§impl GComputationTrait for GComputation
impl GComputationTrait for GComputation
fn as_raw_mut_GComputation(&mut self) -> *mut c_void
Source§fn apply(
&mut self,
callback: &impl Detail_ExtractArgsCallbackTraitConst,
args: GCompileArgs,
) -> Result<GRunArgs>
fn apply( &mut self, callback: &impl Detail_ExtractArgsCallbackTraitConst, args: GCompileArgs, ) -> Result<GRunArgs>
Source§fn apply_def(
&mut self,
callback: &impl Detail_ExtractArgsCallbackTraitConst,
) -> Result<GRunArgs>
fn apply_def( &mut self, callback: &impl Detail_ExtractArgsCallbackTraitConst, ) -> Result<GRunArgs>
Source§fn apply_1(
&mut self,
ins: &Vector<Mat>,
outs: &Vector<Mat>,
args: GCompileArgs,
) -> Result<()>
fn apply_1( &mut self, ins: &Vector<Mat>, outs: &Vector<Mat>, args: GCompileArgs, ) -> Result<()>
Source§fn apply_def_1(&mut self, ins: &Vector<Mat>, outs: &Vector<Mat>) -> Result<()>
fn apply_def_1(&mut self, ins: &Vector<Mat>, outs: &Vector<Mat>) -> Result<()>
Source§fn apply_2(
&mut self,
in_: impl MatTrait,
out: &mut impl MatTrait,
args: GCompileArgs,
) -> Result<()>
fn apply_2( &mut self, in_: impl MatTrait, out: &mut impl MatTrait, args: GCompileArgs, ) -> Result<()>
Source§fn apply_def_2(
&mut self,
in_: impl MatTrait,
out: &mut impl MatTrait,
) -> Result<()>
fn apply_def_2( &mut self, in_: impl MatTrait, out: &mut impl MatTrait, ) -> Result<()>
Source§fn apply_3(
&mut self,
in_: impl MatTrait,
out: &mut Scalar,
args: GCompileArgs,
) -> Result<()>
fn apply_3( &mut self, in_: impl MatTrait, out: &mut Scalar, args: GCompileArgs, ) -> Result<()>
Source§fn apply_def_3(&mut self, in_: impl MatTrait, out: &mut Scalar) -> Result<()>
fn apply_def_3(&mut self, in_: impl MatTrait, out: &mut Scalar) -> Result<()>
Source§fn apply_4(
&mut self,
in1: impl MatTrait,
in2: impl MatTrait,
out: &mut impl MatTrait,
args: GCompileArgs,
) -> Result<()>
fn apply_4( &mut self, in1: impl MatTrait, in2: impl MatTrait, out: &mut impl MatTrait, args: GCompileArgs, ) -> Result<()>
Source§fn apply_def_4(
&mut self,
in1: impl MatTrait,
in2: impl MatTrait,
out: &mut impl MatTrait,
) -> Result<()>
fn apply_def_4( &mut self, in1: impl MatTrait, in2: impl MatTrait, out: &mut impl MatTrait, ) -> Result<()>
Source§fn apply_5(
&mut self,
in1: impl MatTrait,
in2: impl MatTrait,
out: &mut Scalar,
args: GCompileArgs,
) -> Result<()>
fn apply_5( &mut self, in1: impl MatTrait, in2: impl MatTrait, out: &mut Scalar, args: GCompileArgs, ) -> Result<()>
Source§fn apply_def_5(
&mut self,
in1: impl MatTrait,
in2: impl MatTrait,
out: &mut Scalar,
) -> Result<()>
fn apply_def_5( &mut self, in1: impl MatTrait, in2: impl MatTrait, out: &mut Scalar, ) -> Result<()>
Source§fn apply_6(
&mut self,
ins: &Vector<Mat>,
outs: &mut Vector<Mat>,
args: GCompileArgs,
) -> Result<()>
fn apply_6( &mut self, ins: &Vector<Mat>, outs: &mut Vector<Mat>, args: GCompileArgs, ) -> Result<()>
Source§fn apply_def_6(
&mut self,
ins: &Vector<Mat>,
outs: &mut Vector<Mat>,
) -> Result<()>
fn apply_def_6( &mut self, ins: &Vector<Mat>, outs: &mut Vector<Mat>, ) -> Result<()>
Source§fn compile_streaming(
&mut self,
args: GCompileArgs,
) -> Result<GStreamingCompiled>
fn compile_streaming( &mut self, args: GCompileArgs, ) -> Result<GStreamingCompiled>
Source§fn compile_streaming_def(&mut self) -> Result<GStreamingCompiled>
fn compile_streaming_def(&mut self) -> Result<GStreamingCompiled>
Source§fn compile_streaming_1(
&mut self,
callback: &impl Detail_ExtractMetaCallbackTraitConst,
args: GCompileArgs,
) -> Result<GStreamingCompiled>
fn compile_streaming_1( &mut self, callback: &impl Detail_ExtractMetaCallbackTraitConst, args: GCompileArgs, ) -> Result<GStreamingCompiled>
Source§fn compile_streaming_def_1(
&mut self,
callback: &impl Detail_ExtractMetaCallbackTraitConst,
) -> Result<GStreamingCompiled>
fn compile_streaming_def_1( &mut self, callback: &impl Detail_ExtractMetaCallbackTraitConst, ) -> Result<GStreamingCompiled>
Source§impl GComputationTraitConst for GComputation
impl GComputationTraitConst for GComputation
fn as_raw_GComputation(&self) -> *const c_void
impl Send for GComputation
Auto Trait Implementations§
impl Freeze for GComputation
impl RefUnwindSafe for GComputation
impl !Sync for GComputation
impl Unpin for GComputation
impl UnwindSafe for GComputation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
impl<Mat> ModifyInplace for Matwhere
Mat: Boxed,
Source§unsafe fn modify_inplace<Res>(
&mut self,
f: impl FnOnce(&Mat, &mut Mat) -> Res,
) -> Res
unsafe fn modify_inplace<Res>( &mut self, f: impl FnOnce(&Mat, &mut Mat) -> Res, ) -> Res
Mat
or another similar object. By passing
a mutable reference to the Mat
to this function your closure will get called with the read reference and a write references
to the same Mat
. This is unsafe in a general case as it leads to having non-exclusive mutable access to the internal data,
but it can be useful for some performance sensitive operations. One example of an OpenCV function that allows such in-place
modification is imgproc::threshold
. Read more