diff --git a/modules/gpu/src/cuda/surf.cu b/modules/gpu/src/cuda/surf.cu index 2c9f48f75..0f4d0611b 100644 --- a/modules/gpu/src/cuda/surf.cu +++ b/modules/gpu/src/cuda/surf.cu @@ -323,7 +323,7 @@ namespace cv { namespace gpu { namespace surf const int layer_rows = img_rows >> octave; const int layer_cols = img_cols >> octave; - int min_margin = ((calcSize(octave, 2) >> 1) >> octave) + 1; + const int min_margin = ((calcSize(octave, 2) >> 1) >> octave) + 1; dim3 threads(16, 16); diff --git a/modules/gpu/src/surf.cpp b/modules/gpu/src/surf.cpp index 9a4e6ec91..1d50fb241 100644 --- a/modules/gpu/src/surf.cpp +++ b/modules/gpu/src/surf.cpp @@ -84,6 +84,21 @@ using namespace cv::gpu::surf; namespace { + int calcSize(int octave, int layer) + { + /* Wavelet size at first layer of first octave. */ + const int HAAR_SIZE0 = 9; + + /* Wavelet size increment between layers. This should be an even number, + such that the wavelet sizes in an octave are either all even or all odd. + This ensures that when looking for the neighbours of a sample, the layers + + above and below are aligned correctly. */ + const int HAAR_SIZE_INC = 6; + + return (HAAR_SIZE0 + HAAR_SIZE_INC * layer) << octave; + } + class SURF_GPU_Invoker : private CvSURFParams { public: @@ -102,6 +117,16 @@ namespace CV_Assert(mask.empty() || (mask.size() == img.size() && mask.type() == CV_8UC1)); CV_Assert(nOctaves > 0 && nOctaveLayers > 0); CV_Assert(TargetArchs::builtWith(GLOBAL_ATOMICS) && DeviceInfo().supports(GLOBAL_ATOMICS)); + + const int min_size = calcSize(nOctaves - 1, 0); + CV_Assert(img_rows - min_size >= 0); + CV_Assert(img_cols - min_size >= 0); + + const int layer_rows = img_rows >> (nOctaves - 1); + const int layer_cols = img_cols >> (nOctaves - 1); + const int min_margin = ((calcSize((nOctaves - 1), 2) >> 1) >> (nOctaves - 1)) + 1; + CV_Assert(layer_rows - 2 * min_margin > 0); + CV_Assert(layer_cols - 2 * min_margin > 0); maxFeatures = min(static_cast(img.size().area() * surf.keypointsRatio), 65535); maxCandidates = min(static_cast(1.5 * maxFeatures), 65535); @@ -279,20 +304,6 @@ void cv::gpu::SURF_GPU::uploadKeypoints(const vector& keypoints, GpuMa namespace { - int calcSize(int octave, int layer) - { - /* Wavelet size at first layer of first octave. */ - const int HAAR_SIZE0 = 9; - - /* Wavelet size increment between layers. This should be an even number, - such that the wavelet sizes in an octave are either all even or all odd. - This ensures that when looking for the neighbours of a sample, the layers - above and below are aligned correctly. */ - const int HAAR_SIZE_INC = 6; - - return (HAAR_SIZE0 + HAAR_SIZE_INC * layer) << octave; - } - int getPointOctave(float size, const CvSURFParams& params) { int best_octave = 0;