Blame view

3rdparty/opencv_4_1/include/opencv2/gapi/garg.hpp 3.25 KB
09c2d08c   Hu Chunming   arm交付版
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
  // This file is part of OpenCV project.
  // It is subject to the license terms in the LICENSE file found in the top-level directory
  // of this distribution and at http://opencv.org/license.html.
  //
  // Copyright (C) 2018 Intel Corporation
  
  
  #ifndef OPENCV_GAPI_GARG_HPP
  #define OPENCV_GAPI_GARG_HPP
  
  #include <vector>
  #include <type_traits>
  
  #include <opencv2/gapi/opencv_includes.hpp>
  #include <opencv2/gapi/own/mat.hpp>
  
  #include <opencv2/gapi/util/any.hpp>
  #include <opencv2/gapi/util/variant.hpp>
  
  #include <opencv2/gapi/gmat.hpp>
  #include <opencv2/gapi/gscalar.hpp>
  #include <opencv2/gapi/garray.hpp>
  #include <opencv2/gapi/gtype_traits.hpp>
  #include <opencv2/gapi/gmetaarg.hpp>
  #include <opencv2/gapi/own/scalar.hpp>
  
  namespace cv {
  
  class GArg;
  
  namespace detail {
      template<typename T>
      using is_garg = std::is_same<GArg, typename std::decay<T>::type>;
  }
  
  // Parameter holder class for a node
  // Depending on platform capabilities, can either support arbitrary types
  // (as `boost::any`) or a limited number of types (as `boot::variant`).
  // FIXME: put into "details" as a user shouldn't use it in his code
  class GAPI_EXPORTS GArg
  {
  public:
      GArg() {}
  
      template<typename T, typename std::enable_if<!detail::is_garg<T>::value, int>::type = 0>
      explicit GArg(const T &t)
          : kind(detail::GTypeTraits<T>::kind)
          , value(detail::wrap_gapi_helper<T>::wrap(t))
      {
      }
  
      template<typename T, typename std::enable_if<!detail::is_garg<T>::value, int>::type = 0>
      explicit GArg(T &&t)
          : kind(detail::GTypeTraits<typename std::decay<T>::type>::kind)
          , value(detail::wrap_gapi_helper<T>::wrap(t))
      {
      }
  
      template<typename T> inline T& get()
      {
          return util::any_cast<typename std::remove_reference<T>::type>(value);
      }
  
      template<typename T> inline const T& get() const
      {
          return util::any_cast<typename std::remove_reference<T>::type>(value);
      }
  
      template<typename T> inline T& unsafe_get()
      {
          return util::unsafe_any_cast<typename std::remove_reference<T>::type>(value);
      }
  
      template<typename T> inline const T& unsafe_get() const
      {
          return util::unsafe_any_cast<typename std::remove_reference<T>::type>(value);
      }
  
      detail::ArgKind kind = detail::ArgKind::OPAQUE;
  
  protected:
      util::any value;
  };
  
  using GArgs = std::vector<GArg>;
  
  // FIXME: Express as M<GProtoArg...>::type
  // FIXME: Move to a separate file!
  using GRunArg  = util::variant<
  #if !defined(GAPI_STANDALONE)
      cv::Mat,
      cv::Scalar,
      cv::UMat,
  #endif // !defined(GAPI_STANDALONE)
      cv::gapi::own::Mat,
      cv::gapi::own::Scalar,
      cv::detail::VectorRef
      >;
  using GRunArgs = std::vector<GRunArg>;
  
  using GRunArgP = util::variant<
  #if !defined(GAPI_STANDALONE)
      cv::Mat*,
      cv::Scalar*,
      cv::UMat*,
  #endif // !defined(GAPI_STANDALONE)
      cv::gapi::own::Mat*,
      cv::gapi::own::Scalar*,
      cv::detail::VectorRef
      >;
  using GRunArgsP = std::vector<GRunArgP>;
  
  
  template<typename... Ts> inline GRunArgs gin(const Ts&... args)
  {
      return GRunArgs{ GRunArg(detail::wrap_host_helper<Ts>::wrap_in(args))... };
  }
  
  template<typename... Ts> inline GRunArgsP gout(Ts&... args)
  {
      return GRunArgsP{ GRunArgP(detail::wrap_host_helper<Ts>::wrap_out(args))... };
  }
  
  } // namespace cv
  
  #endif // OPENCV_GAPI_GARG_HPP