Merge pull request #19495 from dbudniko:gapi_media_frame_size
Add Media Frame size function and corresponding tests * add media frame size and tests * Address comments from Ruslan and Asya
This commit is contained in:
parent
c527b3cefd
commit
1162cef978
@ -591,6 +591,12 @@ G_TYPED_KERNEL(GSizeR, <GOpaque<Size>(GOpaque<Rect>)>, "org.opencv.streaming.siz
|
||||
return empty_gopaque_desc();
|
||||
}
|
||||
};
|
||||
|
||||
G_TYPED_KERNEL(GSizeMF, <GOpaque<Size>(GFrame)>, "org.opencv.streaming.sizeMF") {
|
||||
static GOpaqueDesc outMeta(const GFrameDesc&) {
|
||||
return empty_gopaque_desc();
|
||||
}
|
||||
};
|
||||
} // namespace streaming
|
||||
|
||||
//! @addtogroup gapi_math
|
||||
@ -1940,6 +1946,15 @@ Gets dimensions from rectangle.
|
||||
@return Size (rectangle dimensions).
|
||||
*/
|
||||
GAPI_EXPORTS GOpaque<Size> size(const GOpaque<Rect>& r);
|
||||
|
||||
/** @brief Gets dimensions from MediaFrame.
|
||||
|
||||
@note Function textual ID is "org.opencv.streaming.sizeMF"
|
||||
|
||||
@param src Input frame
|
||||
@return Size (frame dimensions).
|
||||
*/
|
||||
GAPI_EXPORTS GOpaque<Size> size(const GFrame& src);
|
||||
} //namespace streaming
|
||||
} //namespace gapi
|
||||
} //namespace cv
|
||||
|
||||
@ -427,5 +427,10 @@ GOpaque<Size> streaming::size(const GOpaque<Rect>& r)
|
||||
return streaming::GSizeR::on(r);
|
||||
}
|
||||
|
||||
GOpaque<Size> streaming::size(const GFrame& src)
|
||||
{
|
||||
return streaming::GSizeMF::on(src);
|
||||
}
|
||||
|
||||
} //namespace gapi
|
||||
} //namespace cv
|
||||
|
||||
@ -692,6 +692,14 @@ GAPI_OCV_KERNEL(GCPUSizeR, cv::gapi::streaming::GSizeR)
|
||||
}
|
||||
};
|
||||
|
||||
GAPI_OCV_KERNEL(GCPUSizeMF, cv::gapi::streaming::GSizeMF)
|
||||
{
|
||||
static void run(const cv::MediaFrame& in, cv::Size& out)
|
||||
{
|
||||
out = in.desc().size;
|
||||
}
|
||||
};
|
||||
|
||||
cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
|
||||
{
|
||||
static auto pkg = cv::gapi::kernels
|
||||
@ -771,6 +779,7 @@ cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
|
||||
, GCPUParseYolo
|
||||
, GCPUSize
|
||||
, GCPUSizeR
|
||||
>();
|
||||
, GCPUSizeMF
|
||||
>();
|
||||
return pkg;
|
||||
}
|
||||
|
||||
@ -170,6 +170,7 @@ GAPI_TEST_EXT_BASE_FIXTURE(ParseYoloTest, ParserYoloTest, initNothing,
|
||||
FIXTURE_API(float, float, int, std::pair<bool,int>), 4, confidence_threshold, nms_threshold, num_classes, dims_config)
|
||||
GAPI_TEST_FIXTURE(SizeTest, initMatrixRandU, <>, 0)
|
||||
GAPI_TEST_FIXTURE(SizeRTest, initNothing, <>, 0)
|
||||
GAPI_TEST_FIXTURE(SizeMFTest, initNothing, <>, 0)
|
||||
} // opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_CORE_TESTS_HPP
|
||||
|
||||
@ -1906,6 +1906,39 @@ TEST_P(SizeRTest, ParseTest)
|
||||
EXPECT_EQ(out_sz, sz);
|
||||
}
|
||||
|
||||
namespace {
|
||||
class TestMediaBGR final : public cv::MediaFrame::IAdapter {
|
||||
cv::Mat m_mat;
|
||||
|
||||
public:
|
||||
explicit TestMediaBGR(cv::Mat m)
|
||||
: m_mat(m) {
|
||||
}
|
||||
cv::GFrameDesc meta() const override {
|
||||
return cv::GFrameDesc{ cv::MediaFormat::BGR, cv::Size(m_mat.cols, m_mat.rows) };
|
||||
}
|
||||
cv::MediaFrame::View access(cv::MediaFrame::Access) override {
|
||||
cv::MediaFrame::View::Ptrs pp = { m_mat.ptr(), nullptr, nullptr, nullptr };
|
||||
cv::MediaFrame::View::Strides ss = { m_mat.step, 0u, 0u, 0u };
|
||||
return cv::MediaFrame::View(std::move(pp), std::move(ss));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TEST_P(SizeMFTest, ParseTest)
|
||||
{
|
||||
cv::Size out_sz;
|
||||
cv::Mat bgr = cv::Mat::eye(sz.height, sz.width, CV_8UC3);
|
||||
cv::MediaFrame frame = cv::MediaFrame::Create<TestMediaBGR>(bgr);
|
||||
|
||||
cv::GFrame in;
|
||||
auto out = cv::gapi::streaming::size(in);
|
||||
cv::GComputation c(cv::GIn(in), cv::GOut(out));
|
||||
c.apply(cv::gin(frame), cv::gout(out_sz), getCompileArgs());
|
||||
|
||||
EXPECT_EQ(out_sz, sz);
|
||||
}
|
||||
|
||||
} // opencv_test
|
||||
|
||||
#endif //OPENCV_GAPI_CORE_TESTS_INL_HPP
|
||||
|
||||
@ -617,4 +617,11 @@ INSTANTIATE_TEST_CASE_P(SizeRTestCPU, SizeRTest,
|
||||
cv::Size(640, 320)),
|
||||
Values(-1),
|
||||
Values(CORE_CPU)));
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(SizeMFTestCPU, SizeMFTest,
|
||||
Combine(Values(CV_8UC1, CV_8UC3, CV_32FC1),
|
||||
Values(cv::Size(32, 32),
|
||||
cv::Size(640, 320)),
|
||||
Values(-1),
|
||||
Values(CORE_CPU)));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user