Merge pull request #15763 from akhakim:dynamic_set_kernel_window_size
This commit is contained in:
@@ -68,19 +68,21 @@ public:
|
||||
// This function is a generic "getBorder" callback (extracts border-related data from kernel's input parameters)
|
||||
using B = std::function<gapi::fluid::BorderOpt(const GMetaArgs&, const GArgs&)>;
|
||||
|
||||
// This function is a generic "getWindow" callback (extracts window-related data from kernel's input parameters)
|
||||
using GW = std::function<int(const GMetaArgs&, const GArgs&)>;
|
||||
|
||||
// FIXME: move implementations out of header file
|
||||
GFluidKernel() {}
|
||||
GFluidKernel(int w, Kind k, int l, bool scratch, const F& f, const IS &is, const RS &rs, const B& b)
|
||||
: m_window(w)
|
||||
, m_kind(k)
|
||||
GFluidKernel(Kind k, int l, bool scratch, const F& f, const IS &is, const RS &rs, const B& b, const GW& win)
|
||||
: m_kind(k)
|
||||
, m_lpi(l)
|
||||
, m_scratch(scratch)
|
||||
, m_f(f)
|
||||
, m_is(is)
|
||||
, m_rs(rs)
|
||||
, m_b(b) {}
|
||||
, m_b(b)
|
||||
, m_gw(win) {}
|
||||
|
||||
int m_window = -1;
|
||||
Kind m_kind;
|
||||
const int m_lpi = -1;
|
||||
const bool m_scratch = false;
|
||||
@@ -89,6 +91,7 @@ public:
|
||||
const IS m_is;
|
||||
const RS m_rs;
|
||||
const B m_b;
|
||||
const GW m_gw;
|
||||
};
|
||||
|
||||
// FIXME!!!
|
||||
@@ -255,6 +258,67 @@ struct get_border_helper<false, Impl, Ins...>
|
||||
}
|
||||
};
|
||||
|
||||
template<bool CallCustomGetWindow, typename, typename... Ins>
|
||||
struct get_window_helper;
|
||||
|
||||
template<typename Impl, typename... Ins>
|
||||
struct get_window_helper<true, Impl, Ins...>
|
||||
{
|
||||
template<int... IIs>
|
||||
static int get_window_impl(const GMetaArgs &metas,
|
||||
const cv::GArgs &in_args,
|
||||
cv::detail::Seq<IIs...>)
|
||||
{
|
||||
return Impl::getWindow(cv::detail::get_in_meta<Ins>(metas, in_args, IIs)...);
|
||||
}
|
||||
|
||||
static int help(const GMetaArgs &metas, const cv::GArgs &in_args)
|
||||
{
|
||||
return get_window_impl(metas, in_args, typename detail::MkSeq<sizeof...(Ins)>::type());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Impl, typename... Ins>
|
||||
struct get_window_helper<false, Impl, Ins...>
|
||||
{
|
||||
static int help(const cv::GMetaArgs &,
|
||||
const cv::GArgs &)
|
||||
{
|
||||
return Impl::Window;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename C, typename T>
|
||||
struct has_Window
|
||||
{
|
||||
private:
|
||||
template<class U>
|
||||
static constexpr auto Check(U*) -> typename std::is_same<decltype(U::Window), T>::type;
|
||||
|
||||
template<typename>
|
||||
static constexpr std::false_type Check(...);
|
||||
|
||||
typedef decltype(Check<C>(0)) Result;
|
||||
|
||||
public:
|
||||
static constexpr bool value = Result::value;
|
||||
};
|
||||
|
||||
template<bool hasWindow, typename Impl>
|
||||
struct callCustomGetBorder;
|
||||
|
||||
template<typename Impl>
|
||||
struct callCustomGetBorder<true, Impl>
|
||||
{
|
||||
static constexpr bool value = (Impl::Window != 1);
|
||||
};
|
||||
|
||||
template<typename Impl>
|
||||
struct callCustomGetBorder<false, Impl>
|
||||
{
|
||||
static constexpr bool value = true;
|
||||
};
|
||||
|
||||
template<typename, typename, typename, bool UseScratch>
|
||||
struct FluidCallHelper;
|
||||
|
||||
@@ -299,10 +363,17 @@ struct FluidCallHelper<Impl, std::tuple<Ins...>, std::tuple<Outs...>, UseScratch
|
||||
|
||||
static gapi::fluid::BorderOpt getBorder(const GMetaArgs &metas, const cv::GArgs &in_args)
|
||||
{
|
||||
constexpr bool hasWindow = has_Window<Impl, const int>::value;
|
||||
|
||||
// User must provide "init" callback if Window != 1
|
||||
// TODO: move to constexpr if when we enable C++17
|
||||
constexpr bool callCustomGetBorder = (Impl::Window != 1);
|
||||
return get_border_helper<callCustomGetBorder, Impl, Ins...>::help(metas, in_args);
|
||||
return get_border_helper<callCustomGetBorder<hasWindow, Impl>::value, Impl, Ins...>::help(metas, in_args);
|
||||
}
|
||||
|
||||
static int getWindow(const GMetaArgs &metas, const cv::GArgs &in_args)
|
||||
{
|
||||
constexpr bool callCustomGetWindow = !(has_Window<Impl, const int>::value);
|
||||
return get_window_helper<callCustomGetWindow, Impl, Ins...>::help(metas, in_args);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
@@ -322,9 +393,9 @@ public:
|
||||
{
|
||||
// FIXME: call() and getOutMeta() needs to be renamed so it is clear these
|
||||
// functions are internal wrappers, not user API
|
||||
return GFluidKernel(Impl::Window, Impl::Kind, Impl::LPI,
|
||||
return GFluidKernel(Impl::Kind, Impl::LPI,
|
||||
UseScratch,
|
||||
&P::call, &P::init_scratch, &P::reset_scratch, &P::getBorder);
|
||||
&P::call, &P::init_scratch, &P::reset_scratch, &P::getBorder, &P::getWindow);
|
||||
}
|
||||
|
||||
static cv::gapi::GBackend backend() { return cv::gapi::fluid::backend(); }
|
||||
|
||||
Reference in New Issue
Block a user