How to crete a SIFT's descriptors database

别说谁变了你拦得住时间么 提交于 2019-12-25 04:33:06

问题


How do I create a database of SIFT descriptors (of images)? My intention is to implement a supervisioned training set on Support Vector Machine.


回答1:


Which kind of images do you need? If you don`t care, you can just download some public computer vision dataset like http://lear.inrialpes.fr/~jegou/data.php#holidays which offers both images and already computed SIFTs from its regions. Or try other datasets, for instance, from http://www.cvpapers.com/datasets.html

Other possibility is just to download\make lots of photos, detect interest point and describe them with SIFTs. It can be done with OpenCV, VLFeat or other libraries.

OpenCV example.

    #include <opencv2/opencv.hpp>
    #include <opencv2/nonfree/nonfree.hpp>
    #include <fstream>


    void WriteSIFTs(std::vector<cv::KeyPoint> &keys, cv::Mat desc, std::ostream &out1)
    {
      for(int i=0; i < (int) keys.size(); i++)
        {
          out1 << keys[i].pt.x << " " << keys[i].pt.y << " " << keys[i].size << " " << keys[i].angle << " "; 
//If you don`t need information about keypoints (position, size) 
//you can comment out the string above

          float* descPtr = desc.ptr<float>(i);
          for (int j = 0; j < desc.cols; j++)
              out1  << *descPtr++ << " ";
          out1 << std::endl;
        }

    }


    int main(int argc, const char* argv[])
    {
      const cv::Mat img1 = cv::imread("graf.png", 0); //Load as grayscale

      cv::SiftFeatureDetector detector;
      std::vector<cv::KeyPoint> keypoints;
      detector.detect(img1, keypoints);

      cv::SiftDescriptorExtractor extractor;
      cv::Mat descriptors;
      extractor.compute(img1, keypoints, descriptors);

      std::ofstream file1("SIFTs1.txt");
      if (file1.is_open())
        WriteSIFTs(keypoints,descriptors,file1);
      file1.close();
      return 0;
    }


来源:https://stackoverflow.com/questions/19849592/how-to-crete-a-sifts-descriptors-database

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