Search code examples
c++opencvcomputer-sciencesift

Compute Dense SIFT features in OpenCV 3.0


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!


Solution

  • 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