#include<opencv2/features2d/features2d.hpp>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/xfeatures2d/nonfree.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
int main()
{
Mat image01 = imread("C:\\Users\\Apple\\Desktop\\2.png"); //右图
Mat image02 = imread("C:\\Users\\Apple\\Desktop\\1.png"); //左图
if (!image01.data || !image02.data)
{
cout << "读取图片出错" << endl;
return false;
}
namedWindow("p2", 0);
namedWindow("p1", 0);
imshow("p2", image01);
imshow("p1", image02);
//灰度图转换
Mat image1, image2;
cvtColor(image01, image1, CV_RGB2GRAY);
cvtColor(image02, image2, CV_RGB2GRAY);
//提取特征点
Ptr<SURF> surfDetector=SURF::create(2000); //海塞矩阵阈值,在这里调整精度,值越大点越少,越精准
vector<KeyPoint> keyPoint1, keyPoint2;
surfDetector->detect(image1, keyPoint1);
surfDetector->detect(image2, keyPoint2);
//特征点描述,为下边的特征点匹配做准备
Ptr<SURF> SurfDescriptor = SURF::create();
Mat imageDesc1, imageDesc2;
SurfDescriptor->compute(image1, keyPoint1, imageDesc1);
SurfDescriptor->compute(image2, keyPoint2, imageDesc2);
//获得匹配特征点,并提取最优配对
FlannBasedMatcher matcher;
vector<DMatch> matchePoints;
matcher.match(imageDesc1, imageDesc2, matchePoints, Mat());
cout << "total match points: " << matchePoints.size() << endl;
Mat img_match;
drawMatches(image01, keyPoint1, image02, keyPoint2, matchePoints, img_match);
namedWindow("match", 0);
imshow("match", img_match);
//imwrite("match.jpg", img_match);
waitKey();
return 0;
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/xfeatures2d/nonfree.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;
int main()
{
Mat image01 = imread("C:\\Users\\Apple\\Desktop\\2.png"); //右图
Mat image02 = imread("C:\\Users\\Apple\\Desktop\\1.png"); //左图
if (!image01.data || !image02.data)
{
cout << "读取图片出错" << endl;
return false;
}
namedWindow("p2", 0);
namedWindow("p1", 0);
imshow("p2", image01);
imshow("p1", image02);
//灰度图转换
Mat image1, image2;
cvtColor(image01, image1, CV_RGB2GRAY);
cvtColor(image02, image2, CV_RGB2GRAY);
//提取特征点
Ptr<SURF> surfDetector=SURF::create(2000); //海塞矩阵阈值,在这里调整精度,值越大点越少,越精准
vector<KeyPoint> keyPoint1, keyPoint2;
surfDetector->detect(image1, keyPoint1);
surfDetector->detect(image2, keyPoint2);
//特征点描述,为下边的特征点匹配做准备
Ptr<SURF> SurfDescriptor = SURF::create();
Mat imageDesc1, imageDesc2;
SurfDescriptor->compute(image1, keyPoint1, imageDesc1);
SurfDescriptor->compute(image2, keyPoint2, imageDesc2);
//获得匹配特征点,并提取最优配对
FlannBasedMatcher matcher;
vector<DMatch> matchePoints;
matcher.match(imageDesc1, imageDesc2, matchePoints, Mat());
cout << "total match points: " << matchePoints.size() << endl;
Mat img_match;
drawMatches(image01, keyPoint1, image02, keyPoint2, matchePoints, img_match);
namedWindow("match", 0);
imshow("match", img_match);
//imwrite("match.jpg", img_match);
waitKey();
return 0;
}