From e937d9b559d99ab0244ab9413bb2402e946c5786 Mon Sep 17 00:00:00 2001 From: Dmitry Matveev Date: Wed, 23 Sep 2020 21:25:14 +0300 Subject: [PATCH] Merge pull request #18391 from dmatveev:dm/gframe_00_new_type * G-API: Make GFrame a new (distinct) G-type, not an alias to GMat - The underlying host type is still cv::Mat, a new cv::MediaFrame type is to be added as a separate PR * Fix warnings and review comments - Somewhow there was a switch() without a default: clause in Fluid --- modules/gapi/CMakeLists.txt | 1 + modules/gapi/include/opencv2/gapi/gcommon.hpp | 1 + modules/gapi/include/opencv2/gapi/gframe.hpp | 59 +++++++++++++++++++ modules/gapi/include/opencv2/gapi/gmat.hpp | 8 +-- .../include/opencv2/gapi/gtype_traits.hpp | 1 + modules/gapi/src/api/gframe.cpp | 41 +++++++++++++ .../gapi/src/backends/fluid/gfluidbackend.cpp | 1 + modules/gapi/test/gapi_frame_tests.cpp | 15 ++--- 8 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 modules/gapi/include/opencv2/gapi/gframe.hpp create mode 100644 modules/gapi/src/api/gframe.cpp diff --git a/modules/gapi/CMakeLists.txt b/modules/gapi/CMakeLists.txt index 692a1c1423..76d4577774 100644 --- a/modules/gapi/CMakeLists.txt +++ b/modules/gapi/CMakeLists.txt @@ -61,6 +61,7 @@ set(gapi_srcs src/api/garray.cpp src/api/gopaque.cpp src/api/gscalar.cpp + src/api/gframe.cpp src/api/gkernel.cpp src/api/gbackend.cpp src/api/gproto.cpp diff --git a/modules/gapi/include/opencv2/gapi/gcommon.hpp b/modules/gapi/include/opencv2/gapi/gcommon.hpp index 27b154b4b2..dc2c8b9bd7 100644 --- a/modules/gapi/include/opencv2/gapi/gcommon.hpp +++ b/modules/gapi/include/opencv2/gapi/gcommon.hpp @@ -84,6 +84,7 @@ enum class GShape: int GSCALAR, GARRAY, GOPAQUE, + GFRAME, }; struct GCompileArg; diff --git a/modules/gapi/include/opencv2/gapi/gframe.hpp b/modules/gapi/include/opencv2/gapi/gframe.hpp new file mode 100644 index 0000000000..7e19dbf7f7 --- /dev/null +++ b/modules/gapi/include/opencv2/gapi/gframe.hpp @@ -0,0 +1,59 @@ +// 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 + + +#ifndef OPENCV_GAPI_GFRAME_HPP +#define OPENCV_GAPI_GFRAME_HPP + +#include +#include // std::shared_ptr + +#include +#include // GShape + +#include +#include + +// TODO GAPI_EXPORTS or so +namespace cv +{ +// Forward declaration; GNode and GOrigin are an internal +// (user-inaccessible) classes. +class GNode; +struct GOrigin; + +/** \addtogroup gapi_data_objects + * @{ + */ +class GAPI_EXPORTS_W_SIMPLE GFrame +{ +public: + GAPI_WRAP GFrame(); // Empty constructor + GFrame(const GNode &n, std::size_t out); // Operation result constructor + + GOrigin& priv(); // Internal use only + const GOrigin& priv() const; // Internal use only + +private: + std::shared_ptr m_priv; +}; +/** @} */ + +/** + * \addtogroup gapi_meta_args + * @{ + */ +struct GAPI_EXPORTS GFrameDesc +{ +}; +static inline GFrameDesc empty_gframe_desc() { return GFrameDesc{}; } +/** @} */ + +GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GFrameDesc &desc); + +} // namespace cv + +#endif // OPENCV_GAPI_GFRAME_HPP diff --git a/modules/gapi/include/opencv2/gapi/gmat.hpp b/modules/gapi/include/opencv2/gapi/gmat.hpp index 6e04f3ce1a..b38ce48c97 100644 --- a/modules/gapi/include/opencv2/gapi/gmat.hpp +++ b/modules/gapi/include/opencv2/gapi/gmat.hpp @@ -2,7 +2,7 @@ // 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) 2018 Intel Corporation +// Copyright (C) 2018-2020 Intel Corporation #ifndef OPENCV_GAPI_GMAT_HPP @@ -65,12 +65,6 @@ public: using GMat::GMat; }; -class GAPI_EXPORTS GFrame : public GMat -{ -public: - using GMat::GMat; -}; - /** @} */ /** diff --git a/modules/gapi/include/opencv2/gapi/gtype_traits.hpp b/modules/gapi/include/opencv2/gapi/gtype_traits.hpp index 9b1c693c0e..3235b1a373 100644 --- a/modules/gapi/include/opencv2/gapi/gtype_traits.hpp +++ b/modules/gapi/include/opencv2/gapi/gtype_traits.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include diff --git a/modules/gapi/src/api/gframe.cpp b/modules/gapi/src/api/gframe.cpp new file mode 100644 index 0000000000..405924bb0d --- /dev/null +++ b/modules/gapi/src/api/gframe.cpp @@ -0,0 +1,41 @@ +// 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 "precomp.hpp" + +#include + +#include "api/gorigin.hpp" + +// cv::GFrame public implementation ////////////////////////////////////////////// +cv::GFrame::GFrame() + : m_priv(new GOrigin(GShape::GMAT, GNode::Param())) { + // N.B.: The shape here is still GMAT as currently cv::Mat is used + // as an underlying host type. Will be changed to GFRAME once + // GExecutor & GStreamingExecutor & selected backends will be extended + // to support cv::MediaFrame. +} + +cv::GFrame::GFrame(const GNode &n, std::size_t out) + : m_priv(new GOrigin(GShape::GMAT, n, out)) { + // N.B.: GMAT is here for the same reason as above ^ +} + +cv::GOrigin& cv::GFrame::priv() { + return *m_priv; +} + +const cv::GOrigin& cv::GFrame::priv() const { + return *m_priv; +} + +namespace cv { +std::ostream& operator<<(std::ostream& os, const cv::GFrameDesc &) { + return os; +} + +} // namespace cv diff --git a/modules/gapi/src/backends/fluid/gfluidbackend.cpp b/modules/gapi/src/backends/fluid/gfluidbackend.cpp index ccc1418e57..e103c70f78 100644 --- a/modules/gapi/src/backends/fluid/gfluidbackend.cpp +++ b/modules/gapi/src/backends/fluid/gfluidbackend.cpp @@ -1249,6 +1249,7 @@ void cv::gimpl::GFluidExecutable::bindInArg(const cv::gimpl::RcDesc &rc, const G case GShape::GSCALAR: m_res.slot()[rc.id] = util::get(arg); break; case GShape::GARRAY: m_res.slot()[rc.id] = util::get(arg); break; case GShape::GOPAQUE: m_res.slot()[rc.id] = util::get(arg); break; + default: util::throw_error(std::logic_error("Unsupported input GShape type")); } } diff --git a/modules/gapi/test/gapi_frame_tests.cpp b/modules/gapi/test/gapi_frame_tests.cpp index 3b03ee0592..04fa21ef5b 100644 --- a/modules/gapi/test/gapi_frame_tests.cpp +++ b/modules/gapi/test/gapi_frame_tests.cpp @@ -17,15 +17,13 @@ G_API_OP(GBlurFrame, , "test.blur_frame") { } }; -GAPI_OCV_KERNEL(OCVBlurFrame, GBlurFrame) -{ +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 -{ +struct GFrameTest : public ::testing::Test { cv::Size sz{32,32}; cv::Mat in_mat; cv::Mat out_mat; @@ -34,20 +32,17 @@ struct GFrameTest : public ::testing::Test 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)) - { + , 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() - { + void check() { EXPECT_EQ(0, cvtest::norm(out_mat, out_mat_ocv, NORM_INF)); } }; -TEST_F(GFrameTest, Input) -{ +TEST_F(GFrameTest, Input) { cv::GFrame in; auto out = GBlurFrame::on(in); cv::GComputation c(cv::GIn(in), cv::GOut(out));