特征描述子与匹配

       图像特征描述子:即图像中每个像素位置的描述,通过此描述去匹配另一张图像是否含有相同特征。一般用来

大图找小图,具有旋转不变性和尺度不变性。

代码示例:

#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <iostream>

using namespace cv;
using namespace std;
using namespace cv::xfeatures2d;

int main(int argc, char** argv) 
{
	Mat img1 = imread("D:/cv400/data/box.png", IMREAD_GRAYSCALE);
	Mat img2 = imread("D:/cv400/data/box_in_scene.png", IMREAD_GRAYSCALE);
	if (img1.empty() || img2.empty())
	{
		cout << "Load image error..." << endl;
		return -1;
	}
	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);
	//暴力匹配
	BFMatcher matcher(NORM_L2);
	vector<DMatch> matches;
	matcher.match(descriptor_1, descriptor_2, matches);
	//画匹配点
	Mat matchesImg;
	drawMatches(img1, keypoints_1, img2, keypoints_2, matches, matchesImg);
	imshow("Descriptor Demo", matchesImg);

	waitKey(0);
	return 0;
}

运行截图:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值