#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>
#include "opencv2/legacy/legacy.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
Mat img_1 = imread("girl1.jpg");
Mat img_2 = imread("ResultGirl1.jpg");
if( !img_1.data || !img_2.data )
{
printf("读取图片错误,请确定目录下是否有imread函数指定的图片存在~! \n");
return false;
}
int minHessian = 5000;
SurfFeatureDetector detector( minHessian );
vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute( img_1, keypoints_1, descriptors1 );
extractor.compute( img_2, keypoints_2, descriptors2 );
BruteForceMatcher< L2<float> > matcher;
vector< DMatch > matches;
matcher.match( descriptors1, descriptors2, matches );
Mat imgMatches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, imgMatches );//进行绘制
imshow("匹配图", imgMatches );
/*
Mat img_keypoints_1; Mat img_keypoints_2;
drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
imshow("Keypoints 1", img_keypoints_1 );
imshow("Keypoints 2", img_keypoints_2 );
*/
waitKey(5000);
cout<<"按任意键继续……";
cin.get();
return 0;
}