使用ORB描述符检测零特征点
我正在尝试为一组图片计算ORB(定向FAST和旋转BRIEF)特征。接下来的任务是使用“词袋”方法来计算图片的最终特征。不过,我遇到的问题是,有时候从数据库中的图片中得到的关键点数量是0(无论是使用ORB还是BRISK实现)。我的代码来自这里。
img = cv2.imread('D:/_DATABASES/clothes_second/striped_141.descr',0)
orb = cv2.ORB()
kp = orb.detect(img,None)
kp, des = orb.compute(img, kp)
img2 = cv2.drawKeypoints(img,kp,color=(0,255,0), flags=0)
plt.imshow(img2),plt.show()
在这种情况下,有什么办法至少让ORB找到一个关键点吗?对于这些情况,如何使用密集采样呢?
1 个回答
2
你可以使用一种叫做“密集特征检测器”的工具,类似于在C++中实现的那个:http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html#densefeaturedetector
不过,我不太确定这个工具是否已经移植到Python中了。不过,因为这个算法其实不太复杂,你可以自己动手实现。下面是C++中的实现代码:
void DenseFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask ) const
{
float curScale = static_cast<float>(initFeatureScale);
int curStep = initXyStep;
int curBound = initImgBound;
for( int curLevel = 0; curLevel < featureScaleLevels; curLevel++ )
{
for( int x = curBound; x < image.cols - curBound; x += curStep )
{
for( int y = curBound; y < image.rows - curBound; y += curStep )
{
keypoints.push_back( KeyPoint(static_cast<float>(x), static_cast<float>(y), curScale) );
}
}
curScale = static_cast<float>(curScale * featureScaleMul);
if( varyXyStepWithScale ) curStep = static_cast<int>( curStep * featureScaleMul + 0.5f );
if( varyImgBoundWithScale ) curBound = static_cast<int>( curBound * featureScaleMul + 0.5f );
}
KeyPointsFilter::runByPixelsMask( keypoints, mask );
}
不过,你会发现这个实现没有处理关键点的角度。如果你的图片有旋转,这可能会成为一个问题。