gmetaarg.hpp 2.4 KB

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