了解了SIFT特征后,来学习SURF特征。
虽说是SIFT的一个变种,但是跟SIFT还是有区别的
区别有如下:
1.尺度空间的构建(近似)不同。
2.允许尺度空间多层图像同时被处理
3.特征点主方向确定采用haar小波特征统计方法。
4.特征点描述子采用haar小波特征。
接下来贴个SURF匹配代码:
// Load image from file
IplImage *pLeftImage = cvLoadImage("1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
IplImage *pRightImage = cvLoadImage("2.jpg", CV_LOAD_IMAGE_GRAYSCALE);
// Convert IplImage to cv::Mat
Mat matLeftImage = Mat(pLeftImage, false); //
Mat matRightImage = Mat(pRightImage, false);
// Key point and its descriptor
vector<KeyPoint> LeftKey;
vector<KeyPoint> RightKey;
Mat LeftDescriptor;
Mat RightDescriptor;
vector<DMatch> Matches;
// Detect key points from image
FeatureDetector *pDetector = new SurfFeatureDetector; // 这里我们用了SURF特征点
pDetector->detect(matLeftImage, LeftKey);
pDetector->detect(matRightImage, RightKey);
// delete pDetector;
// Extract descriptors
DescriptorExtractor *pExtractor = new SurfDescriptorExtractor; // 提取SURF描述向量
pExtractor->compute(matLeftImage, LeftKey, LeftDescriptor);
pExtractor->compute(matRightImage, RightKey, RightDescriptor);
//delete pExtractor;
// Matching features
DescriptorMatcher *pMatcher = new FlannBasedMatcher; // 使用Flann匹配算法
pMatcher->match(LeftDescriptor, RightDescriptor, Matches);
//delete pMatcher;
// Show result
Mat OutImage;
drawMatches(matLeftImage, LeftKey, matRightImage, RightKey, Matches, OutImage);
cvNamedWindow( "SURF Match features", 1);
cvShowImage("SURF Match features", &(IplImage(OutImage)));
cvWaitKey( 0 );
cvDestroyWindow( "SURF Match features" );
return 0;
调试一下:
两幅图像分别生成SURF特征描述子。
当然也可看到其中的值。
做这个也只是想表达一下 ,OpenCV结合VS可以做到跟MATLAB一样的效果。。。。
SURF学习相关链接:
http://blog.csdn.net/andkobe/article/details/5778739
http://blog.csdn.net/crzy_sparrow/article/details/7392345
http://www2.ulg.ac.be/telecom/research/vibe/download.html