From: Dmitry Budnikov Date: Wed, 10 Feb 2021 19:23:54 +0000 (+0300) Subject: Merge pull request #19495 from dbudniko:gapi_media_frame_size X-Git-Tag: accepted/tizen/unified/20220125.121719~1^2~212 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1162cef9781c2123a6bae4105577571830b64d14;p=platform%2Fupstream%2Fopencv.git 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 --- diff --git a/modules/gapi/include/opencv2/gapi/core.hpp b/modules/gapi/include/opencv2/gapi/core.hpp index b1338dd..9c3b632 100644 --- a/modules/gapi/include/opencv2/gapi/core.hpp +++ b/modules/gapi/include/opencv2/gapi/core.hpp @@ -591,6 +591,12 @@ G_TYPED_KERNEL(GSizeR, (GOpaque)>, "org.opencv.streaming.siz return empty_gopaque_desc(); } }; + +G_TYPED_KERNEL(GSizeMF, (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(const GOpaque& 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(const GFrame& src); } //namespace streaming } //namespace gapi } //namespace cv diff --git a/modules/gapi/src/api/kernels_core.cpp b/modules/gapi/src/api/kernels_core.cpp index 8ff992a..3196b5d 100644 --- a/modules/gapi/src/api/kernels_core.cpp +++ b/modules/gapi/src/api/kernels_core.cpp @@ -427,5 +427,10 @@ GOpaque streaming::size(const GOpaque& r) return streaming::GSizeR::on(r); } +GOpaque streaming::size(const GFrame& src) +{ + return streaming::GSizeMF::on(src); +} + } //namespace gapi } //namespace cv diff --git a/modules/gapi/src/backends/cpu/gcpucore.cpp b/modules/gapi/src/backends/cpu/gcpucore.cpp index 5c358f5..b0bce41 100644 --- a/modules/gapi/src/backends/cpu/gcpucore.cpp +++ b/modules/gapi/src/backends/cpu/gcpucore.cpp @@ -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; } diff --git a/modules/gapi/test/common/gapi_core_tests.hpp b/modules/gapi/test/common/gapi_core_tests.hpp index 48ac448..f299d84 100644 --- a/modules/gapi/test/common/gapi_core_tests.hpp +++ b/modules/gapi/test/common/gapi_core_tests.hpp @@ -170,6 +170,7 @@ GAPI_TEST_EXT_BASE_FIXTURE(ParseYoloTest, ParserYoloTest, initNothing, FIXTURE_API(float, float, int, std::pair), 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 diff --git a/modules/gapi/test/common/gapi_core_tests_inl.hpp b/modules/gapi/test/common/gapi_core_tests_inl.hpp index b2cdf89..683a145 100644 --- a/modules/gapi/test/common/gapi_core_tests_inl.hpp +++ b/modules/gapi/test/common/gapi_core_tests_inl.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(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 diff --git a/modules/gapi/test/cpu/gapi_core_tests_cpu.cpp b/modules/gapi/test/cpu/gapi_core_tests_cpu.cpp index fedc7c1..9f8c85f 100644 --- a/modules/gapi/test/cpu/gapi_core_tests_cpu.cpp +++ b/modules/gapi/test/cpu/gapi_core_tests_cpu.cpp @@ -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))); }