图像特征点提取及匹配的几种方法总结——基于C++和OPENCV实现SIFT、SURF、ORB、FAST

前言

对于特征提取算法的理论学习以及代码实现有很多,本文主要对自己用到的部分进行总结。主要包括特征点的提取,以及图像匹配和融合。

  • 这里将特征提取单独拿出来,是为了想更清楚的学习如果实现特征提取,同时统计特征点的数量。
  • 另外总结基于SIFT、ORB的特征匹配的实现方式。
  • 针对误匹配对的情况,用RANSAC算法进行剔除。

SIFT特征点提取

  • 该部分我们可以选择在彩色图或者灰度图的基础上进行特征点提取。
  • 也可以选择具体特征点数目或者自动生成特征点个数
  • KeyPoint是SIFT算法里面的关键点,包含了各种特点:坐标、 特征点领域直径、特征点的方向、特征点的强度、特征点所在的图像金字塔的组、用于聚类的id
vector<KeyPoint>keypoints;
  • src图像中检测到的SIFT特征点存储到keypoints中。
 detector->detect(src, keypoints, Mat());

整体代码:

#include<opencv2/opencv.hpp>
#include<iostream>
#include<opencv2/xfeatures2d.hpp>
#include <opencv2/highgui/highgui_c.h>
#include<opencv2/xfeatures2d/nonfree.hpp>
#include<vector>

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

Mat src;
int main(int argc, char** argv)
{
   
	src = imread("./data2/101.png", IMREAD_GRAYSCALE); //加载灰度图像
	//src = imread("./data2/101.png"); //加载图像
	if (!src.data)
	{
   
		cout << "图片加载失败" << endl;
		return -1;
	}
	//namedWindow("加载的灰度图像", CV_WINDOW_NORMAL); //可任意改变窗口大小
	imshow("加载的灰度图像", src);
	int numfeature = 400;  //特征点数目
	Ptr<SIFT>detector = SIFT::create(numfeature);
	//auto detector = SIFT::create(); //自动生成特征点的个数
	vector<KeyPoint>keypoints;
	detector->detect(src, keypoints, Mat());
	printf("所有的特征点个数:%d", keypoints.size());
	Mat resultImg;
	drawKeypoints(src, keypoints, resultImg, Scalar::all(-1), DrawMatchesFlags::DEFAULT); //特征点颜色随机
	imshow("SIFT特征点提取", resultImg);
	imwrite("./效果图/SIFT特征点提取.jpg", resultImg);
	waitKey(0);
	return 0;

}

灰度图基础上
在这里插入图片描述

ORB特征点提取

#include<opencv2/opencv.hpp>
#include<iostream>
#include<opencv2/xfeatures2d.hpp>
#include <opencv2/highgui/highgui_c.h>
#include<opencv2/xfeatures2d/nonfree.hpp>
#include<vector>

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

Mat src;
int main(int argc, char** argv)
{
   
	src = imread("./data2/101.png", IMREAD_GRAYSCALE); //加载灰度图像
	//src = imread("./data2/101.png"); //加载图像
	if (!src.data)
	{
   
		cout << "图片加载失败" << endl;
		return -1;
	}
	namedWindow("加载的灰度图像", CV_WINDOW_NORMAL); //可任意改变窗口大小
	imshow("加载的灰度图像", src);
	int numfeature = 400;  //特征点数目
	Ptr<ORB>detector = ORB::create(numfeature);
	//auto detector = ORB::create(); //自动生成特征点的个数
	vector<KeyPoint>keypoints;
	detector->detect(src, keypoints, Mat());
	printf("所有的特征点个数:%d", keypoints.size());
	Mat resultImg;
	drawKeypoints(src, keypoints, resultImg, Scalar::all(-1), DrawMatchesFlags::DEFAULT); //特征点颜色随机
	imshow("特征点提取", resultImg);
	imwrite("./效果图/特征点提取.jpg", resultImg);
	waitKey(0);
	return 0;

}

在这里插入图片描述

FAST角点检测且阈值可调节

  • 阈值可自动调节,首先给予一个初值为40的阈值。在这里插入图片描述
  • 将特征点个数以及阈值打印出来。

#include<opencv2/opencv.hpp>
#include<iostream>
#include<opencv2/xfeatures2d.hpp>
#include <opencv2/highgui/highgui_c.h>
#include<opencv2/xfeatures2d/nonfree.hpp>
#include<vector>

//FAST角点检测
using namespace std;
using namespace cv;
int thre = 40;
Mat src;
void trackBar(int, void*);

int main(int argc, char** argv)
{
   
	//src = imread("./data2/88.jpg");
	src = imread("./data2/88.jpg", IMREAD_GRAYSCALE); //加载灰度图像
	if (src.empty())
	{
   
		printf("无图像加载 \n");
		return -1;
	}
	namedWindow("input", WINDOW_NORMAL);
	imshow("input", src);

	namedWindow("output", WINDOW_NORMAL);
	createTrackbar("threshould", "output", &thre, 255, trackBar);
	waitKey(0);
	return 0;
}

void trackBar(int, void*)
{
   
	std
  • 8
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Fighting_FPGA

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

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

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

打赏作者

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

抵扣说明:

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

余额充值