#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include<xfeatures2d/nonfree.hpp>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
Mat image1,image2;
int main()
{
image1 = imread("C:/Users/zhang/Desktop/77.png");
image2 = imread("C:/Users/zhang/Desktop/76.png");
imshow("原图像1", image1);
imshow("原图像2", image2);
//////////////检测
int Hessian = 400;//海塞矩阵阈值,在这里调整精度,值越大点越少,越精准
Ptr<SURF> Detector = SURF::create(Hessian);
vector<KeyPoint> keyPoint1, keyPoint2;//KeyPoint专门为特征点建立的坐标类型
Mat point_image1, point_image2;
Detector->detectAndCompute(image1,Mat(), keyPoint1, point_image1);
//detect寻找特征点的坐标
//detectAndCompute寻找特征点的坐标同时求出特征点周围的描述子向量
Detector->detectAndCompute(image2, Mat(), keyPoint2, point_image2);
/////////////////匹配
BFMatcher matcher;//通过BF暴力匹配
vector<DMatch> matchePoints;//DMatch专门为特征点匹配建立的类型
matcher.match(point_image1, point_image2, matchePoints, Mat());
//把两幅图像合成一幅图像。并且找到两幅图像相同的特征点(利用欧式距离)
//所以matchePoints保存的是两个相同特征点之间的距离,距离越小两个特征点就会相似
Mat img_match;
drawMatches(image1, keyPoint1, image2, keyPoint2, matchePoints, img_match);//画线
imshow("特征匹配", img_match);
waitKey(0);
return 0;
}
|
|