1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Added planar flag to GMatDesc, intergated into framework, added tests

This commit is contained in:
Ruslan Garnov
2019-04-22 17:36:10 +03:00
parent 1f517b8a02
commit f81886d17c
14 changed files with 519 additions and 27 deletions
+56 -2
View File
@@ -46,6 +46,10 @@ private:
std::shared_ptr<GOrigin> m_priv;
};
namespace gapi { namespace own {
class Mat;
}}//gapi::own
/** @} */
/**
@@ -58,10 +62,16 @@ struct GAPI_EXPORTS GMatDesc
int depth;
int chan;
cv::gapi::own::Size size; // NB.: no multi-dimensional cases covered yet
bool planar;
GMatDesc(int d, int c, cv::gapi::own::Size s, bool p = false)
: depth(d), chan(c), size(s), planar(p) {}
GMatDesc() : GMatDesc(-1, -1, {-1,-1}) {}
inline bool operator== (const GMatDesc &rhs) const
{
return depth == rhs.depth && chan == rhs.chan && size == rhs.size;
return depth == rhs.depth && chan == rhs.chan && size == rhs.size && planar == rhs.planar;
}
inline bool operator!= (const GMatDesc &rhs) const
@@ -69,6 +79,12 @@ struct GAPI_EXPORTS GMatDesc
return !(*this == rhs);
}
// Checks if the passed mat can be described by this descriptor
// (it handles the case when
// 1-channel mat can be reinterpreted as is (1-channel mat)
// and as a 3-channel planar mat with height divided by 3)
bool canDescribe(const cv::gapi::own::Mat& mat) const;
// Meta combinator: return a new GMatDesc which differs in size by delta
// (all other fields are taken unchanged from this GMatDesc)
// FIXME: a better name?
@@ -88,6 +104,8 @@ struct GAPI_EXPORTS GMatDesc
{
return withSize(to_own(sz));
}
bool canDescribe(const cv::Mat& mat) const;
#endif // !defined(GAPI_STANDALONE)
// Meta combinator: return a new GMatDesc which differs in size by delta
// (all other fields are taken unchanged from this GMatDesc)
@@ -125,6 +143,43 @@ struct GAPI_EXPORTS GMatDesc
desc.chan = dchan;
return desc;
}
// Meta combinator: return a new GMatDesc with planar flag set
// (no size changes are performed, only channel interpretation is changed
// (interleaved -> planar)
GMatDesc asPlanar() const
{
GAPI_Assert(planar == false);
GMatDesc desc(*this);
desc.planar = true;
return desc;
}
// Meta combinator: return a new GMatDesc
// reinterpreting 1-channel input as planar image
// (size height is divided by plane number)
GMatDesc asPlanar(int planes) const
{
GAPI_Assert(planar == false);
GAPI_Assert(chan == 1);
GAPI_Assert(planes > 1);
GAPI_Assert(size.height % planes == 0);
GMatDesc desc(*this);
desc.size.height /= planes;
desc.chan = planes;
return desc.asPlanar();
}
// Meta combinator: return a new GMatDesc with planar flag set to false
// (no size changes are performed, only channel interpretation is changed
// (planar -> interleaved)
GMatDesc asInterleaved() const
{
GAPI_Assert(planar == true);
GMatDesc desc(*this);
desc.planar = false;
return desc;
}
};
static inline GMatDesc empty_gmat_desc() { return GMatDesc{-1,-1,{-1,-1}}; }
@@ -138,7 +193,6 @@ GAPI_EXPORTS GMatDesc descr_of(const cv::UMat &mat);
/** @} */
namespace gapi { namespace own {
class Mat;
GAPI_EXPORTS GMatDesc descr_of(const Mat &mat);
}}//gapi::own
+9 -1
View File
@@ -112,8 +112,16 @@ GMetaArgs GAPI_EXPORTS descr_of(const GRunArgs &args);
// Transform run-time operation result argument into metadata extracted from that argument
// Used to compare the metadata, which generated at compile time with the metadata result operation in run time
GMetaArg GAPI_EXPORTS descr_of(const GRunArgP& argp);
GMetaArg GAPI_EXPORTS descr_of(const GRunArgP& argp);
// Checks if run-time computation argument can be described by metadata
bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArg& arg);
bool GAPI_EXPORTS can_describe(const GMetaArgs& metas, const GRunArgs& args);
// Checks if run-time computation result argument can be described by metadata.
// Used to check if the metadata generated at compile time
// coincides with output arguments passed to computation in cpu and ocl backends
bool GAPI_EXPORTS can_describe(const GMetaArg& meta, const GRunArgP& argp);
} // namespace cv
@@ -79,6 +79,7 @@ namespace detail
template<typename T> struct GTypeOf;
#if !defined(GAPI_STANDALONE)
template<> struct GTypeOf<cv::Mat> { using type = cv::GMat; };
template<> struct GTypeOf<cv::UMat> { using type = cv::GMat; };
template<> struct GTypeOf<cv::Scalar> { using type = cv::GScalar; };
#endif // !defined(GAPI_STANDALONE)
template<> struct GTypeOf<cv::gapi::own::Mat> { using type = cv::GMat; };