Merge pull request #16805 from Volskig:mp/ocv-gapi-standalone-scalar
G-API: Unification of own:: Scalar with cv:: Scalar * cvdefs.hpp * Small changes * Deowned Scalar. Does't work * Something * Removed to_ocv for Scalar * Clear code * Deleted whitespaces * Added include<..own/scalar.hpp in cvdefs.hpp. * Long string split on two now * Comment about scalar * Comment about crutch * Removed second varible in scalar_wrapper * Changed wrapper for scalar, alignment * Alignment * Whitespaces * Removed scalar_wrapper
This commit is contained in:
committed by
GitHub
parent
d448a636f8
commit
557ac3dbaf
@@ -99,8 +99,8 @@ public:
|
||||
const cv::gapi::own::Mat& inMat(int input);
|
||||
cv::gapi::own::Mat& outMatR(int output); // FIXME: Avoid cv::gapi::own::Mat m = ctx.outMatR()
|
||||
|
||||
const cv::gapi::own::Scalar& inVal(int input);
|
||||
cv::gapi::own::Scalar& outValR(int output); // FIXME: Avoid cv::gapi::own::Scalar s = ctx.outValR()
|
||||
const cv::Scalar& inVal(int input);
|
||||
cv::Scalar& outValR(int output); // FIXME: Avoid cv::Scalar s = ctx.outValR()
|
||||
template<typename T> std::vector<T>& outVecR(int output) // FIXME: the same issue
|
||||
{
|
||||
return outVecRef(output).wref<T>();
|
||||
@@ -155,7 +155,7 @@ template<> struct get_in<cv::GMatP>
|
||||
};
|
||||
template<> struct get_in<cv::GScalar>
|
||||
{
|
||||
static cv::Scalar get(GCPUContext &ctx, int idx) { return to_ocv(ctx.inVal(idx)); }
|
||||
static cv::Scalar get(GCPUContext &ctx, int idx) { return ctx.inVal(idx); }
|
||||
};
|
||||
template<typename U> struct get_in<cv::GArray<U> >
|
||||
{
|
||||
@@ -208,23 +208,12 @@ struct tracked_cv_mat{
|
||||
}
|
||||
};
|
||||
|
||||
struct scalar_wrapper
|
||||
{
|
||||
scalar_wrapper(cv::gapi::own::Scalar& s) : m_s{cv::gapi::own::to_ocv(s)}, m_org_s(s) {};
|
||||
operator cv::Scalar& () { return m_s; }
|
||||
void writeBack() const { m_org_s = to_own(m_s); }
|
||||
|
||||
cv::Scalar m_s;
|
||||
cv::gapi::own::Scalar& m_org_s;
|
||||
};
|
||||
|
||||
template<typename... Outputs>
|
||||
void postprocess(Outputs&... outs)
|
||||
{
|
||||
struct
|
||||
{
|
||||
void operator()(tracked_cv_mat* bm) { bm->validate(); }
|
||||
void operator()(scalar_wrapper* sw) { sw->writeBack(); }
|
||||
void operator()(...) { }
|
||||
|
||||
} validate;
|
||||
@@ -251,10 +240,9 @@ template<> struct get_out<cv::GMatP>
|
||||
};
|
||||
template<> struct get_out<cv::GScalar>
|
||||
{
|
||||
static scalar_wrapper get(GCPUContext &ctx, int idx)
|
||||
static cv::Scalar& get(GCPUContext &ctx, int idx)
|
||||
{
|
||||
auto& s = ctx.outValR(idx);
|
||||
return {s};
|
||||
return ctx.outValR(idx);
|
||||
}
|
||||
};
|
||||
template<typename U> struct get_out<cv::GArray<U>>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <opencv2/gapi/gmat.hpp>
|
||||
|
||||
#include <opencv2/gapi/util/optional.hpp>
|
||||
#include <opencv2/gapi/own/scalar.hpp>
|
||||
#include <opencv2/gapi/own/mat.hpp>
|
||||
|
||||
namespace cv {
|
||||
@@ -27,13 +26,11 @@ namespace fluid {
|
||||
|
||||
struct Border
|
||||
{
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
// This constructor is required to support existing kernels which are part of G-API
|
||||
Border(int _type, cv::Scalar _val) : type(_type), value(to_own(_val)) {};
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
Border(int _type, cv::gapi::own::Scalar _val) : type(_type), value(_val) {};
|
||||
Border(int _type, cv::Scalar _val) : type(_type), value(_val) {};
|
||||
|
||||
int type;
|
||||
cv::gapi::own::Scalar value;
|
||||
cv::Scalar value;
|
||||
};
|
||||
|
||||
using BorderOpt = util::optional<Border>;
|
||||
|
||||
@@ -179,17 +179,10 @@ template<> struct fluid_get_in<cv::GMat>
|
||||
template<> struct fluid_get_in<cv::GScalar>
|
||||
{
|
||||
// FIXME: change to return by reference when moved to own::Scalar
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
static const cv::Scalar get(const cv::GArgs &in_args, int idx)
|
||||
{
|
||||
return cv::gapi::own::to_ocv(in_args[idx].unsafe_get<cv::gapi::own::Scalar>());
|
||||
return in_args[idx].unsafe_get<cv::Scalar>();
|
||||
}
|
||||
#else
|
||||
static const cv::gapi::own::Scalar get(const cv::GArgs &in_args, int idx)
|
||||
{
|
||||
return in_args[idx].get<cv::gapi::own::Scalar>();
|
||||
}
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
};
|
||||
|
||||
template<typename U> struct fluid_get_in<cv::GArray<U>>
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <opencv2/gapi/gopaque.hpp>
|
||||
#include <opencv2/gapi/gtype_traits.hpp>
|
||||
#include <opencv2/gapi/gmetaarg.hpp>
|
||||
#include <opencv2/gapi/own/scalar.hpp>
|
||||
#include <opencv2/gapi/streaming/source.hpp>
|
||||
|
||||
namespace cv {
|
||||
@@ -91,12 +90,11 @@ using GArgs = std::vector<GArg>;
|
||||
using GRunArg = util::variant<
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
cv::Mat,
|
||||
cv::Scalar,
|
||||
cv::UMat,
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
cv::gapi::wip::IStreamSource::Ptr,
|
||||
cv::gapi::own::Mat,
|
||||
cv::gapi::own::Scalar,
|
||||
cv::Scalar,
|
||||
cv::detail::VectorRef,
|
||||
cv::detail::OpaqueRef
|
||||
>;
|
||||
@@ -125,11 +123,10 @@ struct Data: public GRunArg
|
||||
using GRunArgP = util::variant<
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
cv::Mat*,
|
||||
cv::Scalar*,
|
||||
cv::UMat*,
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
cv::gapi::own::Mat*,
|
||||
cv::gapi::own::Scalar*,
|
||||
cv::Scalar*,
|
||||
cv::detail::VectorRef,
|
||||
cv::detail::OpaqueRef
|
||||
>;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <opencv2/gapi/opencv_includes.hpp>
|
||||
#include <opencv2/gapi/gcommon.hpp> // GShape
|
||||
#include <opencv2/gapi/util/optional.hpp>
|
||||
#include <opencv2/gapi/own/scalar.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -31,11 +30,9 @@ class GAPI_EXPORTS GScalar
|
||||
{
|
||||
public:
|
||||
GScalar(); // Empty constructor
|
||||
explicit GScalar(const cv::gapi::own::Scalar& s); // Constant value constructor from cv::gapi::own::Scalar
|
||||
explicit GScalar(cv::gapi::own::Scalar&& s); // Constant value move-constructor from cv::gapi::own::Scalar
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
explicit GScalar(const cv::Scalar& s); // Constant value constructor from cv::Scalar
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
explicit GScalar(const cv::Scalar& s); // Constant value constructor from cv::Scalar
|
||||
explicit GScalar(cv::Scalar&& s); // Constant value move-constructor from cv::Scalar
|
||||
|
||||
GScalar(double v0); // Constant value constructor from double
|
||||
GScalar(const GNode &n, std::size_t out); // Operation result constructor
|
||||
|
||||
@@ -69,12 +66,7 @@ struct GScalarDesc
|
||||
|
||||
static inline GScalarDesc empty_scalar_desc() { return GScalarDesc(); }
|
||||
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
GAPI_EXPORTS GScalarDesc descr_of(const cv::Scalar &scalar);
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
/** @} */
|
||||
|
||||
GAPI_EXPORTS GScalarDesc descr_of(const cv::gapi::own::Scalar &scalar);
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const cv::GScalarDesc &desc);
|
||||
|
||||
|
||||
@@ -107,10 +107,9 @@ namespace detail
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
template<> struct GTypeOf<cv::Mat> { using type = cv::GMat; };
|
||||
template<> struct GTypeOf<cv::UMat> { using type = cv::GMat; };
|
||||
template<> struct GTypeOf<cv::Scalar> { using type = cv::GScalar; };
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
template<> struct GTypeOf<cv::gapi::own::Mat> { using type = cv::GMat; };
|
||||
template<> struct GTypeOf<cv::gapi::own::Scalar> { using type = cv::GScalar; };
|
||||
template<> struct GTypeOf<cv::Scalar> { using type = cv::GScalar; };
|
||||
template<typename U> struct GTypeOf<std::vector<U> > { using type = cv::GArray<U>; };
|
||||
template<typename U> struct GTypeOf { using type = cv::GOpaque<U>;};
|
||||
// FIXME: This is not quite correct since IStreamSource may produce not only Mat but also Scalar
|
||||
|
||||
@@ -62,8 +62,8 @@ public:
|
||||
const cv::UMat& inMat(int input);
|
||||
cv::UMat& outMatR(int output); // FIXME: Avoid cv::Mat m = ctx.outMatR()
|
||||
|
||||
const cv::gapi::own::Scalar& inVal(int input);
|
||||
cv::gapi::own::Scalar& outValR(int output); // FIXME: Avoid cv::gapi::own::Scalar s = ctx.outValR()
|
||||
const cv::Scalar& inVal(int input);
|
||||
cv::Scalar& outValR(int output); // FIXME: Avoid cv::Scalar s = ctx.outValR()
|
||||
template<typename T> std::vector<T>& outVecR(int output) // FIXME: the same issue
|
||||
{
|
||||
return outVecRef(output).wref<T>();
|
||||
@@ -110,7 +110,7 @@ template<> struct ocl_get_in<cv::GMat>
|
||||
};
|
||||
template<> struct ocl_get_in<cv::GScalar>
|
||||
{
|
||||
static cv::Scalar get(GOCLContext &ctx, int idx) { return to_ocv(ctx.inVal(idx)); }
|
||||
static cv::Scalar get(GOCLContext &ctx, int idx) { return ctx.inVal(idx); }
|
||||
};
|
||||
template<typename U> struct ocl_get_in<cv::GArray<U> >
|
||||
{
|
||||
@@ -146,24 +146,12 @@ struct tracked_cv_umat{
|
||||
}
|
||||
};
|
||||
|
||||
struct scalar_wrapper_ocl
|
||||
{
|
||||
//FIXME reuse CPU (OpenCV) plugin code
|
||||
scalar_wrapper_ocl(cv::gapi::own::Scalar& s) : m_s{cv::gapi::own::to_ocv(s)}, m_org_s(s) {};
|
||||
operator cv::Scalar& () { return m_s; }
|
||||
void writeBack() const { m_org_s = to_own(m_s); }
|
||||
|
||||
cv::Scalar m_s;
|
||||
cv::gapi::own::Scalar& m_org_s;
|
||||
};
|
||||
|
||||
template<typename... Outputs>
|
||||
void postprocess_ocl(Outputs&... outs)
|
||||
{
|
||||
struct
|
||||
{
|
||||
void operator()(tracked_cv_umat* bm) { bm->validate(); }
|
||||
void operator()(scalar_wrapper_ocl* sw) { sw->writeBack(); }
|
||||
void operator()(...) { }
|
||||
|
||||
} validate;
|
||||
@@ -183,10 +171,9 @@ template<> struct ocl_get_out<cv::GMat>
|
||||
};
|
||||
template<> struct ocl_get_out<cv::GScalar>
|
||||
{
|
||||
static scalar_wrapper_ocl get(GOCLContext &ctx, int idx)
|
||||
static cv::Scalar& get(GOCLContext &ctx, int idx)
|
||||
{
|
||||
auto& s = ctx.outValR(idx);
|
||||
return{ s };
|
||||
return ctx.outValR(idx);
|
||||
}
|
||||
};
|
||||
template<typename U> struct ocl_get_out<cv::GArray<U> >
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <opencv2/gapi/opencv_includes.hpp>
|
||||
#include <opencv2/gapi/own/types.hpp>
|
||||
#include <opencv2/gapi/own/mat.hpp>
|
||||
#include <opencv2/gapi/own/scalar.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
@@ -35,9 +34,6 @@ namespace cv
|
||||
: cv::gapi::own::Mat{to_own<int>(m.size), m.type(), m.data};
|
||||
};
|
||||
|
||||
|
||||
inline cv::gapi::own::Scalar to_own(const cv::Scalar& s) { return {s[0], s[1], s[2], s[3]}; };
|
||||
|
||||
inline cv::gapi::own::Size to_own (const Size& s) { return {s.width, s.height}; };
|
||||
|
||||
inline cv::gapi::own::Rect to_own (const Rect& r) { return {r.x, r.y, r.width, r.height}; };
|
||||
@@ -53,9 +49,6 @@ namespace own
|
||||
: cv::Mat{m.dims, m.type(), m.data};
|
||||
}
|
||||
cv::Mat to_ocv(Mat&&) = delete;
|
||||
|
||||
inline cv::Scalar to_ocv(const Scalar& s) { return {s[0], s[1], s[2], s[3]}; };
|
||||
|
||||
inline cv::Size to_ocv (const Size& s) { return cv::Size(s.width, s.height); };
|
||||
|
||||
inline cv::Rect to_ocv (const Rect& r) { return cv::Rect(r.x, r.y, r.width, r.height); };
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define OPENCV_GAPI_CV_DEFS_HPP
|
||||
|
||||
#if defined(GAPI_STANDALONE)
|
||||
#include <opencv2/gapi/own/scalar.hpp> // cv::gapi::own::Scalar
|
||||
|
||||
// Simulate OpenCV definitions taken from various
|
||||
// OpenCV interface headers if G-API is built in a
|
||||
@@ -137,6 +138,8 @@ enum InterpolationFlags{
|
||||
INTER_LINEAR_EXACT = 5,
|
||||
INTER_MAX = 7,
|
||||
};
|
||||
// replacement of cv's structures:
|
||||
using Scalar = gapi::own::Scalar;
|
||||
} // namespace cv
|
||||
|
||||
static inline int cvFloor( double value )
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <opencv2/gapi/opencv_includes.hpp>
|
||||
#include <opencv2/gapi/util/variant.hpp>
|
||||
#include <opencv2/gapi/own/exports.hpp>
|
||||
#include <opencv2/gapi/own/scalar.hpp>
|
||||
|
||||
|
||||
/** \defgroup gapi_draw G-API Drawing and composition functionality
|
||||
|
||||
Reference in New Issue
Block a user