mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
Added GMatP type
This commit is contained in:
parent
faca45a7ea
commit
834d438d6e
@ -124,6 +124,10 @@ template<> struct get_in<cv::GMat>
|
||||
{
|
||||
static cv::Mat get(GCPUContext &ctx, int idx) { return to_ocv(ctx.inMat(idx)); }
|
||||
};
|
||||
template<> struct get_in<cv::GMatP>
|
||||
{
|
||||
static cv::Mat get(GCPUContext &ctx, int idx) { return get_in<cv::GMat>::get(ctx, idx); }
|
||||
};
|
||||
template<> struct get_in<cv::GScalar>
|
||||
{
|
||||
static cv::Scalar get(GCPUContext &ctx, int idx) { return to_ocv(ctx.inVal(idx)); }
|
||||
@ -188,6 +192,13 @@ template<> struct get_out<cv::GMat>
|
||||
return {r};
|
||||
}
|
||||
};
|
||||
template<> struct get_out<cv::GMatP>
|
||||
{
|
||||
static tracked_cv_mat get(GCPUContext &ctx, int idx)
|
||||
{
|
||||
return get_out<cv::GMat>::get(ctx, idx);
|
||||
}
|
||||
};
|
||||
template<> struct get_out<cv::GScalar>
|
||||
{
|
||||
static scalar_wrapper get(GCPUContext &ctx, int idx)
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
|
||||
// A generic yield method - obtain a link to operator's particular GMat output
|
||||
GMat yield (int output = 0);
|
||||
GMatP yieldP (int output = 0);
|
||||
GScalar yieldScalar(int output = 0);
|
||||
|
||||
template<class T> GArray<T> yieldArray(int output = 0)
|
||||
|
@ -63,6 +63,10 @@ namespace detail
|
||||
{
|
||||
static inline cv::GMat yield(cv::GCall &call, int i) { return call.yield(i); }
|
||||
};
|
||||
template<> struct Yield<cv::GMatP>
|
||||
{
|
||||
static inline cv::GMatP yield(cv::GCall &call, int i) { return call.yieldP(i); }
|
||||
};
|
||||
template<> struct Yield<cv::GScalar>
|
||||
{
|
||||
static inline cv::GScalar yield(cv::GCall &call, int i) { return call.yieldScalar(i); }
|
||||
@ -82,6 +86,7 @@ namespace detail
|
||||
// This mapping is used to transform types to call outMeta() callback.
|
||||
template<typename T> struct MetaType;
|
||||
template<> struct MetaType<cv::GMat> { using type = GMatDesc; };
|
||||
template<> struct MetaType<cv::GMatP> { using type = GMatDesc; };
|
||||
template<> struct MetaType<cv::GScalar> { using type = GScalarDesc; };
|
||||
template<typename U> struct MetaType<cv::GArray<U> > { using type = GArrayDesc; };
|
||||
template<typename T> struct MetaType { using type = T; }; // opaque args passed as-is
|
||||
|
@ -46,6 +46,12 @@ private:
|
||||
std::shared_ptr<GOrigin> m_priv;
|
||||
};
|
||||
|
||||
class GAPI_EXPORTS GMatP : public GMat
|
||||
{
|
||||
public:
|
||||
using GMat::GMat;
|
||||
};
|
||||
|
||||
namespace gapi { namespace own {
|
||||
class Mat;
|
||||
}}//gapi::own
|
||||
|
@ -34,6 +34,7 @@ namespace cv {
|
||||
// directly.
|
||||
using GProtoArg = util::variant
|
||||
< GMat
|
||||
, GMatP
|
||||
, GScalar
|
||||
, detail::GArrayU // instead of GArray<T>
|
||||
>;
|
||||
|
@ -29,6 +29,7 @@ namespace detail
|
||||
OPAQUE, // Unknown, generic, opaque-to-GAPI data type - STATIC
|
||||
GOBJREF, // <internal> reference to object
|
||||
GMAT, // a cv::GMat
|
||||
GMATP, // a cv::GMatP
|
||||
GSCALAR, // a cv::GScalar
|
||||
GARRAY, // a cv::GArrayU (note - exactly GArrayU, not GArray<T>!)
|
||||
};
|
||||
@ -47,6 +48,11 @@ namespace detail
|
||||
static constexpr const ArgKind kind = ArgKind::GMAT;
|
||||
static constexpr const GShape shape = GShape::GMAT;
|
||||
};
|
||||
template<> struct GTypeTraits<cv::GMatP>
|
||||
{
|
||||
static constexpr const ArgKind kind = ArgKind::GMATP;
|
||||
static constexpr const GShape shape = GShape::GMAT;
|
||||
};
|
||||
template<> struct GTypeTraits<cv::GScalar>
|
||||
{
|
||||
static constexpr const ArgKind kind = ArgKind::GSCALAR;
|
||||
@ -76,6 +82,10 @@ namespace detail
|
||||
|
||||
// Resolve a Host type back to its associated G-Type.
|
||||
// FIXME: Probably it can be avoided
|
||||
// FIXME: GMatP is not present here.
|
||||
// (Actually these traits is used only to check
|
||||
// if associated G-type has custom wrap functions
|
||||
// and GMat behavior is correct for GMatP)
|
||||
template<typename T> struct GTypeOf;
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
template<> struct GTypeOf<cv::Mat> { using type = cv::GMat; };
|
||||
|
@ -49,6 +49,11 @@ cv::GMat cv::GCall::yield(int output)
|
||||
return cv::GMat(m_priv->m_node, output);
|
||||
}
|
||||
|
||||
cv::GMatP cv::GCall::yieldP(int output)
|
||||
{
|
||||
return cv::GMatP(m_priv->m_node, output);
|
||||
}
|
||||
|
||||
cv::GScalar cv::GCall::yieldScalar(int output)
|
||||
{
|
||||
return cv::GScalar(m_priv->m_node, output);
|
||||
|
@ -25,6 +25,9 @@ const cv::GOrigin& cv::gimpl::proto::origin_of(const cv::GProtoArg &arg)
|
||||
case cv::GProtoArg::index_of<cv::GMat>():
|
||||
return util::get<cv::GMat>(arg).priv();
|
||||
|
||||
case cv::GProtoArg::index_of<cv::GMatP>():
|
||||
return util::get<cv::GMatP>(arg).priv();
|
||||
|
||||
case cv::GProtoArg::index_of<cv::GScalar>():
|
||||
return util::get<cv::GScalar>(arg).priv();
|
||||
|
||||
@ -53,6 +56,7 @@ bool cv::gimpl::proto::is_dynamic(const cv::GArg& arg)
|
||||
switch (arg.kind)
|
||||
{
|
||||
case detail::ArgKind::GMAT:
|
||||
case detail::ArgKind::GMATP:
|
||||
case detail::ArgKind::GSCALAR:
|
||||
case detail::ArgKind::GARRAY:
|
||||
return true;
|
||||
@ -78,6 +82,7 @@ cv::GProtoArg cv::gimpl::proto::rewrap(const cv::GArg &arg)
|
||||
switch (arg.kind)
|
||||
{
|
||||
case detail::ArgKind::GMAT: return GProtoArg(arg.get<cv::GMat>());
|
||||
case detail::ArgKind::GMATP: return GProtoArg(arg.get<cv::GMatP>());
|
||||
case detail::ArgKind::GSCALAR: return GProtoArg(arg.get<cv::GScalar>());
|
||||
case detail::ArgKind::GARRAY: return GProtoArg(arg.get<cv::detail::GArrayU>());
|
||||
default: util::throw_error(std::logic_error("Unsupported GArg type"));
|
||||
|
@ -156,6 +156,7 @@ void cv::gimpl::GCompiler::validateInputMeta()
|
||||
{
|
||||
// FIXME: Auto-generate methods like this from traits:
|
||||
case GProtoArg::index_of<cv::GMat>():
|
||||
case GProtoArg::index_of<cv::GMatP>():
|
||||
return util::holds_alternative<cv::GMatDesc>(meta);
|
||||
|
||||
case GProtoArg::index_of<cv::GScalar>():
|
||||
|
@ -11,7 +11,7 @@
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
G_TYPED_KERNEL(GResize3c3p, <GMat(GMat,Size,int)>, "test.resize3c3p") {
|
||||
G_TYPED_KERNEL(GResize3c3p, <GMatP(GMat,Size,int)>, "test.resize3c3p") {
|
||||
static GMatDesc outMeta(GMatDesc in, Size sz, int) {
|
||||
GAPI_Assert(in.depth == CV_8U);
|
||||
GAPI_Assert(in.chan == 3);
|
||||
@ -20,7 +20,7 @@ G_TYPED_KERNEL(GResize3c3p, <GMat(GMat,Size,int)>, "test.resize3c3p") {
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GResize3p3p, <GMat(GMat,Size,int)>, "test.resize3p3p") {
|
||||
G_TYPED_KERNEL(GResize3p3p, <GMatP(GMatP,Size,int)>, "test.resize3p3p") {
|
||||
static GMatDesc outMeta(GMatDesc in, Size sz, int) {
|
||||
GAPI_Assert(in.depth == CV_8U);
|
||||
GAPI_Assert(in.chan == 3);
|
||||
@ -42,13 +42,7 @@ static GMatDesc NV12toRGBoutMeta(GMatDesc inY, GMatDesc inUV)
|
||||
return inY.withType(CV_8U, 3);
|
||||
}
|
||||
|
||||
G_TYPED_KERNEL(GNV12toRGB, <GMat(GMat,GMat)>, "test.nv12torgb") {
|
||||
static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) {
|
||||
return NV12toRGBoutMeta(inY, inUV);
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GNV12toRGBp, <GMat(GMat,GMat)>, "test.nv12torgbp") {
|
||||
G_TYPED_KERNEL(GNV12toRGBp, <GMatP(GMat,GMat)>, "test.nv12torgbp") {
|
||||
static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) {
|
||||
return NV12toRGBoutMeta(inY, inUV).asPlanar();
|
||||
}
|
||||
@ -152,7 +146,7 @@ TEST_P(PlanarTest, Resize3p3p)
|
||||
cv::Mat out_mat = cv::Mat::zeros(out_sz.height*3, out_sz.width, CV_8UC1);
|
||||
cv::Mat out_mat_ocv = cv::Mat::zeros(out_sz.height*3, out_sz.width, CV_8UC1);
|
||||
|
||||
cv::GMat in;
|
||||
cv::GMatP in;
|
||||
auto out = GResize3p3p::on(in, out_sz, interp);
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
|
||||
|
@ -31,6 +31,7 @@ using GArg_Test_Types = ::testing::Types
|
||||
<
|
||||
// G-API types
|
||||
Expected<cv::GMat, cv::detail::ArgKind::GMAT>
|
||||
, Expected<cv::GMatP, cv::detail::ArgKind::GMATP>
|
||||
, Expected<cv::GScalar, cv::detail::ArgKind::GSCALAR>
|
||||
, Expected<cv::GArray<int>, cv::detail::ArgKind::GARRAY>
|
||||
, Expected<cv::GArray<float>, cv::detail::ArgKind::GARRAY>
|
||||
|
Loading…
Reference in New Issue
Block a user