mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #18584 from smirnov-alexey:as/rmat_s11n
[G-API]: Introduce RMat serialization API * Introduce RMat serialization API * Fix RunArgs deserialization * Address review comments * Export operators for GRunArg serialization * Fix warning and add handling for RMat in bind() * Update CMakeLists.txt * G-API: RMat S11N -- probably fix the Windows warning
This commit is contained in:
@@ -79,6 +79,9 @@ cv::GRunArgsP cv::gapi::bind(cv::GRunArgs &results)
|
||||
case T::index_of<cv::detail::OpaqueRef>() :
|
||||
outputs.emplace_back(cv::util::get<cv::detail::OpaqueRef>(res_obj));
|
||||
break;
|
||||
case cv::GRunArg::index_of<cv::RMat>() :
|
||||
outputs.emplace_back((cv::RMat*)(&(cv::util::get<cv::RMat>(res_obj))));
|
||||
break;
|
||||
default:
|
||||
GAPI_Assert(false && "This value type is not supported!"); // ...maybe because of STANDALONE mode.
|
||||
break;
|
||||
@@ -112,6 +115,9 @@ cv::GRunArg cv::gapi::bind(cv::GRunArgP &out)
|
||||
case T::index_of<cv::Scalar*>() :
|
||||
return cv::GRunArg(*cv::util::get<cv::Scalar*>(out));
|
||||
|
||||
case T::index_of<cv::RMat*>() :
|
||||
return cv::GRunArg(*cv::util::get<cv::RMat*>(out));
|
||||
|
||||
default:
|
||||
// ...maybe our types were extended
|
||||
GAPI_Assert(false && "This value type is UNKNOWN!");
|
||||
|
||||
@@ -165,12 +165,12 @@ IOStream& operator<< (IOStream& os, const cv::Scalar &s) {
|
||||
IIStream& operator>> (IIStream& is, cv::Scalar& s) {
|
||||
return is >> s.val[0] >> s.val[1] >> s.val[2] >> s.val[3];
|
||||
}
|
||||
IOStream& operator<< (IOStream& os, const cv::RMat&) {
|
||||
util::throw_error(std::logic_error("Serialization of RMat is not supported"));
|
||||
IOStream& operator<< (IOStream& os, const cv::RMat& mat) {
|
||||
mat.serialize(os);
|
||||
return os;
|
||||
}
|
||||
IIStream& operator>> (IIStream& is, cv::RMat&) {
|
||||
util::throw_error(std::logic_error("Serialization of RMat is not supported"));
|
||||
util::throw_error(std::logic_error("operator>> for RMat should never be called"));
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,26 +88,6 @@ GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GArrayDesc &);
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::GFrameDesc &);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GFrameDesc &);
|
||||
|
||||
#if !defined(GAPI_STANDALONE)
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::UMat &);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::UMat &);
|
||||
#endif // !defined(GAPI_STANDALONE)
|
||||
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::RMat &r);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::RMat &r);
|
||||
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::IStreamSource::Ptr &);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::IStreamSource::Ptr &);
|
||||
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::detail::VectorRef &);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::detail::VectorRef &);
|
||||
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::detail::OpaqueRef &);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::detail::OpaqueRef &);
|
||||
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::MediaFrame &);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::MediaFrame &);
|
||||
|
||||
GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gimpl::RcDesc &rc);
|
||||
GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::RcDesc &rc);
|
||||
|
||||
@@ -178,46 +158,6 @@ GAPI_EXPORTS void serialize( IOStream& os
|
||||
GAPI_EXPORTS GSerialized deserialize(IIStream& is);
|
||||
GAPI_EXPORTS void reconstruct(const GSerialized &s, ade::Graph &g);
|
||||
|
||||
// Generic: variant serialization //////////////////////////////////////////////
|
||||
namespace detail { // FIXME: breaks old code
|
||||
template<typename V>
|
||||
IOStream& put_v(IOStream&, const V&, std::size_t) {
|
||||
GAPI_Assert(false && "variant>>: requested index is invalid");
|
||||
};
|
||||
template<typename V, typename X, typename... Xs>
|
||||
IOStream& put_v(IOStream& os, const V& v, std::size_t x) {
|
||||
return (x == 0u)
|
||||
? os << cv::util::get<X>(v)
|
||||
: put_v<V, Xs...>(os, v, x-1);
|
||||
}
|
||||
template<typename V>
|
||||
IIStream& get_v(IIStream&, V&, std::size_t, std::size_t) {
|
||||
GAPI_Assert(false && "variant<<: requested index is invalid");
|
||||
}
|
||||
template<typename V, typename X, typename... Xs>
|
||||
IIStream& get_v(IIStream& is, V& v, std::size_t i, std::size_t gi) {
|
||||
if (i == gi) {
|
||||
X x{};
|
||||
is >> x;
|
||||
v = std::move(x);
|
||||
return is;
|
||||
} else return get_v<V, Xs...>(is, v, i+1, gi);
|
||||
}
|
||||
} // namespace detail FIXME: breaks old code
|
||||
|
||||
template<typename... Ts>
|
||||
IOStream& operator<< (IOStream& os, const cv::util::variant<Ts...> &v) {
|
||||
os << (uint32_t)v.index();
|
||||
return detail::put_v<cv::util::variant<Ts...>, Ts...>(os, v, v.index());
|
||||
}
|
||||
template<typename... Ts>
|
||||
IIStream& operator>> (IIStream& is, cv::util::variant<Ts...> &v) {
|
||||
int idx = -1;
|
||||
is >> idx;
|
||||
GAPI_Assert(idx >= 0 && idx < (int)sizeof...(Ts));
|
||||
return detail::get_v<cv::util::variant<Ts...>, Ts...>(is, v, 0u, idx);
|
||||
}
|
||||
|
||||
// FIXME: Basic Stream implementaions //////////////////////////////////////////
|
||||
|
||||
// Basic in-memory stream implementations.
|
||||
|
||||
Reference in New Issue
Block a user