Skip to content

[G-API] Fix problems with 1D cv::Mat as graph output#21782

Merged
alalek merged 9 commits intoopencv:4.xfrom
TolyaTalamanov:at/fix-1d-mat-problems
Mar 31, 2022
Merged

[G-API] Fix problems with 1D cv::Mat as graph output#21782
alalek merged 9 commits intoopencv:4.xfrom
TolyaTalamanov:at/fix-1d-mat-problems

Conversation

@TolyaTalamanov
Copy link
Copy Markdown
Contributor

@TolyaTalamanov TolyaTalamanov commented Mar 25, 2022

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Overview

This PR fixes the problem with 1D cv::Mat as graph output.
Problem reproducer:

cv::Mat m({2048}, CV_8U); // create cv::Mat with m.size equal to [1, 2048]
m.dims = 1;               // Ok, let's apply WA, after that m.size == [2048].
m.create({2048}, CV_8U);  // Re-create mat with the same 1D meta and get error.

Build configuration

force_builders=Custom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

Xbuild_image:Custom=centos:7
Xbuildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

build_image:Custom=ubuntu-openvino-2021.4.1:20.04
build_image:Custom Win=openvino-2021.4.1
build_image:Custom Mac=openvino-2021.4.1

test_modules:Custom=gapi,python2,python3,java
test_modules:Custom Win=gapi,python2,python3,java
test_modules:Custom Mac=gapi,python2,python3,java

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*


if( data && (d == dims || (d == 1 && dims <= 2)) && _type == type() )
{
if ( d == 1 && _sizes[0] == size[0] )
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alalek Could you have a look:
below there is a condition:

if( i == d && (d > 1 || size[1] == 1))
    return;

Checking size[1] will cause error, because d <= 1.
Is it valid to check size[1] in that case?
https://github.com/opencv/opencv/blob/4.x/modules/core/src/matrix.cpp#L672

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

&& dims == 1 to preserve old behavior for requesting 1D size of pre-allocated 2D.


size[1] was valid (without 1D hacks). We could add dims == 2 precheck there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added

{
GAPI_Assert(!desc.planar);
mat.create(desc.dims, desc.depth);
#if !defined(GAPI_STANDALONE)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dmatveev
Copy link
Copy Markdown
Contributor

I believe tests should be added to the core OpenCV as well as reviewers should be from the core OpenCV team first

@TolyaTalamanov TolyaTalamanov force-pushed the at/fix-1d-mat-problems branch from fbe6b78 to 0484124 Compare March 28, 2022 13:05
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@alalek Could you have a look, please?

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@rgarnov Could you have a look, please?

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

"core" part looks good to me

@alalek alalek merged commit 9390c56 into opencv:4.x Mar 31, 2022
@opencv-pushbot opencv-pushbot mentioned this pull request Apr 23, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…blems

[G-API] Fix problems with 1D cv::Mat as graph output

* Fix issues with 1D cv::Mat

* Fix cv::Mat::create

* Fix standalone build

* Add test on 1d mat

* Fix warning

* Add additional condition

* Add more tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants