Skip to content

handle huge matrices correctly#11505

Merged
vpisarev merged 8 commits intoopencv:3.4from
vpisarev:huge_img_handling
May 14, 2018
Merged

handle huge matrices correctly#11505
vpisarev merged 8 commits intoopencv:3.4from
vpisarev:huge_img_handling

Conversation

@vpisarev
Copy link
Copy Markdown
Contributor

@vpisarev vpisarev commented May 11, 2018

make sure that the matrix with more than INT_MAX elements is marked as non-continuous, and thus all the pixel-wise functions process it correctly (i.e. row-by-row, not as a single row, where integer overflow may occur when computing the total number of elements).

resolves #10211

force_builders=Custom
docker_image:Custom=ubuntu-cuda:16.04

…s non-continuous, and thus all the pixel-wise functions process it correctly (i.e. row-by-row, not as a single row, where integer overflow may occur when computing the total number of elements)
@alalek
Copy link
Copy Markdown
Member

alalek commented May 11, 2018

BTW, Do we want to fix "continuous" / "contiguous" mess?

Memory block is contiguous.
Mathematic function is continuous.

Related StackOverflow questions:

@vpisarev
Copy link
Copy Markdown
Contributor Author

vpisarev commented May 11, 2018

yes, definitely. And it's not a mess at all. On small images (like 20x20) this trick with

Size size = mat.size();
if( mat.isContinuous() ) { size.width *= size.height; size.height = 1; }

can accelerate processing by 10-20% in the case of simple functions. And it's put in many places of the library and in the user code as well. Obviously, this trick can only be done with size.width * size.height not bigger than INT_MAX. And it's also obviously that it only needs to be checked during matrix construction (just few places in the library), not when you process the matrix (many places in the library and in the user code). We attempted to implement such check in updateContinuityFlag() function, but 1) it contained a bug and 2) it was not used everywhere.

@alalek
Copy link
Copy Markdown
Member

alalek commented May 14, 2018

I mean this typo:

-continous
+contiguous

One more reference: https://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.ascontiguousarray.html

@vpisarev vpisarev merged commit e0dbe5c into opencv:3.4 May 14, 2018
@hrnr
Copy link
Copy Markdown
Contributor

hrnr commented May 14, 2018

Do I understand correctly that huge arrays (matrix 1xN) are still not supported by cv::Mat? Or is it somehow solved too?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants