C++实现SIFT匹配

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

using namespace cv;
using namespace std;

//SIFT的方式

using namespace std;
using namespace cv;

int main3(int* argv, int** argc)
{

	Mat imgRight = imread("E:/sift_test.jpg"); //右图
	Mat imgLeft = imread("E:/sift_test2.jpg"); //左图

	int numfeature = 1000; //设置特征点个数
	Ptr<SIFT>Detector = SIFT::create(numfeature);//取1000个特征点
	//auto Detector = SIFT::create(); //自动生成特征点的个数

	vector<KeyPoint> kpCat, kpSmallCat;
	Mat descriptorCat, descriptorSmallCat;

	Detector->detectAndCompute(imgRight, Mat(), kpCat, descriptorCat);
	printf("检测到的左图所有的特征点个数:%d", kpCat.size()); //打印检测到的特征点个数
	Detector->detectAndCompute(imgLeft, Mat(), kpSmallCat, descriptorSmallCat);
	printf("检测到的右图所有的特征点个数:%d", kpCat.size()); //打印检测到的特征点个数
	Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);
	std::vector<DMatch> matchers;
	matcher->match(descriptorCat, descriptorSmallCat, matchers);

	Mat imgMatches;
	drawMatches(imgRight, kpCat, imgLeft, kpSmallCat, matchers, imgMatches); //将右图和左图的特征点匹配并画出。
	//drawMatches(imgRight, kpCat, imgLeft, kpSmallCat, matchers, imgMatches, Scalar(0, 255, 0));//将右图和左图的特征点匹配并指定用绿色线画出。
	//imshow("左图", imgRight);
	//imshow("右图", imgLeft);
	namedWindow("特征点匹配图", CV_WINDOW_NORMAL); //可任意改变窗口大小
	imshow("特征点匹配图", imgMatches);
	imwrite("./效果图/特征点匹配图.jpg", imgMatches);
	waitKey(0);
	return true;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值