Skip to content

Commit 0d456f9

Browse files
Merge pull request opencv#16118 from smirnov-alexey:as/gopaque
G-API: GOpaque implementation * Stub initial copypasted solution * Fix mov test and add a couple of others * Fix warnings * More code coverage and tests * fix macos warning * address review comments * Address review comments and fix indentation * Fix build on armv7
1 parent 2ced568 commit 0d456f9

33 files changed

+850
-23
lines changed

modules/gapi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(gapi_srcs
4444
src/api/gorigin.cpp
4545
src/api/gmat.cpp
4646
src/api/garray.cpp
47+
src/api/gopaque.cpp
4748
src/api/gscalar.cpp
4849
src/api/gkernel.cpp
4950
src/api/gbackend.cpp

modules/gapi/include/opencv2/gapi/cpu/gcpukernel.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ class GAPI_EXPORTS GCPUContext
9494
{
9595
return outVecRef(output).wref<T>();
9696
}
97+
template<typename T> T& outOpaqueR(int output) // FIXME: the same issue
98+
{
99+
return outOpaqueRef(output).wref<T>();
100+
}
97101

98102
protected:
99103
detail::VectorRef& outVecRef(int output);
104+
detail::OpaqueRef& outOpaqueRef(int output);
100105

101106
std::vector<GArg> m_args;
102107

@@ -145,12 +150,31 @@ template<typename U> struct get_in<cv::GArray<U> >
145150
{
146151
static const std::vector<U>& get(GCPUContext &ctx, int idx) { return ctx.inArg<VectorRef>(idx).rref<U>(); }
147152
};
153+
template<typename U> struct get_in<cv::GOpaque<U> >
154+
{
155+
static const U& get(GCPUContext &ctx, int idx) { return ctx.inArg<OpaqueRef>(idx).rref<U>(); }
156+
};
148157

149158
//FIXME(dm): GArray<Mat>/GArray<GMat> conversion should be done more gracefully in the system
150159
template<> struct get_in<cv::GArray<cv::GMat> >: public get_in<cv::GArray<cv::Mat> >
151160
{
152161
};
153162

163+
//FIXME(dm): GArray<Scalar>/GArray<GScalar> conversion should be done more gracefully in the system
164+
template<> struct get_in<cv::GArray<cv::GScalar> >: public get_in<cv::GArray<cv::Scalar> >
165+
{
166+
};
167+
168+
//FIXME(dm): GOpaque<Mat>/GOpaque<GMat> conversion should be done more gracefully in the system
169+
template<> struct get_in<cv::GOpaque<cv::GMat> >: public get_in<cv::GOpaque<cv::Mat> >
170+
{
171+
};
172+
173+
//FIXME(dm): GOpaque<Scalar>/GOpaque<GScalar> conversion should be done more gracefully in the system
174+
template<> struct get_in<cv::GOpaque<cv::GScalar> >: public get_in<cv::GOpaque<cv::Mat> >
175+
{
176+
};
177+
154178
template<class T> struct get_in
155179
{
156180
static T get(GCPUContext &ctx, int idx) { return ctx.inArg<T>(idx); }
@@ -229,6 +253,13 @@ template<typename U> struct get_out<cv::GArray<U>>
229253
return ctx.outVecR<U>(idx);
230254
}
231255
};
256+
template<typename U> struct get_out<cv::GOpaque<U>>
257+
{
258+
static U& get(GCPUContext &ctx, int idx)
259+
{
260+
return ctx.outOpaqueR<U>(idx);
261+
}
262+
};
232263

233264
template<typename, typename, typename>
234265
struct OCVCallHelper;

modules/gapi/include/opencv2/gapi/fluid/gfluidkernel.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ template<typename U> struct fluid_get_in<cv::GArray<U>>
200200
}
201201
};
202202

