render.hpp 6.1 KB

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