在 OpenCV 3.0 中计算密集 SIFT 特征

Compute Dense SIFT features in OpenCV 3.0

从 3.0 版开始,DenseFeatureDetector 不再可用。谁能告诉我如何在 OpenCV 3.0 中计算密集 SIFT 特征?我在文档中找不到它。

非常感谢您!

您可以将 cv2.KeyPoints 的列表传递给 sift.compute。这个例子在Python里,但是说明了原理。我通过扫描图像的像素位置创建了一个 cv2.KeyPoint 列表:

import skimage.data as skid
import cv2
import pylab as plt

img = skid.lena()
gray= cv2.cvtColor(img ,cv2.COLOR_BGR2GRAY)

sift = cv2.xfeatures2d.SIFT_create()

step_size = 5
kp = [cv2.KeyPoint(x, y, step_size) for y in range(0, gray.shape[0], step_size) 
                                    for x in range(0, gray.shape[1], step_size)]

img=cv2.drawKeypoints(gray,kp, img)

plt.figure(figsize=(20,10))
plt.imshow(img)
plt.show()

dense_feat = sift.compute(gray, kp)

以下是我在 OpenCV 3 C++ 中使用密集 SIFT 的方法:

SiftDescriptorExtractor sift;

vector<KeyPoint> keypoints; // keypoint storage
Mat descriptors; // descriptor storage

// manual keypoint grid

int step = 10; // 10 pixels spacing between kp's

for (int y=step; y<img.rows-step; y+=step){
    for (int x=step; x<img.cols-step; x+=step){

        // x,y,radius
        keypoints.push_back(KeyPoint(float(x), float(y), float(step)));
    }
}

// compute descriptors

sift.compute(img, keypoints, descriptors);

复制自: http://answers.opencv.org/question/73165/compute-dense-sift-features-in-opencv-30/?answer=73178#post-id-73178

似乎效果不错