github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/gapi/gmat.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-2020 Intel Corporation 6 7 8 #ifndef OPENCV_GAPI_GMAT_HPP 9 #define OPENCV_GAPI_GMAT_HPP 10 11 #include <ostream> 12 #include <memory> // std::shared_ptr 13 14 #include <opencv2/gapi/opencv_includes.hpp> 15 #include <opencv2/gapi/gcommon.hpp> // GShape 16 17 #include <opencv2/gapi/own/assert.hpp> 18 19 // TODO GAPI_EXPORTS or so 20 namespace cv 21 { 22 // Forward declaration; GNode and GOrigin are an internal 23 // (user-inaccessible) classes. 24 class GNode; 25 struct GOrigin; 26 27 /** \addtogroup gapi_data_objects 28 * @{ 29 * 30 * @brief G-API data objects used to build G-API expressions. 31 * 32 * These objects do not own any particular data (except compile-time 33 * associated values like with cv::GScalar or `cv::GArray<T>`) and are 34 * used only to construct graphs. 35 * 36 * Every graph in G-API starts and ends with data objects. 37 * 38 * Once constructed and compiled, G-API operates with regular host-side 39 * data instead. Refer to the below table to find the mapping between 40 * G-API and regular data types when passing input and output data 41 * structures to G-API: 42 * 43 * G-API data type | I/O data type 44 * ------------------ | ------------- 45 * cv::GMat | cv::Mat, cv::UMat, cv::RMat 46 * cv::GScalar | cv::Scalar 47 * `cv::GArray<T>` | std::vector<T> 48 * `cv::GOpaque<T>` | T 49 * cv::GFrame | cv::MediaFrame 50 */ 51 /** 52 * @brief GMat class represents image or tensor data in the 53 * graph. 54 * 55 * GMat doesn't store any data itself, instead it describes a 56 * functional relationship between operations consuming and producing 57 * GMat objects. 58 * 59 * GMat is a virtual counterpart of Mat and UMat, but it 60 * doesn't mean G-API use Mat or UMat objects internally to represent 61 * GMat objects -- the internal data representation may be 62 * backend-specific or optimized out at all. 63 * 64 * @sa Mat, GMatDesc 65 */ 66 class GAPI_EXPORTS_W_SIMPLE GMat 67 { 68 public: 69 /** 70 * @brief Constructs an empty GMat 71 * 72 * Normally, empty G-API data objects denote a starting point of 73 * the graph. When an empty GMat is assigned to a result of some 74 * operation, it obtains a functional link to this operation (and 75 * is not empty anymore). 76 */ 77 GAPI_WRAP GMat(); // Empty constructor 78 79 /// @private 80 GMat(const GNode &n, std::size_t out); // Operation result constructor 81 /// @private 82 GOrigin& priv(); // Internal use only 83 /// @private 84 const GOrigin& priv() const; // Internal use only 85 86 private: 87 std::shared_ptr<GOrigin> m_priv; 88 }; 89 90 class GAPI_EXPORTS GMatP : public GMat 91 { 92 public: 93 using GMat::GMat; 94 }; 95 96 class RMat; 97 98 /** @} */ 99 100 /** 101 * \addtogroup gapi_meta_args 102 * @{ 103 */ 104 struct GAPI_EXPORTS_W_SIMPLE GMatDesc 105 { 106 // FIXME: Default initializers in C++14 107 GAPI_PROP int depth; 108 GAPI_PROP int chan; 109 GAPI_PROP cv::Size size; // NB.: no multi-dimensional cases covered yet 110 GAPI_PROP bool planar; 111 GAPI_PROP std::vector<int> dims; // FIXME: Maybe it's real questionable to have it here 112 113 GAPI_WRAP GMatDesc(int d, int c, cv::Size s, bool p = false) 114 : depth(d), chan(c), size(s), planar(p) {} 115 116 GAPI_WRAP GMatDesc(int d, const std::vector<int> &dd) 117 : depth(d), chan(-1), size{-1,-1}, planar(false), dims(dd) {} 118 119 GAPI_WRAP GMatDesc(int d, std::vector<int> &&dd) 120 : depth(d), chan(-1), size{-1,-1}, planar(false), dims(std::move(dd)) {} 121 122 GAPI_WRAP GMatDesc() : GMatDesc(-1, -1, {-1,-1}) {} 123 124 inline bool operator== (const GMatDesc &rhs) const 125 { 126 return depth == rhs.depth 127 && chan == rhs.chan 128 && size == rhs.size 129 && planar == rhs.planar 130 && dims == rhs.dims; 131 } 132 133 inline bool operator!= (const GMatDesc &rhs) const 134 { 135 return !(*this == rhs); 136 } 137 138 bool isND() const { return !dims.empty(); } 139 140 // Checks if the passed mat can be described by this descriptor 141 // (it handles the case when 142 // 1-channel mat can be reinterpreted as is (1-channel mat) 143 // and as a 3-channel planar mat with height divided by 3) 144 bool canDescribe(const cv::Mat& mat) const; 145 146 bool canDescribe(const cv::RMat& mat) const; 147 148 // Meta combinator: return a new GMatDesc which differs in size by delta 149 // (all other fields are taken unchanged from this GMatDesc) 150 // FIXME: a better name? 151 GAPI_WRAP GMatDesc withSizeDelta(cv::Size delta) const 152 { 153 GMatDesc desc(*this); 154 desc.size += delta; 155 return desc; 156 } 157 // Meta combinator: return a new GMatDesc which differs in size by delta 158 // (all other fields are taken unchanged from this GMatDesc) 159 // 160 // This is an overload. 161 GAPI_WRAP GMatDesc withSizeDelta(int dx, int dy) const 162 { 163 return withSizeDelta(cv::Size{dx,dy}); 164 } 165 166 GAPI_WRAP GMatDesc withSize(cv::Size sz) const 167 { 168 GMatDesc desc(*this); 169 desc.size = sz; 170 return desc; 171 } 172 173 // Meta combinator: return a new GMatDesc with specified data depth. 174 // (all other fields are taken unchanged from this GMatDesc) 175 GAPI_WRAP GMatDesc withDepth(int ddepth) const 176 { 177 GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1); 178 GMatDesc desc(*this); 179 if (ddepth != -1) desc.depth = ddepth; 180 return desc; 181 } 182 183 // Meta combinator: return a new GMatDesc with specified data depth 184 // and number of channels. 185 // (all other fields are taken unchanged from this GMatDesc) 186 GAPI_WRAP GMatDesc withType(int ddepth, int dchan) const 187 { 188 GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1); 189 GMatDesc desc = withDepth(ddepth); 190 desc.chan = dchan; 191 return desc; 192 } 193 194 // Meta combinator: return a new GMatDesc with planar flag set 195 // (no size changes are performed, only channel interpretation is changed 196 // (interleaved -> planar) 197 GAPI_WRAP GMatDesc asPlanar() const 198 { 199 GAPI_Assert(planar == false); 200 GMatDesc desc(*this); 201 desc.planar = true; 202 return desc; 203 } 204 205 // Meta combinator: return a new GMatDesc 206 // reinterpreting 1-channel input as planar image 207 // (size height is divided by plane number) 208 GAPI_WRAP GMatDesc asPlanar(int planes) const 209 { 210 GAPI_Assert(planar == false); 211 GAPI_Assert(chan == 1); 212 GAPI_Assert(planes > 1); 213 GAPI_Assert(size.height % planes == 0); 214 GMatDesc desc(*this); 215 desc.size.height /= planes; 216 desc.chan = planes; 217 return desc.asPlanar(); 218 } 219 220 // Meta combinator: return a new GMatDesc with planar flag set to false 221 // (no size changes are performed, only channel interpretation is changed 222 // (planar -> interleaved) 223 GAPI_WRAP GMatDesc asInterleaved() const 224 { 225 GAPI_Assert(planar == true); 226 GMatDesc desc(*this); 227 desc.planar = false; 228 return desc; 229 } 230 }; 231 232 static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; } 233 234 namespace gapi { namespace detail { 235 /** Checks GMatDesc fields if the passed matrix is a set of n-dimentional points. 236 @param in GMatDesc to check. 237 @param n expected dimensionality. 238 @return the amount of points. In case input matrix can't be described as vector of points 239 of expected dimensionality, returns -1. 240 */ 241 int checkVector(const GMatDesc& in, const size_t n); 242 243 /** @overload 244 245 Checks GMatDesc fields if the passed matrix can be described as a set of points of any 246 dimensionality. 247 248 @return array of two elements in form of std::vector<int>: the amount of points 249 and their calculated dimensionality. In case input matrix can't be described as vector of points, 250 returns {-1, -1}. 251 */ 252 std::vector<int> checkVector(const GMatDesc& in); 253 }} // namespace gapi::detail 254 255 #if !defined(GAPI_STANDALONE) 256 GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat); 257 #endif // !defined(GAPI_STANDALONE) 258 259 //Fwd declarations 260 namespace gapi { namespace own { 261 class Mat; 262 GAPI_EXPORTS GMatDesc descr_of(const Mat &mat); 263 }}//gapi::own 264 265 GAPI_EXPORTS GMatDesc descr_of(const RMat &mat); 266 267 #if !defined(GAPI_STANDALONE) 268 GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat); 269 #else 270 using gapi::own::descr_of; 271 #endif 272 273 /** @} */ 274 275 GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc); 276 277 } // namespace cv 278 279 #endif // OPENCV_GAPI_GMAT_HPP