gscalar.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. explicit GScalar(const cv::Scalar& s);
  63. /**
  64. * @overload
  65. * @brief Constructs a value-initialized GScalar
  66. *
  67. * @param s a cv::Scalar value to associate with this GScalar object.
  68. */
  69. explicit GScalar(cv::Scalar&& s); // Constant value move-constructor from cv::Scalar
  70. /**
  71. * @overload
  72. * @brief Constructs a value-initialized GScalar
  73. *
  74. * @param v0 A `double` value to associate with this GScalar. Note
  75. * that only the first component of a four-component cv::Scalar is
  76. * set to this value, with others remain zeros.
  77. *
  78. * This constructor overload is not marked `explicit` and can be
  79. * used in G-API expression code like this:
  80. *
  81. * @snippet samples/cpp/tutorial_code/gapi/doc_snippets/api_ref_snippets.cpp gscalar_implicit
  82. *
  83. * Here operator+(GMat,GScalar) is used to wrap cv::gapi::addC()
  84. * and a value-initialized GScalar is created on the fly.
  85. *
  86. * @overload
  87. */
  88. GScalar(double v0); // Constant value constructor from double
  89. /// @private
  90. GScalar(const GNode &n, std::size_t out); // Operation result constructor
  91. /// @private
  92. GOrigin& priv(); // Internal use only
  93. /// @private
  94. const GOrigin& priv() const; // Internal use only
  95. private:
  96. std::shared_ptr<GOrigin> m_priv;
  97. };
  98. /** @} */
  99. /**
  100. * \addtogroup gapi_meta_args
  101. * @{
  102. */
  103. struct GAPI_EXPORTS_W_SIMPLE GScalarDesc
  104. {
  105. // NB.: right now it is empty
  106. inline bool operator== (const GScalarDesc &) const
  107. {
  108. return true; // NB: implement this method if GScalar meta appears
  109. }
  110. inline bool operator!= (const GScalarDesc &rhs) const
  111. {
  112. return !(*this == rhs);
  113. }
  114. };
  115. GAPI_EXPORTS_W inline GScalarDesc empty_scalar_desc() { return GScalarDesc(); }
  116. GAPI_EXPORTS GScalarDesc descr_of(const cv::Scalar &scalar);
  117. std::ostream& operator<<(std::ostream& os, const cv::GScalarDesc &desc);
  118. } // namespace cv
  119. #endif // OPENCV_GAPI_GSCALAR_HPP