Skip to content

Commit e937d9b

Browse files
authored
Merge pull request opencv#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
1 parent 3fc1487 commit e937d9b

File tree

8 files changed

+110
-17
lines changed

8 files changed

+110
-17
lines changed

modules/gapi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ set(gapi_srcs
6161
src/api/garray.cpp
6262
src/api/gopaque.cpp
6363
src/api/gscalar.cpp
64+
src/api/gframe.cpp
6465
src/api/gkernel.cpp
6566
src/api/gbackend.cpp
6667
src/api/gproto.cpp

modules/gapi/include/opencv2/gapi/gcommon.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ enum class GShape: int
8484
GSCALAR,
8585
GARRAY,
8686
GOPAQUE,
87+
GFRAME,
8788
};
8889

8990
struct GCompileArg;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
//
5+
// Copyright (C) 2020 Intel Corporation
6+
7+
8+
#ifndef OPENCV_GAPI_GFRAME_HPP
9+
#define OPENCV_GAPI_GFRAME_HPP
10+
11+
#include <ostream>
12+
#include <memory> // std::shared_ptr
13+
14+
#include <opencv2/gapi/opencv_includes.hpp>
15+
#include <opencv2/gapi/gcommon.hpp> // GShape
16+
17+
#include <opencv2/gapi/gmat.hpp>
18+
#include <opencv2/gapi/own/assert.hpp>
19+
20+
// TODO GAPI_EXPORTS or so
21+
namespace cv
22+
{
23+
// Forward declaration; GNode and GOrigin are an internal
24+
// (user-inaccessible) classes.
25+
class GNode;
26+
struct GOrigin;
27+
28+
/** \addtogroup gapi_data_objects
29+
* @{
30+
*/
31+
class GAPI_EXPORTS_W_SIMPLE GFrame
32+
{
33+
public:
34+
GAPI_WRAP GFrame(); // Empty constructor
35+
GFrame(const GNode &n, std::size_t out); // Operation result constructor
36+
37+
GOrigin& priv(); // Internal use only
38+
const GOrigin& priv() const; // Internal use only
39+
40+
private:
41+
std::shared_ptr<GOrigin> m_priv;
42+
};
43+
/** @} */
44+
45+
/**
46+
* \addtogroup gapi_meta_args
47+
* @{
48+
*/
49+
struct GAPI_EXPORTS GFrameDesc
50+
{
51+
};
52+
static inline GFrameDesc empty_gframe_desc() { return GFrameDesc{}; }
53+
/** @} */
54+
55+
GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const cv::GFrameDesc &desc);
56+
57+
} // namespace cv
58+
59+
#endif // OPENCV_GAPI_GFRAME_HPP

modules/gapi/include/opencv2/gapi/gmat.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// It is subject to the license terms in the LICENSE file found in the top-level directory
33
// of this distribution and at http://opencv.org/license.html.
44
//
5-
// Copyright (C) 2018 Intel Corporation
5+
// Copyright (C) 2018-2020 Intel Corporation
66

77

88
#ifndef OPENCV_GAPI_GMAT_HPP
@@ -65,12 +65,6 @@ class GAPI_EXPORTS GMatP : public GMat
6565
using GMat::GMat;
6666
};
6767

68-
class GAPI_EXPORTS GFrame : public GMat
69-
{
70-
public:
71-
using GMat::GMat;
72-
};
73-
7468
/** @} */
7569

