opencv_C++ Brisk ( Binary Robust Invariant Scalable Keypoints )特征检测与匹配

本文介绍了一种使用BRISK特征检测器进行图像特征匹配的方法,并通过代码示例展示了如何在两幅图像中找到并显示匹配的关键点。此外,还提供了一个筛选良好匹配点的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、代码示例
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
RNG rng(12345);
void drawKeypoints_test(const vector<KeyPoint>& keypoints, Mat& outImage)
{
	for (size_t i = 0; i < keypoints.size(); i++)
	{
		Point2f point = keypoints[i].pt;
		//printf("x = %f, y = %f\n", point.x, point.y);
		circle(outImage, Point(point.x, point.y), 2, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), FILLED, LINE_AA);
	}
}

void showPoints()
{
	Mat sceneImage = imread("curry_dlt.jpg");

	Ptr<Feature2D> detector = BRISK::create();
	vector<KeyPoint> keypoints;
	detector->detect(sceneImage, keypoints, Mat());

	Mat keypointImage = sceneImage.clone();
	//drawKeypoints_test(sceneImage, keypoints, keypointImage, Scalar::all(-1));
	drawKeypoints_test(keypoints, keypointImage);

	imshow("keypointImage", keypointImage);
}

void showMatches()
{ 
	Mat sceneImage = imread("curry_dlt.jpg");
	Mat objImage = imread("curry1.jpg");

	Ptr<Feature2D> detector = BRISK::create();
	vector<KeyPoint> keypoints_obj;
	vector<KeyPoint> keypoints_scene;
	Mat descriptor_obj, descriptor_scene;

	detector->detectAndCompute(objImage, Mat(), keypoints_obj, descriptor_obj);
	detector->detectAndCompute(sceneImage, Mat(), keypoints_scene, descriptor_scene);

	// matching
	BFMatcher matcher(NORM_L2);
	vector<DMatch> matches;
	matcher.match(descriptor_obj, descriptor_scene, matches);

	// draw matching
	Mat outImage;
	drawMatches(objImage, keypoints_obj, sceneImage, keypoints_scene, matches, outImage);
	imshow("outImage", outImage);
	
	// good matching
	vector<DMatch> goodMatches;
	double minDist = 0, maxDist = 0;
	for (size_t i = 0; i < matches.size(); i++)
	{
		double dist = matches[i].distance;
		if (dist < minDist)
			minDist = dist;
		if (dist > maxDist)
			maxDist = dist;
	}

	printf("maxDist = %f, minDist = %f\n", maxDist, minDist);
	
	for (size_t i = 0; i < matches.size(); i++)
	{
		double dist = matches[i].distance;
		if (dist < max(0.02, 3 * minDist))
			printf("i = %d\n", i);
			goodMatches.push_back( matches[i]);
	}

	Mat goodMatchesImage;
	drawMatches(objImage, keypoints_obj, sceneImage, keypoints_scene, goodMatches, goodMatchesImage);
	imshow("goodMatchesImage", goodMatchesImage);
}

int main()
{
	showMatches();


	waitKey(0);
	return 0;
}
二、结果展示

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值