G-API: Integrated cv::MediaFrame as I/O type + CPU backend
This commit is contained in:
@@ -14,47 +14,21 @@
|
||||
namespace opencv_test {
|
||||
|
||||
G_API_OP(GBlurFrame, <GMat(GFrame)>, "test.blur_frame") {
|
||||
static GMatDesc outMeta(GMatDesc in) {
|
||||
return in;
|
||||
static GMatDesc outMeta(GFrameDesc in) {
|
||||
return cv::GMatDesc(CV_8U,3,in.size);
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(OCVBlurFrame, GBlurFrame) {
|
||||
static void run(const cv::Mat& in, cv::Mat& out) {
|
||||
cv::blur(in, out, cv::Size{3,3});
|
||||
static void run(const cv::MediaFrame &in, cv::Mat& out) {
|
||||
GAPI_Assert(in.desc().fmt == cv::MediaFormat::BGR);
|
||||
cv::MediaFrame::View view = in.access(cv::MediaFrame::Access::R);
|
||||
cv::blur(cv::Mat(in.desc().size, CV_8UC3, view.ptr[0], view.stride[0]),
|
||||
out,
|
||||
cv::Size{3,3});
|
||||
}
|
||||
};
|
||||
|
||||
struct GFrameTest : public ::testing::Test {
|
||||
cv::Size sz{32,32};
|
||||
cv::Mat in_mat;
|
||||
cv::Mat out_mat;
|
||||
cv::Mat out_mat_ocv;
|
||||
|
||||
GFrameTest()
|
||||
: in_mat(cv::Mat(sz, CV_8UC1))
|
||||
, out_mat(cv::Mat::zeros(sz, CV_8UC1))
|
||||
, out_mat_ocv(cv::Mat::zeros(sz, CV_8UC1)) {
|
||||
cv::randn(in_mat, cv::Scalar::all(127.0f), cv::Scalar::all(40.f));
|
||||
cv::blur(in_mat, out_mat_ocv, cv::Size{3,3});
|
||||
}
|
||||
|
||||
void check() {
|
||||
EXPECT_EQ(0, cvtest::norm(out_mat, out_mat_ocv, NORM_INF));
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(GFrameTest, Input) {
|
||||
cv::GFrame in;
|
||||
auto out = GBlurFrame::on(in);
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
|
||||
auto pkg = cv::gapi::kernels<OCVBlurFrame>();
|
||||
c.apply(cv::gin(in_mat), cv::gout(out_mat), cv::compile_args(pkg));
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// cv::MediaFrame tests
|
||||
namespace {
|
||||
@@ -108,6 +82,7 @@ struct MediaFrame_BGR: public MediaFrame_Test {
|
||||
M bgr;
|
||||
MediaFrame_BGR()
|
||||
: bgr(M::eye(240, 320, CV_8UC3)) {
|
||||
cv::randn(bgr, cv::Scalar::all(127.0f), cv::Scalar::all(40.f));
|
||||
frame = MF::Create<TestMediaBGR>(bgr);
|
||||
}
|
||||
};
|
||||
@@ -128,6 +103,23 @@ TEST_F(MediaFrame_BGR, Access) {
|
||||
EXPECT_EQ(bgr.step, view2.stride[0]);
|
||||
}
|
||||
|
||||
TEST_F(MediaFrame_BGR, Input) {
|
||||
// Run the OpenCV code
|
||||
cv::Mat out_mat_ocv, out_mat_gapi;
|
||||
cv::blur(bgr, out_mat_ocv, cv::Size{3,3});
|
||||
|
||||
// Run the G-API code
|
||||
cv::GFrame in;
|
||||
cv::GMat out = GBlurFrame::on(in);
|
||||
cv::GComputation(cv::GIn(in), cv::GOut(out))
|
||||
.apply(cv::gin(frame),
|
||||
cv::gout(out_mat_gapi),
|
||||
cv::compile_args(cv::gapi::kernels<OCVBlurFrame>()));
|
||||
|
||||
// Compare
|
||||
EXPECT_EQ(0, cvtest::norm(out_mat_ocv, out_mat_gapi, NORM_INF));
|
||||
}
|
||||
|
||||
struct MediaFrame_NV12: public MediaFrame_Test {
|
||||
cv::Size sz;
|
||||
cv::Mat buf, y, uv;
|
||||
|
||||
Reference in New Issue
Block a user