7670
/**

modules/gapi/include/opencv2/gapi/gtype_traits.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <opencv2/gapi/gscalar.hpp>
1616
#include <opencv2/gapi/garray.hpp>
1717
#include <opencv2/gapi/gopaque.hpp>
18+
#include <opencv2/gapi/gframe.hpp>
1819
#include <opencv2/gapi/streaming/source.hpp>
1920
#include <opencv2/gapi/gcommon.hpp>
2021

modules/gapi/src/api/gframe.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
//
5+
// Copyright (C) 2020 Intel Corporation
6+
7+
8+
#include "precomp.hpp"
9+
10+
#include <opencv2/gapi/gframe.hpp>
11+
12+
#include "api/gorigin.hpp"
13+
14+
// cv::GFrame public implementation //////////////////////////////////////////////
15+
cv::GFrame::GFrame()
16+
: m_priv(new GOrigin(GShape::GMAT, GNode::Param())) {
17+
// N.B.: The shape here is still GMAT as currently cv::Mat is used
18+
// as an underlying host type. Will be changed to GFRAME once
19+
// GExecutor & GStreamingExecutor & selected backends will be extended
20+
// to support cv::MediaFrame.
21+
}
22+
23+
cv::GFrame::GFrame(const GNode &n, std::size_t out)
24+
: m_priv(new GOrigin(GShape::GMAT, n, out)) {
25+
// N.B.: GMAT is here for the same reason as above ^
26+
}
27+
28+
cv::GOrigin& cv::GFrame::priv() {
29+
return *m_priv;
30+
}
31+
32+
const cv::GOrigin& cv::GFrame::priv() const {
33+
return *m_priv;
34+
}
35+
36+
namespace cv {
37+
std::ostream& operator<<(std::ostream& os, const cv::GFrameDesc &) {
38+
return os;
39+
}
40+
41+
} // namespace cv

modules/gapi/src/backends/fluid/gfluidbackend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,7 @@ void cv::gimpl::GFluidExecutable::bindInArg(const cv::gimpl::RcDesc &rc, const G
12491249
case GShape::GSCALAR: m_res.slot<cv::Scalar>()[rc.id] = util::get<cv::Scalar>(arg); break;
12501250
case GShape::GARRAY: m_res.slot<cv::detail::VectorRef>()[rc.id] = util::get<cv::detail::VectorRef>(arg); break;
12511251
case GShape::GOPAQUE: m_res.slot<cv::detail::OpaqueRef>()[rc.id] = util::get<cv::detail::OpaqueRef>(arg); break;
1252+
default: util::throw_error(std::logic_error("Unsupported input GShape type"));
12521253
}
12531254
}
12541255

modules/gapi/test/gapi_frame_tests.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ G_API_OP(GBlurFrame, <GMat(GFrame)>, "test.blur_frame") {
1717
}
1818
};
1919

20-
GAPI_OCV_KERNEL(OCVBlurFrame, GBlurFrame)
21-
{
20+
GAPI_OCV_KERNEL(OCVBlurFrame, GBlurFrame) {
2221
static void run(const cv::Mat& in, cv::Mat& out) {
2322
cv::blur(in, out, cv::Size{3,3});
2423
}
2524
};
2625

27-
struct GFrameTest : public ::testing::Test
28-
{
26+
struct GFrameTest : public ::testing::Test {
2927
cv::Size sz{32,32};
3028
cv::Mat in_mat;
3129
cv::Mat out_mat;
@@ -34,20 +32,17 @@ struct GFrameTest : public ::testing::Test
3432
GFrameTest()
3533
: in_mat(cv::Mat(sz, CV_8UC1))
3634
, out_mat(cv::Mat::zeros(sz, CV_8UC1))
37-
, out_mat_ocv(cv::Mat::zeros(sz, CV_8UC1))
38-
{
35+
, out_mat_ocv(cv::Mat::zeros(sz, CV_8UC1)) {
3936
cv::randn(in_mat, cv::Scalar::all(127.0f), cv::Scalar::all(40.f));
4037
cv::blur(in_mat, out_mat_ocv, cv::Size{3,3});
4138
}
4239

43-
void check()
44-
{
40+
void check() {
4541
EXPECT_EQ(0, cvtest::norm(out_mat, out_mat_ocv, NORM_INF));
4642
}
4743
};
4844

49-
TEST_F(GFrameTest, Input)
50-
{
45+
TEST_F(GFrameTest, Input) {
5146
cv::GFrame in;
5247
auto out = GBlurFrame::on(in);
5348
cv::GComputation c(cv::GIn(in), cv::GOut(out));

0 commit comments

Comments
 (0)