Skip to content

Commit 205022c

Browse files
committed
Fixed issue in ORB detection if firstLevel property is set above 0
1 parent 12ea847 commit 205022c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

modules/features2d/include/opencv2/features2d.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,11 @@ class CV_EXPORTS_W ORB : public Feature2D
304304
will mean that to cover certain scale range you will need more pyramid levels and so the speed
305305
will suffer.
306306
@param nlevels The number of pyramid levels. The smallest level will have linear size equal to
307-
input_image_linear_size/pow(scaleFactor, nlevels).
307+
input_image_linear_size/pow(scaleFactor, nlevels - firstLevel).
308308
@param edgeThreshold This is size of the border where the features are not detected. It should
309309
roughly match the patchSize parameter.
310-
@param firstLevel It should be 0 in the current implementation.
310+
@param firstLevel The level of pytramid to put source image to. Previous layers are filled
311+
with upscaled source image.
311312
@param WTA_K The number of points that produce each element of the oriented BRIEF descriptor. The
312313
default value 2 means the BRIEF where we take a random point pair and compare their brightnesses,
313314
so we get 0/1 response. Other possible values are 3 and 4. For example, 3 means that we take 3

modules/features2d/src/orb.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ class ORB_Impl : public ORB
673673
void setEdgeThreshold(int edgeThreshold_) { edgeThreshold = edgeThreshold_; }
674674
int getEdgeThreshold() const { return edgeThreshold; }
675675

676-
void setFirstLevel(int firstLevel_) { firstLevel = firstLevel_; }
676+
void setFirstLevel(int firstLevel_) { CV_Assert(firstLevel >= 0); firstLevel = firstLevel_; }
677677
int getFirstLevel() const { return firstLevel; }
678678

679679
void setWTA_K(int wta_k_) { wta_k = wta_k_; }
@@ -1014,7 +1014,7 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
10141014

10151015
int level_dy = image.rows + border*2;
10161016
Point level_ofs(0,0);
1017-
Size bufSize((image.cols + border*2 + 15) & -16, 0);
1017+
Size bufSize((cvRound(image.cols/getScale(0, firstLevel, scaleFactor)) + border*2 + 15) & -16, 0);
10181018

10191019
for( level = 0; level < nLevels; level++ )
10201020
{
@@ -1082,8 +1082,11 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
10821082
copyMakeBorder(mask, extMask, border, border, border, border,
10831083
BORDER_CONSTANT+BORDER_ISOLATED);
10841084
}
1085-
prevImg = currImg;
1086-
prevMask = currMask;
1085+
if (level > firstLevel)
1086+
{
1087+
prevImg = currImg;
1088+
prevMask = currMask;
1089+
}
10871090
}
10881091

10891092
if( useOCL )
@@ -1194,6 +1197,7 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
11941197
Ptr<ORB> ORB::create(int nfeatures, float scaleFactor, int nlevels, int edgeThreshold,
11951198
int firstLevel, int wta_k, int scoreType, int patchSize, int fastThreshold)
11961199
{
1200+
CV_Assert(firstLevel >= 0);
11971201
return makePtr<ORB_Impl>(nfeatures, scaleFactor, nlevels, edgeThreshold,
11981202
firstLevel, wta_k, scoreType, patchSize, fastThreshold);
11991203
}

0 commit comments

Comments
 (0)