C++ OpenCV图片特征匹配

void OpenCVHandle::pashSurf(std::string fixjpg, std::string armjpg)
{
	Mat image01 = imread(fixjpg, 1);
	Mat image02 = imread(armjpg, 1);
	//提取特征点    
	 
	cv::Ptr<cv::xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create(); // 海塞矩阵阈值,在这里调整精度,值越大点越少,越精准 
	vector<KeyPoint> keyPoint1, keyPoint2;
	surf->detect(image01, keyPoint1);
	surf->detect(image02, keyPoint2);

	//特征点描述,为下边的特征点匹配做准备    
 
	cv::Ptr<cv::xfeatures2d::SURF> surf2 = cv::xfeatures2d::SURF::create();
	Mat imageDesc1, imageDesc2;
	surf2->compute(image01, keyPoint1, imageDesc1);
	surf2->compute(image02, keyPoint2, imageDesc2);

	FlannBasedMatcher matcher;
	vector<vector<DMatch> > matchePoints;
	vector<DMatch> GoodMatchePoints;

	vector<Mat> train_desc(1, imageDesc1);
	matcher.add(train_desc);
	matcher.train();

	matcher.knnMatch(imageDesc2, matchePoints, 2);
	cout << "total match points: " << matchePoints.size() << endl;

	// Lowe's algorithm,获取优秀匹配点
	for (int i = 0; i < matchePoints.size(); i++)
	{
		if (matchePoints[i][0].distance < 0.39 * matchePoints[i][1].distance)
		{
			GoodMatchePoints.push_back(matchePoints[i][0]);
		}
	}

	Mat first_match;
	drawMatches(image02, keyPoint2, image01, keyPoint1, GoodMatchePoints, first_match);
	imshow("first_match ", first_match);
	waitKey();
}

通过SURF进行特征点提取并进行特征匹配

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值