203+
template<typename U> struct fluid_get_in<cv::GOpaque<U>>
204+
{
205+
static const U& get(const cv::GArgs &in_args, int idx)
206+
{
207+
return in_args.at(idx).unsafe_get<cv::detail::OpaqueRef>().rref<U>();
208+
}
209+
};
210+
203211
template<class T> struct fluid_get_in
204212
{
205213
static const T& get(const cv::GArgs &in_args, int idx)

modules/gapi/include/opencv2/gapi/garg.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <opencv2/gapi/gmat.hpp>
2121
#include <opencv2/gapi/gscalar.hpp>
2222
#include <opencv2/gapi/garray.hpp>
23+
#include <opencv2/gapi/gopaque.hpp>
2324
#include <opencv2/gapi/gtype_traits.hpp>
2425
#include <opencv2/gapi/gmetaarg.hpp>
2526
#include <opencv2/gapi/own/scalar.hpp>
@@ -96,7 +97,8 @@ using GRunArg = util::variant<
9697
cv::gapi::wip::IStreamSource::Ptr,
9798
cv::gapi::own::Mat,
9899
cv::gapi::own::Scalar,
99-
cv::detail::VectorRef
100+
cv::detail::VectorRef,
101+
cv::detail::OpaqueRef
100102
>;
101103
using GRunArgs = std::vector<GRunArg>;
102104

@@ -128,7 +130,8 @@ using GRunArgP = util::variant<
128130
#endif // !defined(GAPI_STANDALONE)
129131
cv::gapi::own::Mat*,
130132
cv::gapi::own::Scalar*,
131-
cv::detail::VectorRef
133+
cv::detail::VectorRef,
134+
cv::detail::OpaqueRef
132135
>;
133136
using GRunArgsP = std::vector<GRunArgP>;
134137

modules/gapi/include/opencv2/gapi/gcall.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <opencv2/gapi/gmat.hpp> // GMat
1313
#include <opencv2/gapi/gscalar.hpp> // GScalar
1414
#include <opencv2/gapi/garray.hpp> // GArray<T>
15+
#include <opencv2/gapi/gopaque.hpp> // GOpaque<T>
1516

1617
namespace cv {
1718

@@ -46,6 +47,11 @@ class GAPI_EXPORTS GCall final
4647
return GArray<T>(yieldArray(output));
4748
}
4849

50+
template<class T> GOpaque<T> yieldOpaque(int output = 0)
51+
{
52+
return GOpaque<T>(yieldOpaque(output));
53+
}
54+
4955
// Internal use only
5056
Priv& priv();
5157
const Priv& priv() const;
@@ -55,8 +61,9 @@ class GAPI_EXPORTS GCall final
5561

5662
void setArgs(std::vector<GArg> &&args);
5763

58-
// Public version returns a typed array, this one is implementation detail
64+
// Public versions return a typed array or opaque, those are implementation details
5965
detail::GArrayU yieldArray(int output = 0);
66+
detail::GOpaqueU yieldOpaque(int output = 0);
6067
};
6168

6269
} // namespace cv

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum class GShape: int
4444
GMAT,
4545
GSCALAR,
4646
GARRAY,
47+
GOPAQUE,
4748
};
4849

4950
struct GCompileArg;

modules/gapi/include/opencv2/gapi/gcompoundkernel.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ template<typename U> struct get_compound_in<cv::GArray<U>>
6565
}
6666
};
6767

68+
template<typename U> struct get_compound_in<cv::GOpaque<U>>
69+
{
70+
static cv::GOpaque<U> get(GCompoundContext &ctx, int idx)
71+
{
72+
auto opaq = cv::GOpaque<U>();
73+
ctx.m_args[idx] = GArg(opaq);
74+
return opaq;
75+
}
76+
};
77+
6878
template<typename, typename, typename>
6979
struct GCompoundCallHelper;
7080

modules/gapi/include/opencv2/gapi/gkernel.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ namespace detail
7474
{
7575
static inline cv::GArray<U> yield(cv::GCall &call, int i) { return call.yieldArray<U>(i); }
7676
};
77+
template<typename U> struct Yield<cv::GOpaque<U> >
78+
{
79+
static inline cv::GOpaque<U> yield(cv::GCall &call, int i) { return call.yieldOpaque<U>(i); }
80+
};
7781
} // anonymous namespace
7882

7983
////////////////////////////////////////////////////////////////////////////
@@ -87,7 +91,8 @@ namespace detail
8791
template<> struct MetaType<cv::GMat> { using type = GMatDesc; };
8892
template<> struct MetaType<cv::GMatP> { using type = GMatDesc; };
8993
template<> struct MetaType<cv::GScalar> { using type = GScalarDesc; };
90-
template<typename U> struct MetaType<cv::GArray<U> > { using type = GArrayDesc; };
94+
template<typename U> struct MetaType<cv::GArray<U> > { using type = GArrayDesc; };
95+
template<typename U> struct MetaType<cv::GOpaque<U> > { using type = GOpaqueDesc; };
9196
template<typename T> struct MetaType { using type = T; }; // opaque args passed as-is
9297

9398
// 2. Hacky test based on MetaType to check if we operate on G-* type or not

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct GOrigin;
4646
* cv::GMat | cv::Mat
4747
* cv::GScalar | cv::Scalar
4848
* `cv::GArray<T>` | std::vector<T>
49+
* `cv::GOpaque<T>` | T
4950
*/
5051
class GAPI_EXPORTS GMat
5152
{

modules/gapi/include/opencv2/gapi/gmetaarg.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <opencv2/gapi/gmat.hpp>
1818
#include <opencv2/gapi/gscalar.hpp>
1919
#include <opencv2/gapi/garray.hpp>
20+
#include <opencv2/gapi/gopaque.hpp>
2021

2122
namespace cv
2223
{
@@ -36,6 +37,7 @@ using GMetaArg = util::variant
3637
, GMatDesc
3738
, GScalarDesc
3839
, GArrayDesc
40+
, GOpaqueDesc
3941
>;
4042
GAPI_EXPORTS std::ostream& operator<<(std::ostream& os, const GMetaArg &);
4143

@@ -52,6 +54,7 @@ namespace detail
5254
template<> struct is_meta_descr<GMatDesc> : std::true_type {};
5355
template<> struct is_meta_descr<GScalarDesc> : std::true_type {};
5456
template<> struct is_meta_descr<GArrayDesc> : std::true_type {};
57+
template<> struct is_meta_descr<GOpaqueDesc> : std::true_type {};
5558

5659
template<typename... Ts>
5760
using are_meta_descrs = all_satisfy<is_meta_descr, Ts...>;

0 commit comments

Comments
 (0)