提交 0f4b27c3 编写于 作者: A Anastasiya Pronina

Upstream fixes from release

上级 fbb38cc2
...@@ -30,9 +30,21 @@ public: ...@@ -30,9 +30,21 @@ public:
View access(Access) const; View access(Access) const;
cv::GFrameDesc desc() const; cv::GFrameDesc desc() const;
// Cast underlying MediaFrame adapter to the particular adapter type,
// return nullptr if underlying type is different
template<typename T> T* get() const
{
static_assert(std::is_base_of<IAdapter, T>::value,
"T is not derived from cv::MediaFrame::IAdapter!");
auto* adapter = getAdapter();
GAPI_Assert(adapter != nullptr);
return dynamic_cast<T*>(adapter);
}
private: private:
struct Priv; struct Priv;
std::shared_ptr<Priv> m; std::shared_ptr<Priv> m;
IAdapter* getAdapter() const;
}; };
template<class T, class... Args> template<class T, class... Args>
......
...@@ -26,6 +26,10 @@ cv::MediaFrame::View cv::MediaFrame::access(Access code) const { ...@@ -26,6 +26,10 @@ cv::MediaFrame::View cv::MediaFrame::access(Access code) const {
return m->adapter->access(code); return m->adapter->access(code);
} }
cv::MediaFrame::IAdapter* cv::MediaFrame::getAdapter() const {
return m->adapter.get();
}
cv::MediaFrame::View::View(Ptrs&& ptrs, Strides&& strs, Callback &&cb) cv::MediaFrame::View::View(Ptrs&& ptrs, Strides&& strs, Callback &&cb)
: ptr (std::move(ptrs)) : ptr (std::move(ptrs))
, stride(std::move(strs)) , stride(std::move(strs))
......
...@@ -126,25 +126,20 @@ inline IE::TensorDesc toIE(const cv::Mat &mat, cv::gapi::ie::TraitAs hint) { ...@@ -126,25 +126,20 @@ inline IE::TensorDesc toIE(const cv::Mat &mat, cv::gapi::ie::TraitAs hint) {
if (sz.dims() == 2 && hint == cv::gapi::ie::TraitAs::IMAGE) if (sz.dims() == 2 && hint == cv::gapi::ie::TraitAs::IMAGE)
{ {
// NB: This logic is mainly taken from IE samples // NB: This logic is mainly taken from IE samples
const size_t pixsz = CV_ELEM_SIZE1(mat.type());
const size_t channels = mat.channels(); const size_t channels = mat.channels();
const size_t height = mat.size().height; const size_t height = mat.size().height;
const size_t width = mat.size().width; const size_t width = mat.size().width;
const size_t strideH = mat.step.buf[0]; const size_t strideH = mat.step[0];
const size_t strideW = mat.step.buf[1];
const bool is_dense = IE::BlockingDesc bdesc({1, height, width, channels} /* dims */,
strideW == pixsz * channels && {0, 2, 3, 1} /* order for NHWC */,
strideH == strideW * width; 0 /* offset */,
{0, 0, 0, 0} /* offsets for dims */,
if (!is_dense) {strideH * height, strideH, channels, 1} /* strides for dims */);
cv::util::throw_error(std::logic_error("Doesn't support conversion"
" from non-dense cv::Mat"));
return IE::TensorDesc(toIE(mat.depth()), return IE::TensorDesc(toIE(mat.depth()),
IE::SizeVector{1, channels, height, width}, IE::SizeVector{1, channels, height, width}, bdesc);
IE::Layout::NHWC);
} }
return IE::TensorDesc(toIE(mat.depth()), toIE(sz), toIELayout(sz.dims())); return IE::TensorDesc(toIE(mat.depth()), toIE(sz), toIELayout(sz.dims()));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册