1// This file is part of OpenCV project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://opencv.org/license.html.
4//
5// Copyright (C) 2018-2020 Intel Corporation
6
7
8#ifndef OPENCV_GAPI_RENDER_HPP
9#define OPENCV_GAPI_RENDER_HPP
10
11#include <opencv2/gapi/render/render_types.hpp>
12
13#include <opencv2/gapi.hpp>
14
15/** \defgroup gapi_draw G-API Drawing and composition functionality
16 * @{
17 *
18 * @brief Functions for in-graph drawing.
19 *
20 * @note This is a Work in Progress functionality and APIs may
21 * change in the future releases.
22 *
23 * G-API can do some in-graph drawing with a generic operations and a
24 * set of [rendering primitives](@ref gapi_draw_prims).
25 * In contrast with traditional OpenCV, in G-API user need to form a
26 * *rendering list* of primitives to draw. This list can be built
27 * manually or generated within a graph. This list is passed to
28 * [special operations or functions](@ref gapi_draw_api) where all
29 * primitives are interpreted and applied to the image.
30 *
31 * For example, in a complex pipeline a list of detected objects
32 * can be translated in-graph to a list of cv::gapi::wip::draw::Rect
33 * primitives to highlight those with bounding boxes, or a list of
34 * detected faces can be translated in-graph to a list of
35 * cv::gapi::wip::draw::Mosaic primitives to hide sensitive content
36 * or protect privacy.
37 *
38 * Like any other operations, rendering in G-API can be reimplemented
39 * by different backends. Currently only an OpenCV-based backend is
40 * available.
41 *
42 * In addition to the graph-level operations, there are also regular
43 * (immediate) OpenCV-like functions are available -- see
44 * cv::gapi::wip::draw::render(). These functions are just wrappers
45 * over regular G-API and build the rendering graphs on the fly, so
46 * take compilation arguments as parameters.
47 *
48 * Currently this API is more machine-oriented than human-oriented.
49 * The main purpose is to translate a set of domain-specific objects
50 * to a list of primitives to draw. For example, in order to generate
51 * a picture like this:
52 *
53 * ![](modules/gapi/doc/pics/render_example.png)
54 *
55 * Rendering list needs to be generated as follows:
56 *
57 * @include modules/gapi/samples/draw_example.cpp
58 *
59 * @defgroup gapi_draw_prims Drawing primitives
60 * @defgroup gapi_draw_api Drawing operations and functions
61 * @}
62 */
63
64namespace cv
65{
66namespace gapi
67{
68namespace wip
69{
70namespace draw
71{
72
73using GMat2 = std::tuple<cv::GMat,cv::GMat>;
74using GMatDesc2 = std::tuple<cv::GMatDesc,cv::GMatDesc>;
75
76//! @addtogroup gapi_draw_api
77//! @{
78/** @brief The function renders on the input image passed drawing primitivies
79
80@param bgr input image: 8-bit unsigned 3-channel image @ref CV_8UC3.
81@param prims vector of drawing primitivies
82@param args graph compile time parameters
83*/
84void GAPI_EXPORTS_W render(cv::Mat& bgr,
85 const Prims& prims,
86 cv::GCompileArgs&& args = {});
87
88/** @brief The function renders on two NV12 planes passed drawing primitivies
89
90@param y_plane input image: 8-bit unsigned 1-channel image @ref CV_8UC1.
91@param uv_plane input image: 8-bit unsigned 2-channel image @ref CV_8UC2.
92@param prims vector of drawing primitivies
93@param args graph compile time parameters
94*/
95void GAPI_EXPORTS_W render(cv::Mat& y_plane,
96 cv::Mat& uv_plane,
97 const Prims& prims,
98 cv::GCompileArgs&& args = {});
99
100/** @brief The function renders on the input media frame passed drawing primitivies
101
102@param frame input Media Frame : @ref cv::MediaFrame.
103@param prims vector of drawing primitivies
104@param args graph compile time parameters
105*/
106void GAPI_EXPORTS render(cv::MediaFrame& frame,
107 const Prims& prims,
108 cv::GCompileArgs&& args = {});
109
110
111G_TYPED_KERNEL_M(GRenderNV12, <GMat2(cv::GMat,cv::GMat,cv::GArray<wip::draw::Prim>)>, "org.opencv.render.nv12")
112{
113 static GMatDesc2 outMeta(GMatDesc y_plane, GMatDesc uv_plane, GArrayDesc)
114 {
115 return std::make_tuple(args&: y_plane, args&: uv_plane);
116 }
117};
118
119G_TYPED_KERNEL(GRenderBGR, <cv::GMat(cv::GMat,cv::GArray<wip::draw::Prim>)>, "org.opencv.render.bgr")
120{
121 static GMatDesc outMeta(GMatDesc bgr, GArrayDesc)
122 {
123 return bgr;
124 }
125};
126
127G_TYPED_KERNEL(GRenderFrame, <cv::GFrame(cv::GFrame, cv::GArray<wip::draw::Prim>)>, "org.opencv.render.frame")
128{
129 static GFrameDesc outMeta(GFrameDesc desc, GArrayDesc)
130 {
131 return desc;
132 }
133};
134
135/** @brief Renders on 3 channels input
136
137Output image must be 8-bit unsigned planar 3-channel image
138
139@param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3
140@param prims draw primitives
141*/
142GAPI_EXPORTS_W GMat render3ch(const GMat& src, const GArray<Prim>& prims);
143
144/** @brief Renders on two planes
145
146Output y image must be 8-bit unsigned planar 1-channel image @ref CV_8UC1
147uv image must be 8-bit unsigned planar 2-channel image @ref CV_8UC2
148
149@param y input image: 8-bit unsigned 1-channel image @ref CV_8UC1
150@param uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2
151@param prims draw primitives
152*/
153GAPI_EXPORTS_W GMat2 renderNV12(const GMat& y,
154 const GMat& uv,
155 const GArray<Prim>& prims);
156
157/** @brief Renders Media Frame
158
159Output media frame frame cv::MediaFrame
160
161@param m_frame input image: cv::MediaFrame @ref cv::MediaFrame
162@param prims draw primitives
163*/
164GAPI_EXPORTS GFrame renderFrame(const GFrame& m_frame,
165 const GArray<Prim>& prims);
166
167//! @} gapi_draw_api
168
169} // namespace draw
170} // namespace wip
171
172/**
173 * @brief This namespace contains G-API CPU rendering backend functions,
174 * structures, and symbols. See @ref gapi_draw for details.
175 */
176namespace render
177{
178namespace ocv
179{
180 GAPI_EXPORTS_W cv::GKernelPackage kernels();
181
182} // namespace ocv
183} // namespace render
184} // namespace gapi
185
186namespace detail
187{
188 template<> struct CompileArgTag<cv::gapi::wip::draw::freetype_font>
189 {
190 static const char* tag() { return "gapi.freetype_font"; }
191 };
192} // namespace detail
193
194} // namespace cv
195
196#endif // OPENCV_GAPI_RENDER_HPP
197

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of opencv/modules/gapi/include/opencv2/gapi/render/render.hpp