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.
5 // Copyright (C) 2018-2019 Intel Corporation
8 #ifndef OPENCV_GAPI_GMAT_HPP
9 #define OPENCV_GAPI_GMAT_HPP
12 #include <memory> // std::shared_ptr
14 #include <opencv2/gapi/opencv_includes.hpp>
15 #include <opencv2/gapi/gcommon.hpp> // GShape
17 #include "opencv2/gapi/own/types.hpp" // cv::gapi::own::Size
18 #include "opencv2/gapi/own/convert.hpp" // to_own
19 #include "opencv2/gapi/own/assert.hpp"
21 // TODO GAPI_EXPORTS or so
24 // Forward declaration; GNode and GOrigin are an internal
25 // (user-inaccessible) classes.
29 /** \addtogroup gapi_data_objects
32 * @brief Data-representing objects which can be used to build G-API
36 class GAPI_EXPORTS GMat
39 GMat(); // Empty constructor
40 GMat(const GNode &n, std::size_t out); // Operation result constructor
42 GOrigin& priv(); // Internal use only
43 const GOrigin& priv() const; // Internal use only
46 std::shared_ptr<GOrigin> m_priv;
52 * \addtogroup gapi_meta_args
55 struct GAPI_EXPORTS GMatDesc
57 // FIXME: Default initializers in C++14
60 cv::gapi::own::Size size; // NB.: no multi-dimensional cases covered yet
62 inline bool operator== (const GMatDesc &rhs) const
64 return depth == rhs.depth && chan == rhs.chan && size == rhs.size;
67 inline bool operator!= (const GMatDesc &rhs) const
69 return !(*this == rhs);
72 // Meta combinator: return a new GMatDesc which differs in size by delta
73 // (all other fields are taken unchanged from this GMatDesc)
74 // FIXME: a better name?
75 GMatDesc withSizeDelta(cv::gapi::own::Size delta) const
81 #if !defined(GAPI_STANDALONE)
82 GMatDesc withSizeDelta(cv::Size delta) const
84 return withSizeDelta(to_own(delta));
87 GMatDesc withSize(cv::Size sz) const
89 return withSize(to_own(sz));
91 #endif // !defined(GAPI_STANDALONE)
92 // Meta combinator: return a new GMatDesc which differs in size by delta
93 // (all other fields are taken unchanged from this GMatDesc)
95 // This is an overload.
96 GMatDesc withSizeDelta(int dx, int dy) const
98 return withSizeDelta(cv::gapi::own::Size{dx,dy});
101 GMatDesc withSize(cv::gapi::own::Size sz) const
103 GMatDesc desc(*this);
108 // Meta combinator: return a new GMatDesc with specified data depth.
109 // (all other fields are taken unchanged from this GMatDesc)
110 GMatDesc withDepth(int ddepth) const
112 GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1);
113 GMatDesc desc(*this);
114 if (ddepth != -1) desc.depth = ddepth;
118 // Meta combinator: return a new GMatDesc with specified data depth
119 // and number of channels.
120 // (all other fields are taken unchanged from this GMatDesc)
121 GMatDesc withType(int ddepth, int dchan) const
123 GAPI_Assert(CV_MAT_CN(ddepth) == 1 || ddepth == -1);
124 GMatDesc desc = withDepth(ddepth);
130 static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; }
132 #if !defined(GAPI_STANDALONE)
134 GAPI_EXPORTS GMatDesc descr_of(const cv::Mat &mat);
135 GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat);
136 #endif // !defined(GAPI_STANDALONE)
140 namespace gapi { namespace own {
142 GAPI_EXPORTS GMatDesc descr_of(const Mat &mat);
145 GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GMatDesc &desc);
149 #endif // OPENCV_GAPI_GMAT_HPP