Ask Your Question
1

Very (very) large image causes issues with function (int type related)

asked 2017-11-21 04:10:59 -0600

Florent Tomi gravatar image

Hello !

I'm working on large images (~65000x40000 on average). I've experienced multiple issues with some functions (ie. cv::threshold and cv::medianBlur) that I don't have if I downscale these images.

After some code digging, I think the issue comes from the use of "int" types in most functions which, obviously, can't fit my size.

For example, in functions cv::threshold with Triangle method, operations like this are done:

size.width *= size.height

Is there any "easy" solution to use "int64" instead of "int" in OpenCV ? I've tried to change cv::Size alias from Size2i to Size2l but it isn't enough as most of OpenCV functions uses "int" as input/output type...

Thanks :)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-11-21 16:39:22 -0600

Tetragramm gravatar image

Easy? No. But you can make the changes in each function as you use them and submit the changes as a pull request so they get integrated into the main trunk.

Part of the heritage of OpenCV is that it was once all C code. So it lacks a uniform use of typedefs or templates, such as the size_t you're familiar with from the C++ STL. So most people going along just assumed that int will be big enough.

Also, those are really big images.

edit flag offensive delete link more

Comments

Thanks for the quick answer.

I assume OpenCV is also meant to be memory efficient so a straightforward change from int to size_t isn't a viable solution (even if, maybe, the change on cv::Size maybe insignificant in this regard). Am I right ?

However, this kind of change seems difficult to avoid (in C++).

In any case, I will typedef Size as Size_ <std::size_t> to workaround my (very) niche needs and see if it's enough for my algorithm. If I see that it works just fine and that it doesn't impact the memory efficiency of the library too much, I'll propose it to the community :).

Florent Tomi gravatar imageFlorent Tomi ( 2017-11-22 03:12:53 -0600 )edit

Yeah, the change from a 32 to 64 bit total size should have very little effect. You could even just change it to an unsigned int. It's just that there's no standard type for total size, so people just used whatever they thought was appropriate, which was often an int.

Tetragramm gravatar imageTetragramm ( 2017-11-22 12:38:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-11-21 04:10:59 -0600

Seen: 485 times

Last updated: Nov 21 '17