Search code examples
c++opencvimage-processingcomputer-visionvlfeat

Dense SIFT Keypoints & Descriptor Extraction using vlfeat


I'm currently using Dense SIFT from vlfeat. But I got only a single keypoint & descriptor out from the code. But the number of keypoints returned was more. How to extract all the keypoints & descriptors.

Also Descriptor was a single value and it should be of 128 X N.

The code is as follows.

The vlkeypoints size was only one. How to extract all the keypoints?

    img = imread("filename.jpg");

     // create filter
    vlf = vl_dsift_new(img.rows, img.cols, 1, 3);

    // transform image in cv::Mat to float vector
    std::vector<float> imgvec;
    for (int i = 0; i < img.rows; ++i){
      for (int j = 0; j < img.cols; ++j){
        imgvec.push_back(img.at<unsigned char>(i,j) / 255.0f);                                                                                                                                                                                                        
      }
    }
    // call processing function of vl
    vl_dsift_process(vlf, &imgvec[0]);

    // echo number of keypoints found
    std::cout << vl_dsift_get_keypoint_num(vlf) << std::endl;

    // Extract keypoints
    VlDsiftKeypoint * vlkeypoints;
    vlkeypoints = vl_dsift_get_keypoints(vlf);

Solution

  • for (int i = 0; i < numKeyPoints; i++) {
        cout << vlkeypoints[i].x << endl;
        cout << vlkeypoints[i].y << endl;
    }