OpenCV  5.0.0alpha
Open Source Computer Vision
Loading...
Searching...
No Matches
cv::GComputationT< typename > Class Template Reference

This class is a typed wrapper over a regular GComputation. More...

Collaboration diagram for cv::GComputationT< typename >:

Detailed Description

template<typename>
class cv::GComputationT< typename >

This class is a typed wrapper over a regular GComputation.

std::function<>-like template parameter specifies the graph signature so methods so the object's constructor, methods like apply() and the derived GCompiledT::operator() also become typed.

There is no need to use cv::gin() or cv::gout() modifiers with objects of this class. Instead, all input arguments are followed by all output arguments in the order from the template argument signature.

Refer to the following example. Regular (untyped) code is written this way:

// Untyped G-API ///////////////////////////////////////////////////////////
cv::GComputation cvtU([]()
{
cv::GMat in1, in2;
cv::GMat out = cv::gapi::add(in1, in2);
return cv::GComputation({in1, in2}, {out});
});
std::vector<cv::Mat> u_ins = {in_mat1, in_mat2};
std::vector<cv::Mat> u_outs = {out_mat_untyped};
cvtU.apply(u_ins, u_outs);

Here:

  • cv::GComputation object is created with a lambda constructor where it is defined as a two-input, one-output graph.
  • Its method apply() in fact takes arbitrary number of arguments (as vectors) so user can pass wrong number of inputs/outputs here. C++ compiler wouldn't notice that since the cv::GComputation API is polymorphic, and only a run-time error will be generated.

Now the same code written with typed API:

// Typed G-API /////////////////////////////////////////////////////////////
{
return m1+m2;
});
cvtT.apply(in_mat1, in_mat2, out_mat_typed1);
auto cvtTC = cvtT.compile(cv::descr_of(in_mat1), cv::descr_of(in_mat2));
cvtTC(in_mat1, in_mat2, out_mat_typed2);

The key difference is:

  • Now the constructor lambda must take parameters and must return values as defined in the GComputationT<> signature.
  • Its method apply() does not require any extra specifiers to separate input arguments from the output ones
  • A GCompiledT (compilation product) takes input/output arguments with no extra specifiers as well.

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