2014-03-19 40 views
1

我正在尝试计算图像数据库的ORB(Oriented FAST and Rotated BRIEF)功能。 nexr的任务是使用Bag Of Words方法来计算图像的最终特征。我的问题是,在某些情况下,我从数据库的图像中获取了0个关键点(无论是在ORB中还是在BRISK实现中)。我的代码是here使用ORB描述符检测零关键点

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找到一个关键点?如何对这些情况使用密集取样?

回答

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); 
} 

然而,正如你会发现,这种做法不处理的关键点的角度。如果你的图像有旋转,这可能是一个问题。