# Strange assert in surf_gpu.cpp

I get very strange asserts in my code, changing the size of the input image.

        CV_Assert(img_rows - min_size >= 0);
CV_Assert(img_cols - min_size >= 0);

or

CV_Assert(layer_rows - 2 * min_margin > 0);
CV_Assert(layer_cols - 2 * min_margin > 0);


Line 125 surf_gpu.cpp opencv 2.4.5

I decided to read the code and came across a black magic

Code (line 131):

const int min_margin = ((calcSize((surf_.nOctaves - 1), 2) >> 1) >> (surf_.nOctaves - 1)) + 1;


gives always 11

proof:

this is bug or not?

edit retag close merge delete

Sort by ยป oldest newest most voted

It is not a bug. GPU SURF doesn't support small image size. This assert checks that input image has proper size.

UPDATE

Why min_margin is always 11?

sizeo(oct, layer) = (9 + 6*layer) << oct = (9 + 6*layer)*(2^oct)
sizeo(oct - 1, 2) = (9 + 6*2)*(2^(oct - 1)) = 21 * (2^(oct - 1))
sizeo(oct - 1, 2) >> 1 = sizeo(oct - 1, 2) / 2 = 21 * (2^(oct - 2))
(sizeo(oct - 1, 2) >> 1) >> (oct - 1) = (sizeo(oct - 1, 2) >> 1) * (2^(1 - oct)) = 21 * (2^(oct - 2)) * (2^(1 - oct)) = 21/2 === 10
getsd(oct) = ((sizeo(oct - 1, 2) >> 1) >> (oct - 1)) + 1 === 11

more

I solved the problem with the small image size. But why line 131 returns always 11? =)

( 2013-07-24 02:35:33 -0500 )edit
1

Thanks for the proof. Then maybe we should change the line 131 to const int min_margin = 11;

( 2013-07-24 04:22:11 -0500 )edit

Official site

GitHub

Wiki

Documentation