// This file is part of OpenCV project. // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html. // // Copyright (C) 2019 Intel Corporation #ifndef OPENCV_GAPI_GTRANSFORM_HPP #define OPENCV_GAPI_GTRANSFORM_HPP #include #include #include #include #include #include #include #include #include namespace cv { struct GAPI_EXPORTS GTransform { // FIXME: consider another simplified // class instead of GComputation using F = std::function; std::string description; F pattern; F substitute; GTransform(const std::string& d, const F &p, const F &s) : description(d), pattern(p), substitute(s){}; }; namespace detail { template struct TransHelper; template struct TransHelper, Out> { template static GComputation invoke(Callable f, Seq, Seq) { const std::tuple ins; const auto r = tuple_wrap_helper::get(f(std::get(ins)...)); return GComputation(cv::GIn(std::get(ins)...), cv::GOut(std::get(r)...)); } static GComputation get_pattern() { return invoke(K::pattern, typename MkSeq::type(), typename MkSeq::type>::value>::type()); } static GComputation get_substitute() { return invoke(K::substitute, typename MkSeq::type(), typename MkSeq::type>::value>::type()); } }; } // namespace detail template class GTransformImpl; template class GTransformImpl> : public cv::detail::TransHelper, R>, public cv::detail::TransformTag { public: // FIXME: currently there is no check that transformations' signatures are unique // and won't be any intersection in graph compilation stage using API = K; static GTransform transformation() { return GTransform(K::descr(), &K::get_pattern, &K::get_substitute); } }; } // namespace cv #define G_DESCR_HELPER_CLASS(Class) Class##DescrHelper #define G_DESCR_HELPER_BODY(Class, Descr) \ namespace detail \ { \ struct G_DESCR_HELPER_CLASS(Class) \ { \ static constexpr const char *descr() { return Descr; }; \ }; \ } #define GAPI_TRANSFORM(Class, API, Descr) \ G_DESCR_HELPER_BODY(Class, Descr) \ struct Class final : public cv::GTransformImpl, \ public detail::G_DESCR_HELPER_CLASS(Class) #endif // OPENCV_GAPI_GTRANSFORM_HPP