mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 09:25:45 +08:00
Merge pull request #21041 from sivanov-work:gin_gout_concept
G-API: GAPI introduce compile guard for some types for gin/gout params passing * Initial for taged solution * Move out tags to gtags.hpp & add protection for own::Mat * Add compile guard to proper place * Fix MACRO concat * Add unit tests * Remove class MACRO injection due to Python3 * Revert back unproper changes * Apply comments: reuse shape from traits * Throw away unused gtags * Apply comments * Handle own::* * Fix test * Fix test(1) * Fix unix build * Try on type list * Apply comments * Apply comments * Fix warning
This commit is contained in:
parent
f61883b227
commit
c5b8b5687f
@ -19,11 +19,25 @@
|
||||
#include <opencv2/gapi/streaming/source.hpp>
|
||||
#include <opencv2/gapi/media.hpp>
|
||||
#include <opencv2/gapi/gcommon.hpp>
|
||||
#include <opencv2/gapi/util/util.hpp>
|
||||
#include <opencv2/gapi/own/convert.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template<typename, typename = void>
|
||||
struct contains_shape_field : std::false_type {};
|
||||
|
||||
template<typename TaggedTypeCandidate>
|
||||
struct contains_shape_field<TaggedTypeCandidate,
|
||||
void_t<decltype(TaggedTypeCandidate::shape)>> :
|
||||
std::is_same<typename std::decay<decltype(TaggedTypeCandidate::shape)>::type, GShape>
|
||||
{};
|
||||
|
||||
template<typename Type>
|
||||
struct has_gshape : contains_shape_field<Type> {};
|
||||
|
||||
// FIXME: These traits and enum and possible numerous switch(kind)
|
||||
// block may be replaced with a special Handler<T> object or with
|
||||
// a double dispatch
|
||||
@ -181,10 +195,16 @@ namespace detail
|
||||
}
|
||||
template<typename U> static auto wrap_in (const U &u) -> typename GTypeTraits<T>::strip_type
|
||||
{
|
||||
static_assert(!(cv::detail::has_gshape<GTypeTraits<U>>::value
|
||||
|| cv::detail::contains<typename std::decay<U>::type, GAPI_OWN_TYPES_LIST>::value),
|
||||
"gin/gout must not be used with G* classes or cv::gapi::own::*");
|
||||
return GTypeTraits<T>::wrap_in(u);
|
||||
}
|
||||
template<typename U> static auto wrap_out(U &u) -> typename GTypeTraits<T>::strip_type
|
||||
{
|
||||
static_assert(!(cv::detail::has_gshape<GTypeTraits<U>>::value
|
||||
|| cv::detail::contains<typename std::decay<U>::type, GAPI_OWN_TYPES_LIST>::value),
|
||||
"gin/gout must not be used with G* classses or cv::gapi::own::*");
|
||||
return GTypeTraits<T>::wrap_out(u);
|
||||
}
|
||||
};
|
||||
|
@ -14,6 +14,12 @@
|
||||
# include <opencv2/core/cvdef.h>
|
||||
# include <opencv2/core/types.hpp>
|
||||
# include <opencv2/core/base.hpp>
|
||||
#define GAPI_OWN_TYPES_LIST cv::gapi::own::Rect, \
|
||||
cv::gapi::own::Size, \
|
||||
cv::gapi::own::Point, \
|
||||
cv::gapi::own::Point2f, \
|
||||
cv::gapi::own::Scalar, \
|
||||
cv::gapi::own::Mat
|
||||
#else // Without OpenCV
|
||||
# include <opencv2/gapi/own/cvdefs.hpp>
|
||||
# include <opencv2/gapi/own/types.hpp> // cv::gapi::own::Rect/Size/Point
|
||||
@ -28,6 +34,8 @@ namespace cv {
|
||||
using Scalar = gapi::own::Scalar;
|
||||
using Mat = gapi::own::Mat;
|
||||
} // namespace cv
|
||||
#define GAPI_OWN_TYPES_LIST cv::gapi::own::VoidType
|
||||
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
|
||||
#endif // OPENCV_GAPI_OPENCV_INCLUDES_HPP
|
||||
|
@ -143,6 +143,7 @@ inline std::ostream& operator<<(std::ostream& o, const Size& s)
|
||||
return o;
|
||||
}
|
||||
|
||||
struct VoidType {};
|
||||
} // namespace own
|
||||
} // namespace gapi
|
||||
} // namespace cv
|
||||
|
@ -116,6 +116,13 @@ namespace detail
|
||||
using type = std::tuple<Objs...>;
|
||||
static type get(std::tuple<Objs...>&& objs) { return std::forward<std::tuple<Objs...>>(objs); }
|
||||
};
|
||||
|
||||
template<typename... Ts>
|
||||
struct make_void { typedef void type;};
|
||||
|
||||
template<typename... Ts>
|
||||
using void_t = typename make_void<Ts...>::type;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
namespace util
|
||||
|
@ -4,13 +4,32 @@
|
||||
//
|
||||
// Copyright (C) 2018 Intel Corporation
|
||||
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include <opencv2/gapi/gtype_traits.hpp>
|
||||
#include <opencv2/gapi/util/util.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
struct Own {};
|
||||
namespace gapi
|
||||
{
|
||||
namespace own
|
||||
{
|
||||
struct ConvertibleToOwn{};
|
||||
struct NotConvertibleToOwn{};
|
||||
} // own
|
||||
} // gapi
|
||||
} // cv
|
||||
|
||||
struct NoGhape {};
|
||||
struct HasGShape {
|
||||
static constexpr cv::GShape shape = cv::GShape::GFRAME;
|
||||
};
|
||||
struct MimicGShape {
|
||||
static constexpr int shape = 0;
|
||||
};
|
||||
#define DISALLOWED_LIST cv::gapi::own::NotConvertibleToOwn
|
||||
namespace opencv_test
|
||||
{
|
||||
|
||||
@ -40,4 +59,17 @@ TEST(GAPIUtil, AllButLast)
|
||||
"[int, float] are NOT all integral types");
|
||||
}
|
||||
|
||||
TEST(GAPIUtil, GShaped)
|
||||
{
|
||||
static_assert(!cv::detail::has_gshape<NoGhape>::value, "NoGhape hasn't got any shape");
|
||||
static_assert(cv::detail::has_gshape<HasGShape>::value, "HasGShape has got GShape shape");
|
||||
static_assert(!cv::detail::has_gshape<MimicGShape>::value, "MimicGShape hasn't got right shape");
|
||||
}
|
||||
|
||||
TEST(GAPIUtil, GTypeList)
|
||||
{
|
||||
static_assert(cv::detail::contains<cv::gapi::own::NotConvertibleToOwn, GAPI_OWN_TYPES_LIST, DISALLOWED_LIST>::value, "NotConvertibleToOwn is in denial list");
|
||||
static_assert(!cv::detail::contains<cv::gapi::own::ConvertibleToOwn>::value, "ConvertibleToOwn is not in empty denial list");
|
||||
static_assert(!cv::detail::contains<cv::gapi::own::ConvertibleToOwn, GAPI_OWN_TYPES_LIST, DISALLOWED_LIST>::value, "ConvertibleToOwn is not in denial list");
|
||||
}
|
||||
} // namespace opencv_test
|
||||
|
@ -138,22 +138,18 @@ TEST(GMetaArg, Can_Describe_RunArg)
|
||||
cv::Mat m(3, 3, CV_8UC3);
|
||||
cv::UMat um(3, 3, CV_8UC3);
|
||||
cv::Scalar s;
|
||||
constexpr int w = 3, h = 3, c = 3;
|
||||
uchar data[w*h*c];
|
||||
cv::gapi::own::Mat om(h, w, CV_8UC3, data);
|
||||
cv::Scalar os;
|
||||
std::vector<int> v;
|
||||
|
||||
GMetaArgs metas = {GMetaArg(descr_of(m)),
|
||||
GMetaArg(descr_of(um)),
|
||||
GMetaArg(descr_of(s)),
|
||||
GMetaArg(descr_of(om)),
|
||||
GMetaArg(descr_of(os)),
|
||||
GMetaArg(descr_of(v))};
|
||||
|
||||
auto in_run_args = cv::gin(m, um, s, om, os, v);
|
||||
auto in_run_args = cv::gin(m, um, s, os, v);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (size_t i = 0; i < metas.size(); i++) {
|
||||
EXPECT_TRUE(can_describe(metas[i], in_run_args[i]));
|
||||
}
|
||||
}
|
||||
@ -178,22 +174,18 @@ TEST(GMetaArg, Can_Describe_RunArgP)
|
||||
cv::Mat m(3, 3, CV_8UC3);
|
||||
cv::UMat um(3, 3, CV_8UC3);
|
||||
cv::Scalar s;
|
||||
constexpr int w = 3, h = 3, c = 3;
|
||||
uchar data[w*h*c];
|
||||
cv::gapi::own::Mat om(h, w, CV_8UC3, data);
|
||||
cv::Scalar os;
|
||||
std::vector<int> v;
|
||||
|
||||
GMetaArgs metas = {GMetaArg(descr_of(m)),
|
||||
GMetaArg(descr_of(um)),
|
||||
GMetaArg(descr_of(s)),
|
||||
GMetaArg(descr_of(om)),
|
||||
GMetaArg(descr_of(os)),
|
||||
GMetaArg(descr_of(v))};
|
||||
|
||||
auto out_run_args = cv::gout(m, um, s, om, os, v);
|
||||
auto out_run_args = cv::gout(m, um, s, os, v);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (size_t i = 0; i < metas.size(); i++) {
|
||||
EXPECT_TRUE(can_describe(metas[i], out_run_args[i]));
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ struct ProtoPtrTest : public ::testing::Test { using Type = T; };
|
||||
|
||||
using ProtoPtrTestTypes = ::testing::Types< cv::Mat
|
||||
, cv::UMat
|
||||
, cv::gapi::own::Mat
|
||||
, cv::RMat
|
||||
, cv::Scalar
|
||||
, std::vector<int>
|
||||
|
Loading…
Reference in New Issue
Block a user