opencv3.4.5实现GMS+ORB特征匹配

环境:opencv3.4.5+opencv_contrib,vs2015;

GMS链接:

GMS: Grid-based Motion Statistics for Fast, Ultra-robust Feature Correspondence CVPR2017

 c++ code: https://github.com/JiawangBian/GMS-Feature-Matcher

代码:

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/flann.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/xfeatures2d.hpp>


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


int main() 
{
	Mat img_1 = imread("01.jpg");
	Mat img_2 = imread("02.jpg");
	//Ptr<Feature2D> sift = xfeatures2d::SIFT::create();
	//Ptr<Feature2D> surf = xfeatures2d::SURF::create();
	Ptr<ORB> orb = ORB::create(5000);
	orb->setFastThreshold(0);

	vector<KeyPoint> keypoints_1, keypoints_2;
	Mat descriptors_1,descriptors_2;

	//sift->detect(img_1, keypoints_1);
	//sift->compute(img_1, keypoints_1, descriptors);

	orb->detectAndCompute(img_1, Mat(),keypoints_1, descriptors_1);
	orb->detectAndCompute(img_2, Mat(), keypoints_2, descriptors_2);

	//orb ->detect(img_1, keypoints_1);
	//orb ->compute(img_1, keypoints_1, descriptors_1);

	//orb->detect(img_2, keypoints_2);
	//orb->compute(img_2, keypoints_2, descriptors_2);

	Mat ShowKeypoints1, ShowKeypoints2;
	drawKeypoints(img_1, keypoints_1, ShowKeypoints1);
	drawKeypoints(img_2, keypoints_2, ShowKeypoints2);
	imshow("Result_1", ShowKeypoints1);
	imshow("Result_2", ShowKeypoints2);

    vector<DMatch> matchesAll, matchesGMS;
	BFMatcher matcher(NORM_HAMMING);
	
	matcher.match(descriptors_1, descriptors_2, matchesAll);
	cout << "matchesAll: " << matchesAll.size() << endl;
	matchGMS(img_1.size(), img_2.size(), keypoints_1, keypoints_2, matchesAll, matchesGMS);
	std::cout << "matchesGMS: " << matchesGMS.size() << std::endl;

	Mat finalMatches;
	drawMatches(img_1, keypoints_1, img_2, keypoints_2, matchesGMS, finalMatches, Scalar::all(-1), Scalar::all(-1),
		std::vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
	imshow("Matches GMS", finalMatches);
	imwrite("MatchesGMS.jpg", finalMatches);
	waitKey(0);

	return 0;
}

匹配结果:

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值