gscalar.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_GSCALAR_HPP
  7. #define OPENCV_GAPI_GSCALAR_HPP
  8. #include <ostream>
  9. #include <opencv2/gapi/opencv_includes.hpp>
  10. #include <opencv2/gapi/gcommon.hpp> // GShape
  11. #include <opencv2/gapi/util/optional.hpp>
  12. namespace cv
  13. {
  14. // Forward declaration; GNode and GOrigin are an internal
  15. // (user-inaccessible) classes.
  16. class GNode;
  17. struct GOrigin;
  18. /** \addtogroup gapi_data_objects
  19. * @{
  20. */
  21. /**
  22. * @brief GScalar class represents cv::Scalar data in the graph.
  23. *
  24. * GScalar may be associated with a cv::Scalar value, which becomes
  25. * its constant value bound in graph compile time. cv::GScalar describes a
  26. * functional relationship between operations consuming and producing
  27. * GScalar objects.
  28. *
  29. * GScalar is a virtual counterpart of cv::Scalar, which is usually used
  30. * to represent the GScalar data in G-API during the execution.
  31. *
  32. * @sa Scalar
  33. */
  34. class GAPI_EXPORTS_W_SIMPLE GScalar
  35. {
  36. public:
  37. /**
  38. * @brief Constructs an empty GScalar
  39. *
  40. * Normally, empty G-API data objects denote a starting point of
  41. * the graph. When an empty GScalar is assigned to a result of some
  42. * operation, it obtains a functional link to this operation (and
  43. * is not empty anymore).
  44. */
  45. GAPI_WRAP GScalar();
  46. /**
  47. * @brief Constructs a value-initialized GScalar
  48. *
  49. * In contrast with GMat (which can be either an explicit graph input
  50. * or a result of some operation), GScalars may have their values
  51. * be associated at graph construction time. It is useful when
  52. * some operation has a GScalar input which doesn't change during
  53. * the program execution, and is set only once. In this case,
  54. * there is no need to declare such GScalar as a graph input.
  55. *
  56. * @note The value of GScalar may be overwritten by assigning some
  57. * other GScalar to the object using `operator=` -- on the
  58. * assignment, the old GScalar value is discarded.
  59. *
  60. * @param s a cv::Scalar value to associate with this GScalar object.
  61. */
  62. GAPI_WRAP
  63. explicit GScalar(const cv::Scalar& s);
  64. /**
  65. * @overload
  66. * @brief Constructs a value-initialized GScalar
  67. *
  68. * @param s a cv::Scalar value to associate with this GScalar object.
  69. */
  70. explicit GScalar(cv::Scalar&& s); // Constant value move-constructor from cv::Scalar
  71. /**
  72. * @overload
  73. * @brief Constructs a value-initialized GScalar
  74. *
  75. * @param v0 A `double` value to associate with this GScalar. Note
  76. * that only the first component of a four-component cv::Scalar is
  77. * set to this value, with others remain zeros.
  78. *
  79. * This constructor overload is not marked `explicit` and can be
  80. * used in G-API expression code like this:
  81. *
  82. * @snippet samples/cpp/tutorial_code/gapi/doc_snippets/api_ref_snippets.cpp gscalar_implicit
  83. *
  84. * Here operator+(GMat,GScalar) is used to wrap cv::gapi::addC()
  85. * and a value-initialized GScalar is created on the fly.
  86. *
  87. * @overload
  88. */
  89. GScalar(double v0); // Constant value constructor from double
  90. /// @private
  91. GScalar(const GNode &n, std::size_t out); // Operation result constructor
  92. /// @private
  93. GOrigin& priv(); // Internal use only
  94. /// @private
  95. const GOrigin& priv() const; // Internal use only
  96. private:
  97. std::shared_ptr<GOrigin> m_priv;
  98. };
  99. /** @} */
  100. /**
  101. * \addtogroup gapi_meta_args
  102. * @{
  103. */
  104. struct GAPI_EXPORTS_W_SIMPLE GScalarDesc
  105. {
  106. // NB.: right now it is empty
  107. inline bool operator== (const GScalarDesc &) const
  108. {
  109. return true; // NB: implement this method if GScalar meta appears
  110. }
  111. inline bool operator!= (const GScalarDesc &rhs) const
  112. {
  113. return !(*this == rhs);
  114. }
  115. };
  116. GAPI_EXPORTS_W inline GScalarDesc empty_scalar_desc() { return GScalarDesc(); }
  117. GAPI_EXPORTS GScalarDesc descr_of(const cv::Scalar &scalar);
  118. std::ostream& operator<<(std::ostream& os, const cv::GScalarDesc &desc);
  119. } // namespace cv
  120. #endif // OPENCV_GAPI_GSCALAR_HPP