问题
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