gframe.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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) 2020 Intel Corporation
  6. #ifndef OPENCV_GAPI_GFRAME_HPP
  7. #define OPENCV_GAPI_GFRAME_HPP
  8. #include <ostream>
  9. #include <memory> // std::shared_ptr
  10. #include <opencv2/gapi/opencv_includes.hpp>
  11. #include <opencv2/gapi/gcommon.hpp> // GShape
  12. #include <opencv2/gapi/gmat.hpp>
  13. #include <opencv2/gapi/own/assert.hpp>
  14. // TODO GAPI_EXPORTS or so
  15. namespace cv
  16. {
  17. // Forward declaration; GNode and GOrigin are an internal
  18. // (user-inaccessible) classes.
  19. class GNode;
  20. struct GOrigin;
  21. /** \addtogroup gapi_data_objects
  22. * @{
  23. */
  24. /**
  25. * @brief GFrame class represents an image or media frame in the graph.
  26. *
  27. * GFrame doesn't store any data itself, instead it describes a
  28. * functional relationship between operations consuming and producing
  29. * GFrame objects.
  30. *
  31. * GFrame is introduced to handle various media formats (e.g., NV12 or
  32. * I420) under the same type. Various image formats may differ in the
  33. * number of planes (e.g. two for NV12, three for I420) and the pixel
  34. * layout inside. GFrame type allows to handle these media formats in
  35. * the graph uniformly -- the graph structure will not change if the
  36. * media format changes, e.g. a different camera or decoder is used
  37. * with the same graph. G-API provides a number of operations which
  38. * operate directly on GFrame, like `infer<>()` or
  39. * renderFrame(); these operations are expected to handle different
  40. * media formats inside. There is also a number of accessor
  41. * operations like BGR(), Y(), UV() -- these operations provide
  42. * access to frame's data in the familiar cv::GMat form, which can be
  43. * used with the majority of the existing G-API operations. These
  44. * accessor functions may perform color space conversion on the fly if
  45. * the image format of the GFrame they are applied to differs from the
  46. * operation's semantic (e.g. the BGR() accessor is called on an NV12
  47. * image frame).
  48. *
  49. * GFrame is a virtual counterpart of cv::MediaFrame.
  50. *
  51. * @sa cv::MediaFrame, cv::GFrameDesc, BGR(), Y(), UV(), infer<>().
  52. */
  53. class GAPI_EXPORTS_W_SIMPLE GFrame
  54. {
  55. public:
  56. /**
  57. * @brief Constructs an empty GFrame
  58. *
  59. * Normally, empty G-API data objects denote a starting point of
  60. * the graph. When an empty GFrame is assigned to a result of some
  61. * operation, it obtains a functional link to this operation (and
  62. * is not empty anymore).
  63. */
  64. GAPI_WRAP GFrame(); // Empty constructor
  65. /// @private
  66. GFrame(const GNode &n, std::size_t out); // Operation result constructor
  67. /// @private
  68. GOrigin& priv(); // Internal use only
  69. /// @private
  70. const GOrigin& priv() const; // Internal use only
  71. private:
  72. std::shared_ptr<GOrigin> m_priv;
  73. };
  74. /** @} */
  75. enum class MediaFormat: int
  76. {
  77. BGR = 0,
  78. NV12,
  79. GRAY,
  80. };
  81. /**
  82. * \addtogroup gapi_meta_args
  83. * @{
  84. */
  85. struct GAPI_EXPORTS GFrameDesc
  86. {
  87. MediaFormat fmt;
  88. cv::Size size;
  89. bool operator== (const GFrameDesc &) const;
  90. };
  91. static inline GFrameDesc empty_gframe_desc() { return GFrameDesc{}; }
  92. /** @} */
  93. class MediaFrame;
  94. GAPI_EXPORTS GFrameDesc descr_of(const MediaFrame &frame);
  95. GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GFrameDesc &desc);
  96. } // namespace cv
  97. #endif // OPENCV_GAPI_GFRAME_HPP