From 834d438d6edbe2de253386f310f39bf05292f03c Mon Sep 17 00:00:00 2001 From: Ruslan Garnov Date: Mon, 29 Apr 2019 19:21:14 +0300 Subject: [PATCH] Added GMatP type --- .../gapi/include/opencv2/gapi/cpu/gcpukernel.hpp | 11 +++++++++++ modules/gapi/include/opencv2/gapi/gcall.hpp | 1 + modules/gapi/include/opencv2/gapi/gkernel.hpp | 5 +++++ modules/gapi/include/opencv2/gapi/gmat.hpp | 6 ++++++ modules/gapi/include/opencv2/gapi/gproto.hpp | 1 + modules/gapi/include/opencv2/gapi/gtype_traits.hpp | 10 ++++++++++ modules/gapi/src/api/gcall.cpp | 5 +++++ modules/gapi/src/api/gproto.cpp | 5 +++++ modules/gapi/src/compiler/gcompiler.cpp | 1 + modules/gapi/test/gapi_planar_test.cpp | 14 ++++---------- modules/gapi/test/internal/gapi_int_garg_test.cpp | 1 + 11 files changed, 50 insertions(+), 10 deletions(-) diff --git a/modules/gapi/include/opencv2/gapi/cpu/gcpukernel.hpp b/modules/gapi/include/opencv2/gapi/cpu/gcpukernel.hpp index facaab6aa4..80392fe0f2 100644 --- a/modules/gapi/include/opencv2/gapi/cpu/gcpukernel.hpp +++ b/modules/gapi/include/opencv2/gapi/cpu/gcpukernel.hpp @@ -124,6 +124,10 @@ template<> struct get_in { static cv::Mat get(GCPUContext &ctx, int idx) { return to_ocv(ctx.inMat(idx)); } }; +template<> struct get_in +{ + static cv::Mat get(GCPUContext &ctx, int idx) { return get_in::get(ctx, idx); } +}; template<> struct get_in { static cv::Scalar get(GCPUContext &ctx, int idx) { return to_ocv(ctx.inVal(idx)); } @@ -188,6 +192,13 @@ template<> struct get_out return {r}; } }; +template<> struct get_out +{ + static tracked_cv_mat get(GCPUContext &ctx, int idx) + { + return get_out::get(ctx, idx); + } +}; template<> struct get_out { static scalar_wrapper get(GCPUContext &ctx, int idx) diff --git a/modules/gapi/include/opencv2/gapi/gcall.hpp b/modules/gapi/include/opencv2/gapi/gcall.hpp index baf4f44e26..50223ce248 100644 --- a/modules/gapi/include/opencv2/gapi/gcall.hpp +++ b/modules/gapi/include/opencv2/gapi/gcall.hpp @@ -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 GArray yieldArray(int output = 0) diff --git a/modules/gapi/include/opencv2/gapi/gkernel.hpp b/modules/gapi/include/opencv2/gapi/gkernel.hpp index 40a9cbbfb0..af184248dc 100644 --- a/modules/gapi/include/opencv2/gapi/gkernel.hpp +++ b/modules/gapi/include/opencv2/gapi/gkernel.hpp @@ -63,6 +63,10 @@ namespace detail { static inline cv::GMat yield(cv::GCall &call, int i) { return call.yield(i); } }; + template<> struct Yield + { + static inline cv::GMatP yield(cv::GCall &call, int i) { return call.yieldP(i); } + }; template<> struct Yield { 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 struct MetaType; template<> struct MetaType { using type = GMatDesc; }; + template<> struct MetaType { using type = GMatDesc; }; template<> struct MetaType { using type = GScalarDesc; }; template struct MetaType > { using type = GArrayDesc; }; template struct MetaType { using type = T; }; // opaque args passed as-is diff --git a/modules/gapi/include/opencv2/gapi/gmat.hpp b/modules/gapi/include/opencv2/gapi/gmat.hpp index 3d89df7a59..f0ce26b415 100644 --- a/modules/gapi/include/opencv2/gapi/gmat.hpp +++ b/modules/gapi/include/opencv2/gapi/gmat.hpp @@ -46,6 +46,12 @@ private: std::shared_ptr m_priv; }; +class GAPI_EXPORTS GMatP : public GMat +{ +public: + using GMat::GMat; +}; + namespace gapi { namespace own { class Mat; }}//gapi::own diff --git a/modules/gapi/include/opencv2/gapi/gproto.hpp b/modules/gapi/include/opencv2/gapi/gproto.hpp index 7b11f0de6d..a3bce1a82a 100644 --- a/modules/gapi/include/opencv2/gapi/gproto.hpp +++ b/modules/gapi/include/opencv2/gapi/gproto.hpp @@ -34,6 +34,7 @@ namespace cv { // directly. using GProtoArg = util::variant < GMat + , GMatP , GScalar , detail::GArrayU // instead of GArray >; diff --git a/modules/gapi/include/opencv2/gapi/gtype_traits.hpp b/modules/gapi/include/opencv2/gapi/gtype_traits.hpp index bb47cd3f75..b11a044663 100644 --- a/modules/gapi/include/opencv2/gapi/gtype_traits.hpp +++ b/modules/gapi/include/opencv2/gapi/gtype_traits.hpp @@ -29,6 +29,7 @@ namespace detail OPAQUE, // Unknown, generic, opaque-to-GAPI data type - STATIC GOBJREF, // reference to object GMAT, // a cv::GMat + GMATP, // a cv::GMatP GSCALAR, // a cv::GScalar GARRAY, // a cv::GArrayU (note - exactly GArrayU, not GArray!) }; @@ -47,6 +48,11 @@ namespace detail static constexpr const ArgKind kind = ArgKind::GMAT; static constexpr const GShape shape = GShape::GMAT; }; + template<> struct GTypeTraits + { + static constexpr const ArgKind kind = ArgKind::GMATP; + static constexpr const GShape shape = GShape::GMAT; + }; template<> struct GTypeTraits { 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 struct GTypeOf; #if !defined(GAPI_STANDALONE) template<> struct GTypeOf { using type = cv::GMat; }; diff --git a/modules/gapi/src/api/gcall.cpp b/modules/gapi/src/api/gcall.cpp index c6acd15101..51de047173 100644 --- a/modules/gapi/src/api/gcall.cpp +++ b/modules/gapi/src/api/gcall.cpp @@ -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); diff --git a/modules/gapi/src/api/gproto.cpp b/modules/gapi/src/api/gproto.cpp index 9e3e8e6673..af5ba56db6 100644 --- a/modules/gapi/src/api/gproto.cpp +++ b/modules/gapi/src/api/gproto.cpp @@ -25,6 +25,9 @@ const cv::GOrigin& cv::gimpl::proto::origin_of(const cv::GProtoArg &arg) case cv::GProtoArg::index_of(): return util::get(arg).priv(); + case cv::GProtoArg::index_of(): + return util::get(arg).priv(); + case cv::GProtoArg::index_of(): return util::get(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()); + case detail::ArgKind::GMATP: return GProtoArg(arg.get()); case detail::ArgKind::GSCALAR: return GProtoArg(arg.get()); case detail::ArgKind::GARRAY: return GProtoArg(arg.get()); default: util::throw_error(std::logic_error("Unsupported GArg type")); diff --git a/modules/gapi/src/compiler/gcompiler.cpp b/modules/gapi/src/compiler/gcompiler.cpp index 0418b995f4..83d4da1b77 100644 --- a/modules/gapi/src/compiler/gcompiler.cpp +++ b/modules/gapi/src/compiler/gcompiler.cpp @@ -156,6 +156,7 @@ void cv::gimpl::GCompiler::validateInputMeta() { // FIXME: Auto-generate methods like this from traits: case GProtoArg::index_of(): + case GProtoArg::index_of(): return util::holds_alternative(meta); case GProtoArg::index_of(): diff --git a/modules/gapi/test/gapi_planar_test.cpp b/modules/gapi/test/gapi_planar_test.cpp index f763fdcf04..6cd8d51899 100644 --- a/modules/gapi/test/gapi_planar_test.cpp +++ b/modules/gapi/test/gapi_planar_test.cpp @@ -11,7 +11,7 @@ namespace opencv_test { -G_TYPED_KERNEL(GResize3c3p, , "test.resize3c3p") { +G_TYPED_KERNEL(GResize3c3p, , "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, , "test.resize3c3p") { } }; -G_TYPED_KERNEL(GResize3p3p, , "test.resize3p3p") { +G_TYPED_KERNEL(GResize3p3p, , "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, , "test.nv12torgb") { - static GMatDesc outMeta(GMatDesc inY, GMatDesc inUV) { - return NV12toRGBoutMeta(inY, inUV); - } -}; - -G_TYPED_KERNEL(GNV12toRGBp, , "test.nv12torgbp") { +G_TYPED_KERNEL(GNV12toRGBp, , "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)); diff --git a/modules/gapi/test/internal/gapi_int_garg_test.cpp b/modules/gapi/test/internal/gapi_int_garg_test.cpp index e66a644900..550d12a6cf 100644 --- a/modules/gapi/test/internal/gapi_int_garg_test.cpp +++ b/modules/gapi/test/internal/gapi_int_garg_test.cpp @@ -31,6 +31,7 @@ using GArg_Test_Types = ::testing::Types < // G-API types Expected + , Expected , Expected , Expected, cv::detail::ArgKind::GARRAY> , Expected, cv::detail::ArgKind::GARRAY>