gmetaarg.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_GMETAARG_HPP
  7. #define OPENCV_GAPI_GMETAARG_HPP
  8. #include <vector>
  9. #include <type_traits>
  10. #include <opencv2/gapi/util/util.hpp>
  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/gopaque.hpp>
  16. #include <opencv2/gapi/gframe.hpp>
  17. namespace cv
  18. {
  19. // FIXME: Rename to GMeta?
  20. // FIXME: user shouldn't deal with it - put to detail?
  21. // GMetaArg is an union type over descriptions of G-types which can serve as
  22. // GComputation's in/output slots.
  23. //
  24. // GMetaArg objects are passed as arguments to GComputation::compile()
  25. // to specify which data a compiled computation should be specialized on.
  26. // For manual compile(), user must supply this metadata, in case of apply()
  27. // this metadata is taken from arguments computation should operate on.
  28. //
  29. // The first type (monostate) is equal to "uninitialized"/"unresolved" meta.
  30. using GMetaArg = util::variant
  31. < util::monostate
  32. , GMatDesc
  33. , GScalarDesc
  34. , GArrayDesc
  35. , GOpaqueDesc
  36. , GFrameDesc
  37. >;
  38. GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const GMetaArg &);
  39. using GMetaArgs = std::vector<GMetaArg>;
  40. namespace detail
  41. {
  42. // These traits are used by GComputation::compile()
  43. // FIXME: is_constructible<T> doesn't work as variant doesn't do any SFINAE
  44. // in its current template constructor
  45. template<typename T> struct is_meta_descr : std::false_type {};
  46. template<> struct is_meta_descr<GMatDesc> : std::true_type {};
  47. template<> struct is_meta_descr<GScalarDesc> : std::true_type {};
  48. template<> struct is_meta_descr<GArrayDesc> : std::true_type {};
  49. template<> struct is_meta_descr<GOpaqueDesc> : std::true_type {};
  50. template<typename... Ts>
  51. using are_meta_descrs = all_satisfy<is_meta_descr, Ts...>;
  52. template<typename... Ts>
  53. using are_meta_descrs_but_last = all_satisfy<is_meta_descr, typename all_but_last<Ts...>::type>;
  54. } // namespace detail
  55. // Note: descr_of(std::vector<..>) returns a GArrayDesc, while
  56. // descrs_of(std::vector<..>) returns an array of Meta args!
  57. class UMat;
  58. GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector<cv::Mat> &vec);
  59. GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector<cv::UMat> &vec);
  60. namespace gapi { namespace own {
  61. GAPI_EXPORTS cv::GMetaArgs descrs_of(const std::vector<Mat> &vec);
  62. }} // namespace gapi::own
  63. } // namespace cv
  64. #endif // OPENCV_GAPI_GMETAARG_HPP