SIFT配合暴力匹配进行关键点描述和提取

接上一篇图片匹配教程

和上次ORB对比一下

上次的效果
在这里插入图片描述

本次的效果
在这里插入图片描述

上次的效果
在这里插入图片描述

本次的效果
在这里插入图片描述

可以说比上次好的多得多

测试环境

win10
visual studio 2019
opencv-3.4.3
opencv_contrib-3.4.3
cmake 3.20.3

备注

sift是有专利的算法, cmake编译时需要勾选 OPENCV_ENABLE_NONFREE, 才能使用有专利的算法

opencv源码编译可参考该视频教程:
vs2019+opencv3.4.6+contrib3.4.6源码编译

测试源码

#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/features2d/features2d.hpp>
#include<opencv2/xfeatures2d/nonfree.hpp>
using namespace std;
using namespace cv;

int main()
{
	Mat trainImage = imread("D:/script/myGit/autojs-flann-feature-matching/图片素材/game001.png"), trainImage_gray;
	//imshow("trainImage", trainImage);
	cvtColor(trainImage, trainImage_gray, COLOR_BGR2GRAY);
	vector<KeyPoint>train_keyPoint;
	Mat trainDescription;

	//SiftFeatureDetector featureDetector;
	//featureDetector.detect(trainImage_gray, train_keyPoint);
	Ptr<xfeatures2d::SiftFeatureDetector> featureDetector = xfeatures2d::SiftFeatureDetector::create();
	featureDetector->detect(trainImage_gray, train_keyPoint);


	Ptr<xfeatures2d::SiftDescriptorExtractor> featureExtractor = xfeatures2d::SiftDescriptorExtractor::create();
	featureExtractor->compute(trainImage_gray, train_keyPoint, trainDescription);
	BFMatcher matcher;
	vector<Mat>train_desc_collection(1, trainDescription);
	matcher.add(train_desc_collection);
	matcher.train();


	Mat captureImage, captureImage_gray;
	captureImage = imread("D:/script/myGit/autojs-flann-feature-matching/图片素材/game001_女生头像.png");
	cvtColor(captureImage, captureImage_gray, COLOR_BGR2GRAY);
	vector<KeyPoint>test_keyPoint;
	Mat testDescriptor;
	featureDetector->detect(captureImage_gray, test_keyPoint);
	featureExtractor->compute(captureImage_gray, test_keyPoint, testDescriptor);

	vector<vector<DMatch>>matches;
	matcher.knnMatch(testDescriptor, matches, 2);

	vector<DMatch>goodMatches;
	for (unsigned int i = 0; i < matches.size(); i++)
	{
		if (matches[i][0].distance < 0.6 * matches[i][1].distance)
			goodMatches.push_back(matches[i][0]);
	}
	Mat dstImage;
	drawMatches(captureImage, test_keyPoint, trainImage, train_keyPoint, goodMatches, dstImage);
	imshow("dstImage", dstImage);

	cv::waitKey(0);
	return 0;
}

参考文章

源代码(《OpenCV3编程入门》综合示例:SIFT配合暴力匹配进行关键点描述和提取)

vs2019装opencv3.4.2cmake报错

Visual Studio 版本 与 MSVC 编译器 版本

opencv3 中的 SIFT 用法

Visual Studio 2019 重新生成 OpenCV 解决方案报 LNK2019 无法解析的外部符号 __imp__Py_NegativeRefcount、__imp_Py_RefTotal

win10下用 Visual Studio 2019 重新生成 OpenCV 解决方案报 LNK1104 无法打开文件 “python38_d.lib”

CMake编译OpenCV4.0时opencv_ffmpeg.dll等下载失败的解决思路总结

OpenCV – 3.4.3

OpenCV - Windows(win10)编译opencv + opencv_contrib

声明

部分内容来自网络
本教程仅用于学习, 禁止用于其他用途

bilibili

牙叔教程

微信公众号 牙叔教程

在这里插入图片描述

QQ群

747748653
在这里插入图片描述

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牙叔教程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值