aihot  2017-05-06 17:55:13  OpenCV |   查看评论   
return 0; }

这里有一个值得说明的问题是:OpenCV2.4版本后好像把SurfFeatureDetector这个类的定义移到了头文件nonfree/features2d.hpp

中,所以头文件中要加入该文件,并且要把opencv_nonfree24xd.lib加入属性表的链接器熟悉的输入中,其中x换成你当前opencv的版本号。

最终的显示效果如下:

OpenCV成长之路(9):特征点检测与图像匹配

四、SURF特征的描述

在图像配准中,特征点的描述往往不是位置这么简单,而是使用了一个N维向量来描述一个特征点,这些描述子之间可以通过定义距离公式来比较相近程度。

SurfDescriptorExtractor 是一个提取SURF特征点以及其描述的类。

 

下面是一个宽景图像的拼接配准的例子:

OpenCV成长之路(9):特征点检测与图像匹配  OpenCV成长之路(9):特征点检测与图像匹配

 

#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/nonfree/features2d.hpp> #include <opencv2/legacy/legacy.hpp>

using namespace cv; int main() {     Mat image1=imread("../b1.png");     Mat image2=imread("../b2.png");     // 检测surf特征点
    vector<KeyPoint> keypoints1,keypoints2;          SurfFeatureDetector detector(400);     detector.detect(image1, keypoints1);     detector.detect(image2, keypoints2);     // 描述surf特征点
    SurfDescriptorExtractor surfDesc;     Mat descriptros1,descriptros2;     surfDesc.compute(image1,keypoints1,descriptros1);     surfDesc.compute(image2,keypoints2,descriptros2);      // 计算匹配点数
    BruteForceMatcher<L2<float>>matcher;     vector<DMatch> matches;     matcher.match(descriptros1,descriptros2,matches);     std::nth_element(matches.begin(),matches.begin()+24,matches.end());     matches.erase(matches.begin()+25,matches.end());     // 画出匹配图
    Mat imageMatches;     drawMatches(image1,keypoints1,image2,keypoints2,matches,         imageMatches,Scalar(255,0,0));      namedWindow("image2");     imshow("image2",image2);     waitKey();          return 0; }

程序中我们选择了25个配准点,得到最后的匹配如下:

OpenCV成长之路(9):特征点检测与图像匹配

 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自OpenCV成长之路(9):特征点检测与图像匹配

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]