Opencv4.1.0+VS2015 Surf特征匹配

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;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值