Opencv3之后的版本Surf等算法的使用方法和Opencv2有所差别,这是基本的surf特征匹配代码,供参考。
#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/core.hpp>
#include<opencv2/features2d.hpp>
#include<opencv2/xfeatures2d.hpp>
using namespace std;
using namespace cv;
using namespace cv::xfeatures2d;
int main()
{
Mat image01 = imread("C:/Users/86158/Desktop/164.jpg", 1);
Mat image02 = imread("C:/Users/86158/Desktop/163.jpg", 1);
namedWindow("p2", 0);
namedWindow("p1", 0);
imshow("p2", image01);
imshow("p1", image02);
Mat image1, image2;
cvtColor(image01, image1, COLOR_BGR2GRAY);
cvtColor(image02, image2, COLOR_BGR2GRAY);
int minHessian = 400;
Ptr<SURF> detector = SURF::create(minHessian);
vector<KeyPoint> keyPoint1, keyPoint2;
detector->detect(image1, keyPoint1);
detector->detect(image2, keyPoint2);
Ptr<SurfDescriptorExtractor> descriptor=SURF::create();
Mat imageDesc1, imageDesc2;
descriptor->compute(image1, keyPoint1, imageDesc1);
descriptor->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;
}