mirror of
https://github.com/opencv/opencv.git
synced 2025-06-13 04:52:53 +08:00
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()
This commit is contained in:
parent
1b5fe91624
commit
d9ed9a9a83
@ -13,6 +13,7 @@
|
|||||||
#include <utility> // forward<>()
|
#include <utility> // forward<>()
|
||||||
|
|
||||||
#include <opencv2/gapi/gframe.hpp>
|
#include <opencv2/gapi/gframe.hpp>
|
||||||
|
#include <opencv2/gapi/util/any.hpp>
|
||||||
|
|
||||||
namespace cv {
|
namespace cv {
|
||||||
|
|
||||||
@ -30,6 +31,10 @@ public:
|
|||||||
View access(Access) const;
|
View access(Access) const;
|
||||||
cv::GFrameDesc desc() 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,
|
// Cast underlying MediaFrame adapter to the particular adapter type,
|
||||||
// return nullptr if underlying type is different
|
// return nullptr if underlying type is different
|
||||||
template<typename T> T* get() const
|
template<typename T> T* get() const
|
||||||
@ -78,6 +83,9 @@ public:
|
|||||||
virtual ~IAdapter() = 0;
|
virtual ~IAdapter() = 0;
|
||||||
virtual cv::GFrameDesc meta() const = 0;
|
virtual cv::GFrameDesc meta() const = 0;
|
||||||
virtual MediaFrame::View access(MediaFrame::Access) = 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
|
} //namespace cv
|
||||||
|
@ -26,6 +26,11 @@ cv::MediaFrame::View cv::MediaFrame::access(Access code) const {
|
|||||||
return m->adapter->access(code);
|
return m->adapter->access(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cv::util::any cv::MediaFrame::blobParams() const
|
||||||
|
{
|
||||||
|
return m->adapter->blobParams();
|
||||||
|
}
|
||||||
|
|
||||||
cv::MediaFrame::IAdapter* cv::MediaFrame::getAdapter() const {
|
cv::MediaFrame::IAdapter* cv::MediaFrame::getAdapter() const {
|
||||||
return m->adapter.get();
|
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() {
|
cv::MediaFrame::IAdapter::~IAdapter() {
|
||||||
}
|
}
|
||||||
|
@ -174,4 +174,11 @@ TEST(MediaFrame, Callback) {
|
|||||||
EXPECT_EQ(3, counter);
|
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
|
} // namespace opencv_test
|
||||||
|
@ -56,6 +56,15 @@ public:
|
|||||||
cv::MediaFrame::View::Strides ss = { m_mat.step, 0u, 0u, 0u };
|
cv::MediaFrame::View::Strides ss = { m_mat.step, 0u, 0u, 0u };
|
||||||
return cv::MediaFrame::View(std::move(pp), std::move(ss), Cb{m_cb});
|
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 {
|
class TestMediaNV12 final: public cv::MediaFrame::IAdapter {
|
||||||
@ -2028,6 +2037,21 @@ TEST_F(ROIList, CallInferMultipleTimes)
|
|||||||
validate();
|
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
|
} // namespace opencv_test
|
||||||
|
|
||||||
#endif // HAVE_INF_ENGINE
|
#endif // HAVE_INF_ENGINE
|
||||||
|
Loading…
Reference in New Issue
Block a user