Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[G-API] Fix issue of getting 1D Mat out of RMat::View #21103

Merged
merged 3 commits into from Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/gapi/src/api/rmat.cpp
Expand Up @@ -41,7 +41,7 @@ View::View(const cv::GMatDesc& desc, uchar* data, size_t step, DestroyCallback&&
: m_desc(checkDesc(desc))
, m_data(data)
, m_steps([this, step](){
GAPI_Assert(m_desc.dims.empty());
// GAPI_Assert(m_desc.dims.empty());
auto steps = defaultSteps(m_desc);
if (step != 0u) {
steps[0] = step;
Expand Down
12 changes: 10 additions & 2 deletions modules/gapi/src/backends/common/gbackend.hpp
Expand Up @@ -24,8 +24,16 @@ namespace gimpl {

inline cv::Mat asMat(RMat::View& v) {
#if !defined(GAPI_STANDALONE)
return v.dims().empty() ? cv::Mat(v.rows(), v.cols(), v.type(), v.ptr(), v.step())
: cv::Mat(v.dims(), v.type(), v.ptr(), v.steps().data());
if (v.dims().empty()) {
return cv::Mat(v.rows(), v.cols(), v.type(), v.ptr(), v.step());
} else {
cv::Mat m(v.dims(), v.type(), v.ptr(), v.steps().data());
if (v.dims().size() == 1) {
// FIXME: The only way to get 1D Mat out of RMat
m.dims = 1;
}
return m;
}
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps #else part should be fixed too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are changes for standalone to support 1D, but not here they are required (as local testing shows)

Added standalone changes in asView()

// FIXME: add a check that steps are default
return v.dims().empty() ? cv::Mat(v.rows(), v.cols(), v.type(), v.ptr(), v.step())
Expand Down
9 changes: 9 additions & 0 deletions modules/gapi/test/rmat/rmat_view_tests.cpp
Expand Up @@ -268,4 +268,13 @@ TEST_F(RMatViewCallbackTest, MagazineInteraction) {
mag.slot<View>().erase(rc);
EXPECT_EQ(1, callbackCalls);
}

TEST(RMatView, Access1DMat) {
cv::Mat m({1}, CV_32FC1);
m.dims = 1;
auto rmat = cv::make_rmat<cv::gimpl::RMatOnMat>(m);
auto view = rmat.access(cv::RMat::Access::R);
auto out = cv::gimpl::asMat(view);
EXPECT_EQ(1, out.dims);
}
} // namespace opencv_test