OpenCV Graph API (or G-API) is a new OpenCV module targeted to make regular image processing fast and portable. These two goals are achieved by introducing a new graph-based model of execution.
G-API is a special module in OpenCV – in contrast with the majority of other main modules, this one acts as a framework rather than some specific CV algorithm. G-API provides means to define CV operations, construct graphs (in form of expressions) using it, and finally implement and run the operations for a particular backend.
G-API documentation is organized into the following chapters:
The motivation behind G-API and its goals.
General overview of G-API architecture and its major internal components.
Learn how to introduce new operations in G-API and implement it for various backends.
Low-level implementation details of G-API, for those who want to contribute.
A very basic example of G-API pipeline is shown below:
G-API is a separate OpenCV module so its header files have to be included explicitly. The first four lines of
create and initialize OpenCV's standard video capture object, which fetches video frames from either an attached camera or a specified file.
G-API pipeline is constructed next. In fact, it is a series of G-API operation calls on
data. The important aspect of G-API is that this code block is just a declaration of actions, but not the actions themselves. No processing happens at this point, G-API only tracks which operations form pipeline and how it is connected. G-API
(here it is
) are used to connect operations each other.
signalling that it is a beginning of computation.
After G-API code is written, it is captured into a call graph with instantiation of
object. This object takes input/output data references (in this example,
objects, respectively) as parameters and reconstructs the call graph based on all the data flow between
is a thin object in sense that it just captures which operations form up a computation. However, it can be used to execute computations – in the following processing loop, every captured frame (a
) is passed to
cv::GComputation::apply() is a polimorphic method which accepts a variadic number of arguments. Since this computation is defined on one input, one output, a special overload of cv::GComputation::apply() is used to pass input data and get output data.
内部， cv::GComputation::apply() compiles the captured graph for the given input parameters and executes the compiled graph on data immediately.
There is a number important concepts can be outlines with this examle:
见 tutorials and porting examples to learn more on various G-API features and concepts.