github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/gapi/gproto.hpp (about) 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 7 8 #ifndef OPENCV_GAPI_GPROTO_HPP 9 #define OPENCV_GAPI_GPROTO_HPP 10 11 #include <type_traits> 12 #include <vector> 13 #include <ostream> 14 15 #include <opencv2/gapi/util/variant.hpp> 16 17 #include <opencv2/gapi/gmat.hpp> 18 #include <opencv2/gapi/gscalar.hpp> 19 #include <opencv2/gapi/garray.hpp> 20 #include <opencv2/gapi/gopaque.hpp> 21 #include <opencv2/gapi/garg.hpp> 22 #include <opencv2/gapi/gmetaarg.hpp> 23 24 namespace cv { 25 26 // FIXME: user shouldn't deal with it - put to detail? 27 // GProtoArg is an union type over G-types which can serve as 28 // GComputation's in/output slots. In other words, GProtoArg 29 // wraps any type which can serve as G-API exchange type. 30 // 31 // In Runtime, GProtoArgs are substituted with appropriate GRunArgs. 32 // 33 // GProtoArg objects are constructed in-place when user describes 34 // (captures) computations, user doesn't interact with these types 35 // directly. 36 using GProtoArg = util::variant 37 < GMat 38 , GMatP 39 , GFrame 40 , GScalar 41 , detail::GArrayU // instead of GArray<T> 42 , detail::GOpaqueU // instead of GOpaque<T> 43 >; 44 45 using GProtoArgs = std::vector<GProtoArg>; 46 47 namespace detail 48 { 49 template<typename... Ts> inline GProtoArgs packArgs(Ts... args) 50 { 51 return GProtoArgs{ GProtoArg(wrap_gapi_helper<Ts>::wrap(args))... }; 52 } 53 54 } 55 56 template<class Tag> 57 struct GIOProtoArgs 58 { 59 public: 60 // NB: Used by python wrapper 61 GIOProtoArgs() = default; 62 explicit GIOProtoArgs(const GProtoArgs& args) : m_args(args) {} 63 explicit GIOProtoArgs(GProtoArgs &&args) : m_args(std::move(args)) {} 64 65 GProtoArgs m_args; 66 67 // TODO: Think about the addition operator 68 /** 69 * @brief This operator allows to complement the proto vectors at runtime. 70 * 71 * It's an ordinary overload of addition assignment operator. 72 * 73 * Example of usage: 74 * @snippet dynamic_graph.cpp GIOProtoArgs usage 75 * 76 */ 77 template<typename Tg> 78 friend GIOProtoArgs<Tg>& operator += (GIOProtoArgs<Tg> &lhs, const GIOProtoArgs<Tg> &rhs); 79 }; 80 81 template<typename Tg> 82 cv::GIOProtoArgs<Tg>& operator += (cv::GIOProtoArgs<Tg> &lhs, const cv::GIOProtoArgs<Tg> &rhs) 83 { 84 lhs.m_args.reserve(lhs.m_args.size() + rhs.m_args.size()); 85 lhs.m_args.insert(lhs.m_args.end(), rhs.m_args.begin(), rhs.m_args.end()); 86 return lhs; 87 } 88 89 struct In_Tag{}; 90 struct Out_Tag{}; 91 92 using GProtoInputArgs = GIOProtoArgs<In_Tag>; 93 using GProtoOutputArgs = GIOProtoArgs<Out_Tag>; 94 95 // Perfect forwarding 96 template<typename... Ts> inline GProtoInputArgs GIn(Ts&&... ts) 97 { 98 return GProtoInputArgs(detail::packArgs(std::forward<Ts>(ts)...)); 99 } 100 101 template<typename... Ts> inline GProtoOutputArgs GOut(Ts&&... ts) 102 { 103 return GProtoOutputArgs(detail::packArgs(std::forward<Ts>(ts)...)); 104 } 105 106 namespace detail 107 { 108 // Extract elements form tuple 109 // FIXME: Someday utilize a generic tuple_to_vec<> routine 110 template<typename... Ts, int... Indexes> 111 static GProtoOutputArgs getGOut_impl(const std::tuple<Ts...>& ts, detail::Seq<Indexes...>) 112 { 113 return GProtoOutputArgs{ detail::packArgs(std::get<Indexes>(ts)...)}; 114 } 115 } 116 117 template<typename... Ts> inline GProtoOutputArgs GOut(const std::tuple<Ts...>& ts) 118 { 119 // TODO: think of std::forward(ts) 120 return detail::getGOut_impl(ts, typename detail::MkSeq<sizeof...(Ts)>::type()); 121 } 122 123 // Takes rvalue as input arg 124 template<typename... Ts> inline GProtoOutputArgs GOut(std::tuple<Ts...>&& ts) 125 { 126 // TODO: think of std::forward(ts) 127 return detail::getGOut_impl(ts, typename detail::MkSeq<sizeof...(Ts)>::type()); 128 } 129 130 // Extract run-time arguments from node origin 131 // Can be used to extract constant values associated with G-objects 132 // (like GScalar) at graph construction time 133 GRunArg value_of(const GOrigin &origin); 134 135 // Transform run-time computation arguments into a collection of metadata 136 // extracted from that arguments 137 GMetaArg GAPI_EXPORTS descr_of(const GRunArg &arg ); 138 GMetaArgs GAPI_EXPORTS descr_of(const GRunArgs &args); 139 140 // Transform run-time operation result argument into metadata extracted from that argument 141 // Used to compare the metadata, which generated at compile time with the metadata result operation in run time 142 GMetaArg GAPI_EXPORTS descr_of(const GRunArgP& argp); 143 144 // Checks if run-time computation argument can be described by metadata 145 bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArg& arg); 146 bool GAPI_EXPORTS can_describe(const GMetaArgs& metas, const GRunArgs& args); 147 148 // Checks if run-time computation result argument can be described by metadata. 149 // Used to check if the metadata generated at compile time 150 // coincides with output arguments passed to computation in cpu and ocl backends 151 bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArgP& argp); 152 153 // Validates input arguments 154 void GAPI_EXPORTS validate_input_arg(const GRunArg& arg); 155 void GAPI_EXPORTS validate_input_args(const GRunArgs& args); 156 157 } // namespace cv 158 159 #endif // OPENCV_GAPI_GPROTO_HPP