Ask Your Question
3

Drawing limited by size of int in opencv

asked 2013-03-14 19:40:22 -0600

maym86 gravatar image

Hello

I have a large image greater than 32768px wide.

When I try and draw on the image at an x position greater than 32768 nothing is drawn. I think the value is limited to 16 bit even though the input value for cv::Line in cv::Point which specifies int. When I get the size of an int from c++ it states that the max is 2,147,483,648 which is 32 bit.

When I read the value from the cv::Point they are greater than 32768 but once they are passed to the opencv drawing functions it seems that they are truncated.

The system is 64bit Windows 7. VC++ 2010 and OpenCV 2.4.3. I am building a 64-bit application.

Thanks for any help,

Mike

edit retag flag offensive close merge delete

Comments

3

Did you report it on the bug tracker? It seems that drawing line is using 16 bits integer (with the shift operation I'm not very familiar with...)

Mathieu Barnachon gravatar imageMathieu Barnachon ( 2013-03-15 03:59:52 -0600 )edit
2

static void ThickLine(...) in modules/core/src drawing.cpp, L ~1463 seems to be the culprit.

the input points are left-shifted by 16, yes, that will overflow for values > 32768

berak gravatar imageberak ( 2013-03-15 04:51:41 -0600 )edit
1

update, looking at the docs again:

<code>

line(Mat&amp; img, Point pt1, Point pt2, const Scalar&amp; color, int thickness=1, int lineType=8, int shift=0)

</code>

"shift – Number of fractional bits in the point coordinates."

what they're doing is this: <code>

p0.x <<= XY_SHIFT - shift;

</code>

so you could at least try a "tradeoff" by supplying a value for shift, 1 would double the range, 2 x4, etc, possibly reducing the quality, but increasing the range of your point coords this way

(sadly, i can't test or reproduce it, only 2gigs ram here ;[ )

berak gravatar imageberak ( 2013-03-15 06:19:26 -0600 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2013-03-15 05:14:50 -0600

Have had the same problem, simple solution that I added whas to subdivide my image into regions of interest, drawing in those regions, then jumping to the next region. This way your region of interest can be kept inside the integer limitations.

I guess you will split up eventually, or are you displaying the full image at once?

edit flag offensive delete link more

Comments

Yes I am splitting the image to display it.

That sounds like a good idea. Thanks. I will try it.

maym86 gravatar imagemaym86 ( 2013-03-15 11:44:18 -0600 )edit

It works here perfectly for images 25000 x 25000 pixels, so guess it should work for you also.

Mat window = inputImage(Rect(x,y,width,heigth)); does all you want :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-15 14:31:33 -0600 )edit
1

Yeah implemented it and works great. Thanks. Every time x is greater than 32768 I set a new ROI and plot relative to that.

Still confusing that they use a short for the int value though.

maym86 gravatar imagemaym86 ( 2013-03-15 15:05:44 -0600 )edit
1

Guess that may be a restriction due to an internal function expecting a short. You could post it as a bug on development forum (http://code.opencv.org/projects/OpenCV/wiki/WikiStart#Creating-new-tickets) and hope they add a fix to it. Even better, if you can fix it, then do so, and add a ticket to add it to the openCV pipeline.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-15 16:38:13 -0600 )edit
1

Posted a bug report and I'll have a look to see if I can fix it myself if I get some time. Thanks.

maym86 gravatar imagemaym86 ( 2013-03-15 17:18:14 -0600 )edit

Question Tools

Stats

Asked: 2013-03-14 19:40:22 -0600

Seen: 1,026 times

Last updated: Mar 15 '13