diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index 6d8388e23..1f182ba07 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -602,11 +602,22 @@ bool PyramidAdaptedFeatureDetector::empty() const void PyramidAdaptedFeatureDetector::detectImpl( const Mat& image, vector& keypoints, const Mat& mask ) const { Mat src = image; + Mat src_mask = mask; + + Mat dilated_mask; + if( !mask.empty() ) + { + dilate( mask, dilated_mask, Mat() ); + Mat mask255( mask.size(), CV_8UC1, Scalar(0) ); + mask255.setTo( Scalar(255), dilated_mask != 0 ); + dilated_mask = mask255; + } + for( int l = 0, multiplier = 1; l <= maxLevel; ++l, multiplier *= 2 ) { // Detect on current level of the pyramid vector new_pts; - detector->detect( src, new_pts, mask ); + detector->detect( src, new_pts, src_mask ); for( vector::iterator it = new_pts.begin(), end = new_pts.end(); it != end; ++it) { it->pt.x *= multiplier; @@ -620,10 +631,16 @@ void PyramidAdaptedFeatureDetector::detectImpl( const Mat& image, vector