gmat.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 Intel Corporation
  6. #ifndef OPENCV_GAPI_GMAT_HPP
  7. #define OPENCV_GAPI_GMAT_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/own/types.hpp" // cv::gapi::own::Size
  13. #include "opencv2/gapi/own/convert.hpp" // to_own
  14. #include "opencv2/gapi/own/assert.hpp"
  15. // TODO GAPI_EXPORTS or so
  16. namespace cv
  17. {
  18. // Forward declaration; GNode and GOrigin are an internal
  19. // (user-inaccessible) classes.
  20. class GNode;
  21. struct GOrigin;
  22. /** \addtogroup gapi_data_objects
  23. * @{
  24. *
  25. * @brief Data-representing objects which can be used to build G-API
  26. * expressions.
  27. */
  28. class GAPI_EXPORTS GMat
  29. {
  30. public:
  31. GMat(); // Empty constructor
  32. GMat(const GNode &n, std::size_t out); // Operation result constructor
  33. GOrigin& priv(); // Internal use only
  34. const GOrigin& priv() const; // Internal use only
  35. private:
  36. std::shared_ptr<GOrigin> m_priv;
  37. };
  38. /** @} */
  39. /**
  40. * \addtogroup gapi_meta_args
  41. * @{
  42. */
  43. struct GAPI_EXPORTS GMatDesc
  44. {
  45. // FIXME: Default initializers in C++14
  46. int depth;
  47. int chan;
  48. cv::gapi::own::Size size; // NB.: no multi-dimensional cases covered yet
  49. inline bool operator== (const GMatDesc &rhs) const
  50. {
  51. return depth == rhs.depth && chan == rhs.chan && size == rhs.size;
  52. }
  53. inline bool operator!= (const GMatDesc &rhs) const
  54. {
  55. return !(*this == rhs);
  56. }
  57. // Meta combinator: return a new GMatDesc which differs in size by delta
  58. // (all other fields are taken unchanged from this GMatDesc)
  59. // FIXME: a better name?
  60. GMatDesc withSizeDelta(cv::gapi::own::Size delta) const
  61. {
  62. GMatDesc desc(*this);
  63. desc.size += delta;
  64. return desc;
  65. }
  66. #if !defined(GAPI_STANDALONE)
  67. GMatDesc withSizeDelta(cv::Size delta) const
  68. {
  69. return withSizeDelta(to_own(delta));
  70. }
  71. GMatDesc withSize(cv::Size sz) const
  72. {
  73. return withSize(to_own(sz));
  74. }
  75. #endif // !defined(GAPI_STANDALONE)
  76. // Meta combinator: return a new GMatDesc which differs in size by delta
  77. // (all other fields are taken unchanged from this GMatDesc)
  78. //
  79. // This is an overload.
  80. GMatDesc withSizeDelta(int dx, int dy) const
  81. {
  82. return withSizeDelta(cv::gapi::own::Size{dx,dy});
  83. }
  84. GMatDesc withSize(cv::gapi::own::Size sz) const
  85. {
  86. GMatDesc desc(*this);
  87. desc.size = sz;
  88. return desc;
  89. }
  90. // Meta combinator: return a new GMatDesc with specified data depth.
  91. // (all other fields are taken unchanged from this GMatDesc)
  92. GMatDesc withDepth(int ddepth) const
  93. {
  94. GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1);
  95. GMatDesc desc(*this);
  96. if (ddepth != -1) desc.depth = ddepth;
  97. return desc;
  98. }
  99. // Meta combinator: return a new GMatDesc with specified data depth
  100. // and number of channels.
  101. // (all other fields are taken unchanged from this GMatDesc)
  102. GMatDesc withType(int ddepth, int dchan) const
  103. {
  104. GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1);
  105. GMatDesc desc = withDepth(ddepth);
  106. desc.chan = dchan;
  107. return desc;
  108. }
  109. };
  110. static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; }
  111. #if !defined(GAPI_STANDALONE)
  112. class Mat;
  113. GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat);
  114. GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat);
  115. #endif // !defined(GAPI_STANDALONE)
  116. /** @} */
  117. namespace gapi { namespace own {
  118. class Mat;
  119. GAPI_EXPORTS GMatDesc descr_of(const Mat &mat);
  120. }}//gapi::own
  121. GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc);
  122. } // namespace cv
  123. #endif // OPENCV_GAPI_GMAT_HPP