opencv 31.Flann匹配器

  FLANN是快速最近邻搜索包(Fast_Library_for_Approximate_Nearest_Neighbors)的简称。它是一个对大数据集和高维特征进行最近邻搜索的算法的集合,而且这些算法都已经被优化过了。在面对大数据集是它的效果要好于BFMatcher。
  使用FLANN匹配,我们需要传入两个字典作为参数。这两个用来确定要使用的算法和其他相关参数等。
FLANN是一个单独的算法库,opencv中引用了,具体的算法以及上面的参数k-d树算法还没研究,目前只学习下opencv中的使用方法

//29 flann匹配
void StartOp2::ImageProcess2_29()
{
	Mat img1 = imread("../../Images/22.jpg", IMREAD_GRAYSCALE);
	Mat img2 = imread("../../Images/23.jpg", IMREAD_GRAYSCALE);
	if (!img1.data || !img2.data) {

	}
	imshow("image1", img1);
	imshow("image2", img2);

	int minHessian = 400;
	Ptr<SURF> detector = SURF::create(minHessian);
	vector<KeyPoint> keypoints_1;
	vector<KeyPoint> keypoints_2;

	Mat descriptor_1, descriptor_2;
	detector->detectAndCompute(img1, Mat(), keypoints_1, descriptor_1);
	detector->detectAndCompute(img2, Mat(), keypoints_2, descriptor_2);

	//matching
	FlannBasedMatcher matcher;
	vector<DMatch> matches;
	matcher.match(descriptor_1, descriptor_2, matches);

	//find good matched points
	double minDist = 1000;
	double maxDist = 0;
	for (int i=0;i<descriptor_1.rows;i++)
	{
		double dist = matches[i].distance;
		if (dist>maxDist)
		{
			maxDist = dist;
		}
		if (dist<minDist)
		{
			minDist = dist;
		}
	}

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

	Mat matchesImage;
	drawMatches(img1, keypoints_1,img2,keypoints_2,goodMatches,matchesImage,Scalar::all(-1),Scalar::all(-1),vector<char>(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

	imshow("output",matchesImage);
}

参考文章:
https://blog.csdn.net/qq_36387683/article/details/80578480
https://blog.csdn.net/cshilin/article/details/52107580

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值