opencv下检测+匹配

1、特征点检测

角点:

传统harris角点检测//有时间加上

改进harris角点检测

不知道opencv下为什么那么慢,matlab下harris检测挺快的

        //以下两句不重复
        vector<KeyPoint> keypoints_1, keypoints_2;
	    Mat descriptors_1, descriptors_2;
	    //
		GoodFeaturesToTrackDetector Detector(200);  //最大点数,值越大,点越多
		//角点最大数目;// 质量等级,这里是0.01*max(min(e1,e2)),e1,e2是harris矩阵的特征值;// 两个角点之间的距离容忍度;
		Detector.detect(image, keypoints_1);
		Detector.detect(image2, keypoints_2);

Fast快速检测

fast很快,角点特征还算可以

		FastFeatureDetector fast(100, true);
		fast.detect(image, keypoints_1);
		fast.detect(image2, keypoints_2);
		std::cout << "keypint_size" << keypoints_1.size() << " " << keypoints_2.size() << endl;

surf检测特征点并提取特征值

		SurfFeatureDetector surf(5000);
		surf.detect(image, keypoints_1);
		surf.detect(image2, keypoints_2);

2、计算描述子

sift、surf、brief等等,这里以sift为例,可以随意使用,但感觉sift效果较好

		SiftDescriptorExtractor extractor;
		extractor.compute(image, keypoints_1, descriptors_1);
		extractor.compute(image2, keypoints_2, descriptors_2);

orb算法=fast 检测+ BriefDescriptorExtractor 描述

	ORB orb;
	orb(image, Mat(), keypoints_1, descriptors_1);
	orb(image2, Mat(), keypoints_2, descriptors_2);

3、匹配 bf matcher

		//A-KNN
		BruteForceMatcher <L2<float>> matcher;
		std::vector< DMatch > matches;
		const float minRatio = 1.f / 1.5f;
		const int k = 2;
		vector<vector<DMatch>> knnMatches;
		matcher.knnMatch(descriptors_1, descriptors_2, knnMatches, k);

		for (size_t i = 0; i < knnMatches.size(); i++) {
			const DMatch& bestMatch = knnMatches[i][0];
			const DMatch& betterMatch = knnMatches[i][1];

			float  distanceRatio = bestMatch.distance / betterMatch.distance;
			if (distanceRatio < minRatio)
				matches.push_back(bestMatch);
		}
		std::cout << "match_size" << matches.size() << endl;

4、显示

        //-- Show detected matches
        Mat img_matches;//把图像点转换到该mat
		drawMatches(image, keypoints_1, image2, keypoints_2, matches, img_matches);
		imshow("Matches", img_matches);

推荐文章
https://blog.csdn.net/Jack_Sarah/article/details/79548334
https://blog.csdn.net/medal003/article/details/45022331
https://blog.csdn.net/holybin/article/details/48776949

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值