Compute Dense SIFT features in OpenCV 3.0

◇◆丶佛笑我妖孽 提交于 2019-12-22 04:54:50

问题


Since version 3.0, DenseFeatureDetector is no longer available. Could anybody please show me how to compute Dense SIFT features in OpenCV 3.0? I couldn't find it in the documentation.

Thank you very much in advance!


回答1:


Here's how I used dense SIFT in OpenCV 3 C++:

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

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

seems to work well




回答2:


You can pass a list of cv2.KeyPoints to sift.compute. This example is in Python, but it shows the principle. I create a list of cv2.KeyPoints by scanning through the pixel locations of the image:

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)


来源:https://stackoverflow.com/questions/33120951/compute-dense-sift-features-in-opencv-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!