diff --git a/modules/gapi/include/opencv2/gapi/media.hpp b/modules/gapi/include/opencv2/gapi/media.hpp index 3d7f5a5b65..61a7098b55 100644 --- a/modules/gapi/include/opencv2/gapi/media.hpp +++ b/modules/gapi/include/opencv2/gapi/media.hpp @@ -13,6 +13,7 @@ #include // forward<>() #include +#include 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 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 diff --git a/modules/gapi/src/api/media.cpp b/modules/gapi/src/api/media.cpp index 3c171b215f..884fc9e83d 100644 --- a/modules/gapi/src/api/media.cpp +++ b/modules/gapi/src/api/media.cpp @@ -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() { } diff --git a/modules/gapi/test/gapi_frame_tests.cpp b/modules/gapi/test/gapi_frame_tests.cpp index ab271087dc..5911ef9d9a 100644 --- a/modules/gapi/test/gapi_frame_tests.cpp +++ b/modules/gapi/test/gapi_frame_tests.cpp @@ -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(bgr); + + EXPECT_NO_THROW(frame.blobParams()); +} + } // namespace opencv_test diff --git a/modules/gapi/test/infer/gapi_infer_ie_test.cpp b/modules/gapi/test/infer/gapi_infer_ie_test.cpp index 4ea33f7713..e33f165ae1 100644 --- a/modules/gapi/test/infer/gapi_infer_ie_test.cpp +++ b/modules/gapi/test/infer/gapi_infer_ie_test.cpp @@ -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({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(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(frame.blobParams()); + + EXPECT_EQ(expected, actual); +} + } // namespace opencv_test #endif // HAVE_INF_ENGINE