gproto.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_GPROTO_HPP
  7. #define OPENCV_GAPI_GPROTO_HPP
  8. #include <type_traits>
  9. #include <vector>
  10. #include <ostream>
  11. #include "opencv2/gapi/util/variant.hpp"
  12. #include "opencv2/gapi/gmat.hpp"
  13. #include "opencv2/gapi/gscalar.hpp"
  14. #include "opencv2/gapi/garray.hpp"
  15. #include "opencv2/gapi/garg.hpp"
  16. #include "opencv2/gapi/gmetaarg.hpp"
  17. namespace cv {
  18. // FIXME: user shouldn't deal with it - put to detail?
  19. // GProtoArg is an union type over G-types which can serve as
  20. // GComputation's in/output slots. In other words, GProtoArg
  21. // wraps any type which can serve as G-API exchange type.
  22. //
  23. // In Runtime, GProtoArgs are substituted with appropriate GRunArgs.
  24. //
  25. // GProtoArg objects are constructed in-place when user describes
  26. // (captures) computations, user doesn't interact with these types
  27. // directly.
  28. using GProtoArg = util::variant
  29. < GMat
  30. , GScalar
  31. , detail::GArrayU // instead of GArray<T>
  32. >;
  33. using GProtoArgs = std::vector<GProtoArg>;
  34. namespace detail
  35. {
  36. template<typename... Ts> inline GProtoArgs packArgs(Ts... args)
  37. {
  38. return GProtoArgs{ GProtoArg(wrap_gapi_helper<Ts>::wrap(args))... };
  39. }
  40. }
  41. template<class Tag>
  42. struct GIOProtoArgs
  43. {
  44. public:
  45. explicit GIOProtoArgs(const GProtoArgs& args) : m_args(args) {}
  46. explicit GIOProtoArgs(GProtoArgs &&args) : m_args(std::move(args)) {}
  47. GProtoArgs m_args;
  48. };
  49. struct In_Tag{};
  50. struct Out_Tag{};
  51. using GProtoInputArgs = GIOProtoArgs<In_Tag>;
  52. using GProtoOutputArgs = GIOProtoArgs<Out_Tag>;
  53. // Perfect forwarding
  54. template<typename... Ts> inline GProtoInputArgs GIn(Ts&&... ts)
  55. {
  56. return GProtoInputArgs(detail::packArgs(std::forward<Ts>(ts)...));
  57. }
  58. template<typename... Ts> inline GProtoOutputArgs GOut(Ts&&... ts)
  59. {
  60. return GProtoOutputArgs(detail::packArgs(std::forward<Ts>(ts)...));
  61. }
  62. namespace detail
  63. {
  64. // Extract elements form tuple
  65. // FIXME: Someday utilize a generic tuple_to_vec<> routine
  66. template<typename... Ts, int... Indexes>
  67. static GProtoOutputArgs getGOut_impl(const std::tuple<Ts...>& ts, detail::Seq<Indexes...>)
  68. {
  69. return GProtoOutputArgs{ detail::packArgs(std::get<Indexes>(ts)...)};
  70. }
  71. }
  72. template<typename... Ts> inline GProtoOutputArgs GOut(const std::tuple<Ts...>& ts)
  73. {
  74. // TODO: think of std::forward(ts)
  75. return detail::getGOut_impl(ts, typename detail::MkSeq<sizeof...(Ts)>::type());
  76. }
  77. // Takes rvalue as input arg
  78. template<typename... Ts> inline GProtoOutputArgs GOut(std::tuple<Ts...>&& ts)
  79. {
  80. // TODO: think of std::forward(ts)
  81. return detail::getGOut_impl(ts, typename detail::MkSeq<sizeof...(Ts)>::type());
  82. }
  83. // Extract run-time arguments from node origin
  84. // Can be used to extract constant values associated with G-objects
  85. // (like GScalar) at graph construction time
  86. GRunArg value_of(const GOrigin &origin);
  87. // Transform run-time computation arguments into a collection of metadata
  88. // extracted from that arguments
  89. GMetaArg GAPI_EXPORTS descr_of(const GRunArg &arg );
  90. GMetaArgs GAPI_EXPORTS descr_of(const GRunArgs &args);
  91. // Transform run-time operation result argument into metadata extracted from that argument
  92. // Used to compare the metadata, which generated at compile time with the metadata result operation in run time
  93. GMetaArg GAPI_EXPORTS descr_of(const GRunArgP& argp);
  94. } // namespace cv
  95. #endif // OPENCV_GAPI_GPROTO_HPP