surf特征提取后在两幅图像中绘制对应线条

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include<opencv2/core/core.hpp>
#include<opencv2/nonfree/nonfree.hpp>
#include<opencv2/features2d/features2d.hpp>
#include<opencv2/legacy/legacy.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace cv;
using namespace std;
/// 使用Shi-Tomasi方法检测角点,再对角点位置进行精准化
int main( int argc, char** argv )
{
Mat srcImage1=imread("8.jpg",1);
Mat srcImage2=imread("81.jpg",1);
imshow("1",srcImage1);
imshow("2",srcImage2);


int minHessian=2000;  //进行surf提取关键点
SurfFeatureDetector detector(minHessian);
//定义一个检测器
std::vector<KeyPoint>keyPoint1,KeyPoint2;//定义关键点
detector.detect(srcImage1,keyPoint1);
detector.detect(srcImage2,KeyPoint2);
//检测出关键点
SurfDescriptorExtractor extractor;  //提取特征向量
Mat descriptors1,descriptors2;  //用于存储的特征向量
extractor.compute(srcImage1,keyPoint1,descriptors1);  //从原图中的关键点位置提取特征向量
extractor.compute(srcImage2,KeyPoint2,descriptors2);


imshow("特征向量1",descriptors1);
imshow("特征向量2",descriptors2);
BruteForceMatcher<L2<float>>matcher;  //L2是计算欧拉距离,定义一个匹配器
std::vector<DMatch>matches;  //DMatch里面存储的是descriptor1和descriptor2相似点对应的索引,以及距离
matcher.match(descriptors1,descriptors2,matches); //进行匹配的距离过程
Mat imgMatches; //在两幅图像中绘制两个关键点的连线输出到imgMatches中
drawMatches(srcImage1,keyPoint1,srcImage2,KeyPoint2,matches,imgMatches);
imshow("匹配图",imgMatches);  //显示图像


waitKey(0);
return(0);
}

你可能感兴趣的:(surf特征提取后在两幅图像中绘制对应线条)