render.hpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 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 render(cv::Mat& y_plane,
  85. cv::Mat& uv_plane,
  86. const Prims& prims,
  87. cv::GCompileArgs&& args = {});
  88. G_TYPED_KERNEL_M(GRenderNV12, <GMat2(cv::GMat,cv::GMat,cv::GArray<wip::draw::Prim>)>, "org.opencv.render.nv12")
  89. {
  90. static GMatDesc2 outMeta(GMatDesc y_plane, GMatDesc uv_plane, GArrayDesc)
  91. {
  92. return std::make_tuple(y_plane, uv_plane);
  93. }
  94. };
  95. G_TYPED_KERNEL(GRenderBGR, <cv::GMat(cv::GMat,cv::GArray<wip::draw::Prim>)>, "org.opencv.render.bgr")
  96. {
  97. static GMatDesc outMeta(GMatDesc bgr, GArrayDesc)
  98. {
  99. return bgr;
  100. }
  101. };
  102. /** @brief Renders on 3 channels input
  103. Output image must be 8-bit unsigned planar 3-channel image
  104. @param src input image: 8-bit unsigned 3-channel image @ref CV_8UC3
  105. @param prims draw primitives
  106. */
  107. GAPI_EXPORTS GMat render3ch(const GMat& src, const GArray<Prim>& prims);
  108. /** @brief Renders on two planes
  109. Output y image must be 8-bit unsigned planar 1-channel image @ref CV_8UC1
  110. uv image must be 8-bit unsigned planar 2-channel image @ref CV_8UC2
  111. @param y input image: 8-bit unsigned 1-channel image @ref CV_8UC1
  112. @param uv input image: 8-bit unsigned 2-channel image @ref CV_8UC2
  113. @param prims draw primitives
  114. */
  115. GAPI_EXPORTS GMat2 renderNV12(const GMat& y,
  116. const GMat& uv,
  117. const GArray<Prim>& prims);
  118. //! @} gapi_draw_api
  119. } // namespace draw
  120. } // namespace wip
  121. namespace render
  122. {
  123. namespace ocv
  124. {
  125. GAPI_EXPORTS cv::gapi::GKernelPackage kernels();
  126. } // namespace ocv
  127. } // namespace render
  128. } // namespace gapi
  129. namespace detail
  130. {
  131. template<> struct CompileArgTag<cv::gapi::wip::draw::freetype_font>
  132. {
  133. static const char* tag() { return "gapi.freetype_font"; }
  134. };
  135. } // namespace detail
  136. } // namespace cv
  137. #endif // OPENCV_GAPI_RENDER_HPP