Skip to content

Commit 1162cef

Browse files
author
Dmitry Budnikov
authored
Merge pull request opencv#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
1 parent c527b3c commit 1162cef

File tree

6 files changed

+71
-1
lines changed

6 files changed

+71
-1
lines changed

modules/gapi/include/opencv2/gapi/core.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,12 @@ G_TYPED_KERNEL(GSizeR, <GOpaque<Size>(GOpaque<Rect>)>, "org.opencv.streaming.siz
591591
return empty_gopaque_desc();
592592
}
593593
};
594+
595+
G_TYPED_KERNEL(GSizeMF, <GOpaque<Size>(GFrame)>, "org.opencv.streaming.sizeMF") {
596+
static GOpaqueDesc outMeta(const GFrameDesc&) {
597+
return empty_gopaque_desc();
598+
}
599+
};
594600
} // namespace streaming
595601

596602
//! @addtogroup gapi_math
@@ -1940,6 +1946,15 @@ Gets dimensions from rectangle.
19401946
@return Size (rectangle dimensions).
19411947
*/
19421948
GAPI_EXPORTS GOpaque<Size> size(const GOpaque<Rect>& r);
1949+
1950+
/** @brief Gets dimensions from MediaFrame.
1951+
1952+
@note Function textual ID is "org.opencv.streaming.sizeMF"
1953+
1954+
@param src Input frame
1955+
@return Size (frame dimensions).
1956+
*/
1957+
GAPI_EXPORTS GOpaque<Size> size(const GFrame& src);
19431958
} //namespace streaming
19441959
} //namespace gapi
19451960
} //namespace cv

modules/gapi/src/api/kernels_core.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,5 +427,10 @@ GOpaque<Size> streaming::size(const GOpaque<Rect>& r)
427427
return streaming::GSizeR::on(r);
428428
}
429429

430+
GOpaque<Size> streaming::size(const GFrame& src)
431+
{
432+
return streaming::GSizeMF::on(src);
433+
}
434+
430435
} //namespace gapi
431436
} //namespace cv

modules/gapi/src/backends/cpu/gcpucore.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,14 @@ GAPI_OCV_KERNEL(GCPUSizeR, cv::gapi::streaming::GSizeR)
692692
}
693693
};
694694

695+
GAPI_OCV_KERNEL(GCPUSizeMF, cv::gapi::streaming::GSizeMF)
696+
{
697+
static void run(const cv::MediaFrame& in, cv::Size& out)
698+
{
699+
out = in.desc().size;
700+
}
701+
};
702+
695703
cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
696704
{
697705
static auto pkg = cv::gapi::kernels
@@ -771,6 +779,7 @@ cv::gapi::GKernelPackage cv::gapi::core::cpu::kernels()
771779
, GCPUParseYolo
772780
, GCPUSize
773781
, GCPUSizeR
774-
>();
782+
, GCPUSizeMF
783+
>();
775784
return pkg;
776785
}

modules/gapi/test/common/gapi_core_tests.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ GAPI_TEST_EXT_BASE_FIXTURE(ParseYoloTest, ParserYoloTest, initNothing,
170170
FIXTURE_API(float, float, int, std::pair<bool,int>), 4, confidence_threshold, nms_threshold, num_classes, dims_config)
171171
GAPI_TEST_FIXTURE(SizeTest, initMatrixRandU, <>, 0)
172172
GAPI_TEST_FIXTURE(SizeRTest, initNothing, <>, 0)
173+
GAPI_TEST_FIXTURE(SizeMFTest, initNothing, <>, 0)
173174
} // opencv_test
174175

175176
#endif //OPENCV_GAPI_CORE_TESTS_HPP

modules/gapi/test/common/gapi_core_tests_inl.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,39 @@ TEST_P(SizeRTest, ParseTest)
19061906
EXPECT_EQ(out_sz, sz);
19071907
}
19081908

1909+
namespace {
1910+
class TestMediaBGR final : public cv::MediaFrame::IAdapter {
1911+
cv::Mat m_mat;
1912+
1913+
public:
1914+
explicit TestMediaBGR(cv::Mat m)
1915+
: m_mat(m) {
1916+
}
1917+
cv::GFrameDesc meta() const override {
1918+
return cv::GFrameDesc{ cv::MediaFormat::BGR, cv::Size(m_mat.cols, m_mat.rows) };
1919+
}
1920+
cv::MediaFrame::View access(cv::MediaFrame::Access) override {
1921+
cv::MediaFrame::View::Ptrs pp = { m_mat.ptr(), nullptr, nullptr, nullptr };
1922+
cv::MediaFrame::View::Strides ss = { m_mat.step, 0u, 0u, 0u };
1923+
return cv::MediaFrame::View(std::move(pp), std::move(ss));
1924+
}
1925+
};
1926+
};
1927+
1928+
TEST_P(SizeMFTest, ParseTest)
1929+
{
1930+
cv::Size out_sz;
1931+
cv::Mat bgr = cv::Mat::eye(sz.height, sz.width, CV_8UC3);
1932+
cv::MediaFrame frame = cv::MediaFrame::Create<TestMediaBGR>(bgr);
1933+
1934+
cv::GFrame in;
1935+
auto out = cv::gapi::streaming::size(in);
1936+
cv::GComputation c(cv::GIn(in), cv::GOut(out));
1937+
c.apply(cv::gin(frame), cv::gout(out_sz), getCompileArgs());
1938+
1939+
EXPECT_EQ(out_sz, sz);
1940+
}
1941+
19091942
} // opencv_test
19101943

19111944
#endif //OPENCV_GAPI_CORE_TESTS_INL_HPP

modules/gapi/test/cpu/gapi_core_tests_cpu.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,4 +617,11 @@ INSTANTIATE_TEST_CASE_P(SizeRTestCPU, SizeRTest,
617617
cv::Size(640, 320)),
618618
Values(-1),
619619
Values(CORE_CPU)));
620+
621+
INSTANTIATE_TEST_CASE_P(SizeMFTestCPU, SizeMFTest,
622+
Combine(Values(CV_8UC1, CV_8UC3, CV_32FC1),
623+
Values(cv::Size(32, 32),
624+
cv::Size(640, 320)),
625+
Values(-1),
626+
Values(CORE_CPU)));
620627
}

0 commit comments

Comments
 (0)