FLANN特征匹配

C++源码

#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;

int main()
{
	Mat srcImage = imread("curry_dlt.jpg");
	Mat dstImage = imread("curry1.jpg");

	// surf 特征提取
	int minHessian = 450;
	Ptr<SURF> detector = SURF::create(minHessian);
	vector<KeyPoint> keypoints_src;
	vector<KeyPoint> keypoints_dst;
	Mat descriptor_src, descriptor_dst;
	detector->detectAndCompute(srcImage, Mat(), keypoints_src, descriptor_src);
	detector->detectAndCompute(dstImage, Mat(), keypoints_dst, descriptor_dst);

	// matching
	FlannBasedMatcher matcher;
	vector<DMatch> matches;
	matcher.match(descriptor_dst, descriptor_src, matches);

	// find good matched points
	double minDist = 0, maxDist = 0;
	for (size_t i = 0; i < matches.size(); i++)
	{
		double dist = matches[i].distance;
		if (dist > maxDist)
			maxDist = dist;
		if (dist < minDist)
			minDist = dist;
	}

	vector<DMatch> goodMatches;
	for (size_t i = 0; i < matches.size(); i++)
	{
		double dist = matches[i].distance;
		if (dist < max(3 * minDist, 0.02))
		{
			goodMatches.push_back(matches[i]);
		}
	}

	Mat matchesImage;
	drawMatches(dstImage, keypoints_dst, srcImage, keypoints_src, goodMatches, matchesImage, Scalar::all(-1), \
		Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

	imshow("matchesImage", matchesImage);

	waitKey(0);
	return 0;
}

blog 2 link:http://www.pianshen.com/article/5346279399/
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值