|
|
|
|
|
|
|
|
|
|
|
|
|
|
| #ifndef OPENCV_GAPI_GCOMMON_HPP
|
| #define OPENCV_GAPI_GCOMMON_HPP
|
|
|
| #include <functional>
|
| #include <vector>
|
| #include <type_traits>
|
|
|
| #include <opencv2/gapi/opencv_includes.hpp>
|
|
|
| #include <opencv2/gapi/util/any.hpp>
|
| #include <opencv2/gapi/util/optional.hpp>
|
| #include <opencv2/gapi/own/exports.hpp>
|
| #include <opencv2/gapi/own/assert.hpp>
|
| #include <opencv2/gapi/render/render_types.hpp>
|
| #include <opencv2/gapi/s11n/base.hpp>
|
|
|
| namespace cv {
|
|
|
| class GMat;
|
|
|
| namespace detail
|
| {
|
|
|
|
|
| template<typename T> struct CompileArgTag;
|
|
|
|
|
| struct KernelTag
|
| {};
|
| struct TransformTag
|
| {};
|
|
|
|
|
|
|
| enum class OpaqueKind: int
|
| {
|
| CV_UNKNOWN,
|
| CV_BOOL,
|
| CV_INT,
|
| CV_INT64,
|
| CV_DOUBLE,
|
| CV_FLOAT,
|
| CV_UINT64,
|
| CV_STRING,
|
| CV_POINT,
|
| CV_POINT2F,
|
| CV_POINT3F,
|
| CV_SIZE,
|
| CV_RECT,
|
| CV_SCALAR,
|
| CV_MAT,
|
| CV_DRAW_PRIM,
|
| };
|
|
|
|
|
| template<typename T> struct GOpaqueTraits;
|
| template<typename T> struct GOpaqueTraits { static constexpr const OpaqueKind kind = OpaqueKind::CV_UNKNOWN; };
|
| template<> struct GOpaqueTraits<int> { static constexpr const OpaqueKind kind = OpaqueKind::CV_INT; };
|
| template<> struct GOpaqueTraits<int64_t> { static constexpr const OpaqueKind kind = OpaqueKind::CV_INT64; };
|
| template<> struct GOpaqueTraits<double> { static constexpr const OpaqueKind kind = OpaqueKind::CV_DOUBLE; };
|
| template<> struct GOpaqueTraits<float> { static constexpr const OpaqueKind kind = OpaqueKind::CV_FLOAT; };
|
| template<> struct GOpaqueTraits<uint64_t> { static constexpr const OpaqueKind kind = OpaqueKind::CV_UINT64; };
|
| template<> struct GOpaqueTraits<bool> { static constexpr const OpaqueKind kind = OpaqueKind::CV_BOOL; };
|
| template<> struct GOpaqueTraits<std::string> { static constexpr const OpaqueKind kind = OpaqueKind::CV_STRING; };
|
| template<> struct GOpaqueTraits<cv::Size> { static constexpr const OpaqueKind kind = OpaqueKind::CV_SIZE; };
|
| template<> struct GOpaqueTraits<cv::Scalar> { static constexpr const OpaqueKind kind = OpaqueKind::CV_SCALAR; };
|
| template<> struct GOpaqueTraits<cv::Point> { static constexpr const OpaqueKind kind = OpaqueKind::CV_POINT; };
|
| template<> struct GOpaqueTraits<cv::Point2f> { static constexpr const OpaqueKind kind = OpaqueKind::CV_POINT2F; };
|
| template<> struct GOpaqueTraits<cv::Point3f> { static constexpr const OpaqueKind kind = OpaqueKind::CV_POINT3F; };
|
| template<> struct GOpaqueTraits<cv::Mat> { static constexpr const OpaqueKind kind = OpaqueKind::CV_MAT; };
|
| template<> struct GOpaqueTraits<cv::Rect> { static constexpr const OpaqueKind kind = OpaqueKind::CV_RECT; };
|
| template<> struct GOpaqueTraits<cv::GMat> { static constexpr const OpaqueKind kind = OpaqueKind::CV_MAT; };
|
| template<> struct GOpaqueTraits<cv::gapi::wip::draw::Prim>
|
| { static constexpr const OpaqueKind kind = OpaqueKind::CV_DRAW_PRIM; };
|
| using GOpaqueTraitsArrayTypes = std::tuple<int, double, float, uint64_t, bool, std::string, cv::Size, cv::Scalar, cv::Point, cv::Point2f,
|
| cv::Point3f, cv::Mat, cv::Rect, cv::gapi::wip::draw::Prim>;
|
|
|
| using GOpaqueTraitsOpaqueTypes = std::tuple<int, double, float, uint64_t, bool, std::string, cv::Size, cv::Point, cv::Point2f, cv::Point3f,
|
| cv::Rect, cv::gapi::wip::draw::Prim>;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| enum class GShape: int
|
| {
|
| GMAT,
|
| GSCALAR,
|
| GARRAY,
|
| GOPAQUE,
|
| GFRAME,
|
| };
|
|
|
| namespace gapi {
|
| namespace s11n {
|
| namespace detail {
|
| template<typename T> struct wrap_serialize;
|
| }
|
| }
|
| }
|
|
|
|
|
| struct GCompileArg;
|
|
|
| namespace detail {
|
| template<typename T>
|
| using is_compile_arg = std::is_same<GCompileArg, typename std::decay<T>::type>;
|
| }
|
|
|
|
|
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| struct GCompileArg
|
| {
|
| public:
|
|
|
| GCompileArg() = default;
|
|
|
| std::string tag;
|
|
|
|
|
| template<typename T, typename std::enable_if<!detail::is_compile_arg<T>::value, int>::type = 0>
|
| explicit GCompileArg(T &&t)
|
| : tag(detail::CompileArgTag<typename std::decay<T>::type>::tag())
|
| , serializeF(cv::gapi::s11n::detail::has_S11N_spec<T>::value ?
|
| &cv::gapi::s11n::detail::wrap_serialize<T>::serialize :
|
| nullptr)
|
| , arg(t)
|
| {
|
| }
|
|
|
| template<typename T> T& get()
|
| {
|
| return util::any_cast<T>(arg);
|
| }
|
|
|
| template<typename T> const T& get() const
|
| {
|
| return util::any_cast<T>(arg);
|
| }
|
|
|
| void serialize(cv::gapi::s11n::IOStream& os) const
|
| {
|
| if (serializeF)
|
| {
|
| serializeF(os, *this);
|
| }
|
| }
|
|
|
| private:
|
| std::function<void(cv::gapi::s11n::IOStream&, const GCompileArg&)> serializeF;
|
| util::any arg;
|
| };
|
|
|
| using GCompileArgs = std::vector<GCompileArg>;
|
|
|
| inline cv::GCompileArgs& operator += ( cv::GCompileArgs &lhs,
|
| const cv::GCompileArgs &rhs)
|
| {
|
| lhs.reserve(lhs.size() + rhs.size());
|
| lhs.insert(lhs.end(), rhs.begin(), rhs.end());
|
| return lhs;
|
| }
|
|
|
| |
| |
| |
|
|
| template<typename... Ts> GCompileArgs compile_args(Ts&&... args)
|
| {
|
| return GCompileArgs{ GCompileArg(args)... };
|
| }
|
|
|
| namespace gapi
|
| {
|
| |
| |
| |
|
|
| template<typename T>
|
| inline cv::util::optional<T> getCompileArg(const cv::GCompileArgs &args)
|
| {
|
| for (auto &compile_arg : args)
|
| {
|
| if (compile_arg.tag == cv::detail::CompileArgTag<T>::tag())
|
| {
|
| return cv::util::optional<T>(compile_arg.get<T>());
|
| }
|
| }
|
| return cv::util::optional<T>();
|
| }
|
|
|
| namespace s11n {
|
| namespace detail {
|
| template<typename T> struct wrap_serialize
|
| {
|
| static void serialize(IOStream& os, const GCompileArg& arg)
|
| {
|
| using DT = typename std::decay<T>::type;
|
| S11N<DT>::serialize(os, arg.get<DT>());
|
| }
|
| };
|
| }
|
| }
|
| }
|
|
|
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| struct graph_dump_path
|
| {
|
| std::string m_dump_path;
|
| };
|
|
|
| |
| |
| |
| |
| |
|
|
| struct GAPI_EXPORTS use_threaded_executor
|
| {
|
| use_threaded_executor();
|
| explicit use_threaded_executor(const uint32_t nthreads);
|
|
|
| uint32_t num_threads;
|
| };
|
|
|
| namespace detail
|
| {
|
| template<> struct CompileArgTag<cv::graph_dump_path>
|
| {
|
| static const char* tag() { return "gapi.graph_dump_path"; }
|
| };
|
|
|
| template<> struct CompileArgTag<cv::use_threaded_executor>
|
| {
|
| static const char* tag() { return "gapi.threaded_executor"; }
|
| };
|
| }
|
|
|
| }
|
|
|
|
|
| namespace std
|
| {
|
| template<> struct hash<cv::GShape>
|
| {
|
| size_t operator() (cv::GShape sh) const
|
| {
|
| return std::hash<int>()(static_cast<int>(sh));
|
| }
|
| };
|
| }
|
|
|
|
|
| #endif
|
|
|