Merge pull request #20151 from smirnov-alexey:as/extend_media_frame

G-API: Extend MediaFrame to be able to extract additional info besides access

* Extend MediaFrame to be able to extract additional info besides access

* Add default implementation for blobParams()

* Add comment on the default blobParams()
pull/20244/head
Alexey Smirnov 4 years ago committed by GitHub
parent 1b5fe91624
commit d9ed9a9a83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      modules/gapi/include/opencv2/gapi/media.hpp
  2. 11
      modules/gapi/src/api/media.cpp
  3. 7
      modules/gapi/test/gapi_frame_tests.cpp
  4. 24
      modules/gapi/test/infer/gapi_infer_ie_test.cpp

@ -13,6 +13,7 @@
#include <utility> // forward<>()
#include <opencv2/gapi/gframe.hpp>
#include <opencv2/gapi/util/any.hpp>
namespace cv {
@ -30,6 +31,10 @@ public:
View access(Access) const;
cv::GFrameDesc desc() const;
// FIXME: design a better solution
// Should be used only if the actual adapter provides implementation
cv::util::any blobParams() const;
// Cast underlying MediaFrame adapter to the particular adapter type,
// return nullptr if underlying type is different
template<typename T> T* get() const
@ -78,6 +83,9 @@ public:
virtual ~IAdapter() = 0;
virtual cv::GFrameDesc meta() const = 0;
virtual MediaFrame::View access(MediaFrame::Access) = 0;
// FIXME: design a better solution
// The default implementation does nothing
virtual cv::util::any blobParams() const;
};
} //namespace cv

@ -26,6 +26,11 @@ cv::MediaFrame::View cv::MediaFrame::access(Access code) const {
return m->adapter->access(code);
}
cv::util::any cv::MediaFrame::blobParams() const
{
return m->adapter->blobParams();
}
cv::MediaFrame::IAdapter* cv::MediaFrame::getAdapter() const {
return m->adapter.get();
}
@ -42,5 +47,11 @@ cv::MediaFrame::View::~View() {
}
}
cv::util::any cv::MediaFrame::IAdapter::blobParams() const
{
// Does nothing by default
return {};
}
cv::MediaFrame::IAdapter::~IAdapter() {
}

@ -174,4 +174,11 @@ TEST(MediaFrame, Callback) {
EXPECT_EQ(3, counter);
}
TEST(MediaFrame, blobParams) {
cv::Mat bgr = cv::Mat::eye(240, 320, CV_8UC3);
cv::MediaFrame frame = cv::MediaFrame::Create<TestMediaBGR>(bgr);
EXPECT_NO_THROW(frame.blobParams());
}
} // namespace opencv_test

@ -56,6 +56,15 @@ public:
cv::MediaFrame::View::Strides ss = { m_mat.step, 0u, 0u, 0u };
return cv::MediaFrame::View(std::move(pp), std::move(ss), Cb{m_cb});
}
cv::util::any blobParams() const override {
return std::make_pair<InferenceEngine::TensorDesc,
InferenceEngine::ParamMap>({IE::Precision::U8,
{1, 3, 300, 300},
IE::Layout::NCHW},
{{"HELLO", 42},
{"COLOR_FORMAT",
InferenceEngine::ColorFormat::NV12}});
}
};
class TestMediaNV12 final: public cv::MediaFrame::IAdapter {
@ -2028,6 +2037,21 @@ TEST_F(ROIList, CallInferMultipleTimes)
validate();
}
TEST(IEFrameAdapter, blobParams)
{
cv::Mat bgr = cv::Mat::eye(240, 320, CV_8UC3);
cv::MediaFrame frame = cv::MediaFrame::Create<TestMediaBGR>(bgr);
auto expected = std::make_pair(IE::TensorDesc{IE::Precision::U8, {1, 3, 300, 300},
IE::Layout::NCHW},
IE::ParamMap{{"HELLO", 42}, {"COLOR_FORMAT",
IE::ColorFormat::NV12}});
auto actual = cv::util::any_cast<decltype(expected)>(frame.blobParams());
EXPECT_EQ(expected, actual);
}
} // namespace opencv_test
#endif // HAVE_INF_ENGINE

Loading…
Cancel
Save