其他分享
首页 > 其他分享> > FLANN特征匹配

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/
在这里插入图片描述

标签:dist,Mat,descriptor,特征,dst,keypoints,matches,FLANN,匹配
来源: https://blog.csdn.net/yunxinan/article/details/89631553