Merge pull request #16963 from rgarnov:rg/gframe

pull/16996/head
Alexander Alekhin 5 years ago
commit a10385543b
  1. 4
      modules/gapi/include/opencv2/gapi/cpu/gcpukernel.hpp
  2. 3
      modules/gapi/include/opencv2/gapi/gkernel.hpp
  3. 6
      modules/gapi/include/opencv2/gapi/gmat.hpp
  4. 1
      modules/gapi/include/opencv2/gapi/gproto.hpp
  5. 6
      modules/gapi/include/opencv2/gapi/gtype_traits.hpp
  6. 5
      modules/gapi/src/api/gproto.cpp
  7. 1
      modules/gapi/src/compiler/gcompiler.cpp
  8. 61
      modules/gapi/test/gapi_frame_tests.cpp
  9. 1
      modules/gapi/test/internal/gapi_int_garg_test.cpp

@ -153,6 +153,10 @@ 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::GFrame>
{
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 ctx.inVal(idx); }

@ -90,6 +90,7 @@ namespace detail
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::GFrame> { using type = GMatDesc; };
template<> struct MetaType<cv::GScalar> { using type = GScalarDesc; };
template<typename U> struct MetaType<cv::GArray<U> > { using type = GArrayDesc; };
template<typename U> struct MetaType<cv::GOpaque<U> > { using type = GOpaqueDesc; };
@ -220,6 +221,8 @@ public:
using InArgs = std::tuple<Args...>;
using OutArgs = std::tuple<R>;
static_assert(!cv::detail::contains<GFrame, OutArgs>::value, "Values of GFrame type can't be used as operation outputs");
static R on(Args... args)
{
cv::GCall call(GKernel{K::id(), K::tag(), &K::getOutMeta, {detail::GTypeTraits<R>::shape}});

@ -65,6 +65,12 @@ public:
using GMat::GMat;
};
class GAPI_EXPORTS GFrame : public GMat
{
public:
using GMat::GMat;
};
namespace gapi { namespace own {
class Mat;
}}//gapi::own

@ -36,6 +36,7 @@ namespace cv {
using GProtoArg = util::variant
< GMat
, GMatP
, GFrame
, GScalar
, detail::GArrayU // instead of GArray<T>
, detail::GOpaqueU // instead of GOpaque<T>

@ -36,6 +36,7 @@ namespace detail
GOBJREF, // <internal> reference to object
GMAT, // a cv::GMat
GMATP, // a cv::GMatP
GFRAME, // a cv::GFrame
GSCALAR, // a cv::GScalar
GARRAY, // a cv::GArrayU (note - exactly GArrayU, not GArray<T>!)
GOPAQUE, // a cv::GOpaqueU (note - exactly GOpaqueU, not GOpaque<T>!)
@ -60,6 +61,11 @@ namespace detail
static constexpr const ArgKind kind = ArgKind::GMATP;
static constexpr const GShape shape = GShape::GMAT;
};
template<> struct GTypeTraits<cv::GFrame>
{
static constexpr const ArgKind kind = ArgKind::GFRAME;
static constexpr const GShape shape = GShape::GMAT;
};
template<> struct GTypeTraits<cv::GScalar>
{
static constexpr const ArgKind kind = ArgKind::GSCALAR;

@ -28,6 +28,9 @@ const cv::GOrigin& cv::gimpl::proto::origin_of(const cv::GProtoArg &arg)
case cv::GProtoArg::index_of<cv::GMatP>():
return util::get<cv::GMatP>(arg).priv();
case cv::GProtoArg::index_of<cv::GFrame>():
return util::get<cv::GFrame>(arg).priv();
case cv::GProtoArg::index_of<cv::GScalar>():
return util::get<cv::GScalar>(arg).priv();
@ -60,6 +63,7 @@ bool cv::gimpl::proto::is_dynamic(const cv::GArg& arg)
{
case detail::ArgKind::GMAT:
case detail::ArgKind::GMATP:
case detail::ArgKind::GFRAME:
case detail::ArgKind::GSCALAR:
case detail::ArgKind::GARRAY:
case detail::ArgKind::GOPAQUE:
@ -87,6 +91,7 @@ cv::GProtoArg cv::gimpl::proto::rewrap(const cv::GArg &arg)
{
case detail::ArgKind::GMAT: return GProtoArg(arg.get<cv::GMat>());
case detail::ArgKind::GMATP: return GProtoArg(arg.get<cv::GMatP>());
case detail::ArgKind::GFRAME: return GProtoArg(arg.get<cv::GFrame>());
case detail::ArgKind::GSCALAR: return GProtoArg(arg.get<cv::GScalar>());
case detail::ArgKind::GARRAY: return GProtoArg(arg.get<cv::detail::GArrayU>());
case detail::ArgKind::GOPAQUE: return GProtoArg(arg.get<cv::detail::GOpaqueU>());

@ -324,6 +324,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>():
case GProtoArg::index_of<cv::GFrame>():
return util::holds_alternative<cv::GMatDesc>(meta);
case GProtoArg::index_of<cv::GScalar>():

@ -0,0 +1,61 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2020 Intel Corporation
#include "test_precomp.hpp"
#include <opencv2/gapi/cpu/gcpukernel.hpp>
namespace opencv_test
{
G_API_OP(GBlurFrame, <GMat(GFrame)>, "test.blur_frame") {
static GMatDesc outMeta(GMatDesc in) {
return in;
}
};
GAPI_OCV_KERNEL(OCVBlurFrame, GBlurFrame)
{
static void run(const cv::Mat& in, cv::Mat& out) {
cv::blur(in, out, cv::Size{3,3});
}
};
struct GFrameTest : public ::testing::Test
{
cv::Size sz{32,32};
cv::Mat in_mat;
cv::Mat out_mat;
cv::Mat out_mat_ocv;
GFrameTest()
: in_mat(cv::Mat(sz, CV_8UC1))
, out_mat(cv::Mat::zeros(sz, CV_8UC1))
, out_mat_ocv(cv::Mat::zeros(sz, CV_8UC1))
{
cv::randn(in_mat, cv::Scalar::all(127.0f), cv::Scalar::all(40.f));
cv::blur(in_mat, out_mat_ocv, cv::Size{3,3});
}
void check()
{
EXPECT_EQ(0, cvtest::norm(out_mat, out_mat_ocv, NORM_INF));
}
};
TEST_F(GFrameTest, Input)
{
cv::GFrame in;
auto out = GBlurFrame::on(in);
cv::GComputation c(cv::GIn(in), cv::GOut(out));
auto pkg = cv::gapi::kernels<OCVBlurFrame>();
c.apply(cv::gin(in_mat), cv::gout(out_mat), cv::compile_args(pkg));
check();
}
} // namespace opencv_test

@ -32,6 +32,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::GFrame, cv::detail::ArgKind::GFRAME>
, Expected<cv::GScalar, cv::detail::ArgKind::GSCALAR>
, Expected<cv::GArray<int>, cv::detail::ArgKind::GARRAY>
, Expected<cv::GArray<float>, cv::detail::ArgKind::GARRAY>

Loading…
Cancel
Save