OpenCV ORB特征检测(22)
  Jk5625xsZPHl 2023年11月02日 40 0

ORB在2011年才首次发布,ORB算法将基于FAST关键点的技术和基于BRIEF描述符的技术相结合,但是ORB并没有解决尺度不一致的问题,在OpenCV的ORB实现中采用了图像金字塔来改善这方面的性能,我们通过构建高斯金字塔,然后在每一层金字塔图像上检测角点,来实现尺度不变性。ORB主要解决了BRIEF描述子不具备旋转不变性的问题。 BRIEF是一种特征描述子提取算法,并非特征点的提取算法,一种生成二值化描述子的算法,不提取代价低,匹配只需要使用简单的汉明距离(Hamming Distance)利用比特之间的异或操作就可以完成。因此,时间代价低,空间代价低,效果还挺好是最大的优点。

ORB算法大致流程

  • 建立图像金字塔
  • FAST算法寻找特征点
  • 给关键点分配方向
  • 通过BRIEF算法创建特征向量,得到特征描述符

API介绍

static Ptr<ORB> create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31,int firstLevel=0, int WTA_K=2, ORB::ScoreType scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20);
/*******************************************************************
*			nfeatures: 					保留的最佳特性的数量				
*			scaleFactor:	    		金字塔抽取率,必须大于1
*			nlevels:					金字塔等级的数量
*			edgeThreshold:  			边缘阈值
*			firstLevel:					第一层的索引值	
*			WTA_K:	    				用于生成定向的BRIEF描述符的每个元素的随机像素的数量
*					2:一次选择两个随机像素比较,匹配的时候距离参数选择NORM_HAMMING,默认方式
*					3:一次选择三个随机像素来比较它们的亮度,返回最亮像素的索引,返回回的索引将为0,1或2
*					4:一次选择四个随机像素来比较它们的亮度,返回最亮像素的索引,回的索引将为0,1,2或3
*			scoreType:					对特征点进行排序的算法
*						HARRIS_SCORE:Harris角算法用于对要素进行排名。该分数仅用于保留最佳功能
*						FAST_SCORE:	速度快,关键点稍差
*			patchSize:  				用于计算BIREF描述子的特征点邻域大小
*			fastThreshold:				fast特征阈值
*********************************************************************/
virtual void detect( InputArray image,std::vector<KeyPoint>& keypoints,InputArray mask=noArray());
/*******************************************************************
*			image: 				输入图				
*			keypoints:	        角点信息
*			mask:				计算亚像素角点区域大小			
*********************************************************************/
void drawKeypoints( InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray outImage,const Scalar& color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT );
/*******************************************************************
*			image: 				输入图				
*			keypoints:	        角点信息
*			outImage:			计算亚像素角点区域大小
*			color:  			颜色
*			flags:				绘制匹配标记			
*********************************************************************/

综合代码

#include <iostream>
#include <map>
#include <new>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
class ORBFeature
{
public:
	ORBFeature() :img(imread("mm.jpg"))
	{
		result["img"] = img;
	}
	void TestORB()
	{
		Ptr<ORB> orb = ORB::create();
		orb->detect(img, point);
		drawKeypoints(img, point, result["orb"], Scalar(255, 0, 255));
	}
	void Show()
	{
		for (auto& v : result)
		{
			imshow(v.first, v.second);
		}
		waitKey(0);
	}
protected:
	Mat img;
	vector<KeyPoint> point;
	map<string, Mat> result;
};

int  main()
{
	unique_ptr<ORBFeature> p(new ORBFeature);
	p->TestORB();
	p->Show();
	return 0;
}

OpenCV ORB特征检测(22)_#include

OpenCV SER特征检测

MSER是极值区域检测算法,MSER类根据输入参数判断是否为彩色or灰度图像进行不同的算法检测。若输入为灰度图像,那么采取MSER极值区域检测算法,若输入为彩色图像,则采用MSCR极值区域检测算法,可以用于图像的斑点区域检测。业界认为是性能最好的仿射不变区域,MSER是当使用不同的灰度阈值对图像进行二值化时得到的最稳定的区域,特点:

  • 对于图像灰度的仿射变化具有不变性
  • 稳定性,区域的支持集相对灰度变化稳定
  • 可以检测不同精细程度的区域

MSER算法大致流程

  • 使用一系列灰度阈值对图像进行二值化处理
  • 对于每个阈值得到的二值图像,得到相应的黑色区域与白色区域
  • 在比较宽的灰度阈值范围内保持形状稳定的区域就是MSER特征
  • 评判标准: dA/dtA: 二值图像区域面积,t: 灰度

API介绍

static Ptr<MSER> create( int delta=5, int min_area=60, int max_area=14400,double max_variation=0.25, double min_diversity=.2,int max_evolution=200, double area_threshold=1.01,double min_margin=0.003, int edge_blur_size=5 );
/*******************************************************************
*			delta: 						两个区域间的灰度差			
*			min_area:	    			剔除小于此值的区域
*			max_area:					剔除大于此值的区域
*			max_variation:				剔除灰度值变化时,区域变化为此倍数的区域
*			min_diversity:  			当前区域与稳定区域的变化率
*			max_evolution:				位置变化步长
*			area_threshold: 			重新初始化的面积阈值
*			min_margin: 				最小边缘尺寸
*			edge_blur_size: 			边缘滤波的孔径尺寸	
*********************************************************************/
virtual void detect( InputArray image,std::vector<KeyPoint>& keypoints,InputArray mask=noArray());
/*******************************************************************
*			image: 				输入图				
*			keypoints:	        角点信息
*			mask:				计算亚像素角点区域大小			
*********************************************************************/
void drawKeypoints( InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray outImage,const Scalar& color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT );
/*******************************************************************
*			image: 				输入图				
*			keypoints:	        角点信息
*			outImage:			计算亚像素角点区域大小
*			color:  			颜色
*			flags:				绘制匹配标记				
*********************************************************************/

综合代码

#include <iostream>
#include <map>
#include <new>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
class MSERFeature
{
public:
	MSERFeature() :img(imread("mm.jpg"))
	{
		result["img"] = img;
	}
	void TestMSER()
	{
		Ptr<ORB> mser = ORB::create();
		mser->detect(img, point);
		drawKeypoints(img, point, result["mser"], Scalar(255, 0, 255));
	}
	void Show()
	{
		for (auto& v : result)
		{
			imshow(v.first, v.second);
		}
		waitKey(0);
	}
protected:
	Mat img;
	vector<KeyPoint> point;
	map<string, Mat> result;
};

int  main()
{
	unique_ptr<MSERFeature> p(new MSERFeature);
	p->TestMSER();
	p->Show();
	return 0;
}

OpenCV ORB特征检测(22)_#include_02

OpenCV SimpleBlob特征检测

SimpleBlob是检测斑点类的特征点,斑点本质其实是一组连通的像素在图像中共享一些共同的属性(如灰度值、颜色等)

SimpleBlob检测大致流程

  • 图像分割(例如阈值化操作)
  • 连通性分析
  • 特征量计算

API介绍

static Ptr<SimpleBlobDetector>create(const SimpleBlobDetector::Params ¶meters = SimpleBlobDetector::Params());
/*******************************************************************
*			parameters: Params结构体		
* 		SimpleBlobDetector::Params params;
* 		阈值控制
* 		params.minThreshold = 10;
* 		params.maxThreshold = 200;
*		像素面积大小控制
* 		params.filterByArea = true;
* 		params.minArea = 1000;
* 		形状(凸)
* 		params.filterByCircularity = false;
* 		params.minCircularity = 0.7;
* 		形状(凹)
* 		params.filterByConvexity = true;
* 		params.minConvexity = 0.9;
* 		形状(圆)
*		params.filterByInertia = false;
* 		params.minInertiaRatio = 0.5;
*********************************************************************/
virtual void detect( InputArray image,std::vector<KeyPoint>& keypoints,InputArray mask=noArray());
/*******************************************************************
*			image: 				输入图				
*			keypoints:	        角点信息
*			mask:				计算亚像素角点区域大小			
*********************************************************************/
void drawKeypoints( InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray outImage,const Scalar& color=Scalar::all(-1), DrawMatchesFlags flags=DrawMatchesFlags::DEFAULT );
/*******************************************************************
*			image: 				输入图				
*			keypoints:	        角点信息
*			outImage:			计算亚像素角点区域大小
*			color:  			颜色
*			flags:				绘制匹配标记				
*********************************************************************/

综合代码

#include <iostream>
#include <map>
#include <new>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
class BLOBFeature
{
public:
	BLOBFeature() :img(imread("mm.jpg"))
	{
		result["img"] = img;
	}
	void TestBLOB()
	{
		SimpleBlobDetector::Params params;
		params.minThreshold = 1;
		params.maxThreshold = 200;
		params.filterByArea = true;
		params.minArea = 10;
		params.filterByCircularity = true;
		params.minCircularity = 0.7;
		params.filterByConvexity = true;
		params.minConvexity = 0.9;
		 params.filterByInertia = true;
		params.minInertiaRatio = 0.5;
		Ptr<SimpleBlobDetector> blob = SimpleBlobDetector::create(params);
		blob->detect(img, point);
		drawKeypoints(img, point, result["blob"], Scalar(255, 0, 255));
	}
	void Show()
	{
		for (auto& v : result)
		{
			imshow(v.first, v.second);
		}
		waitKey(0);
	}
protected:
	Mat img;
	vector<KeyPoint> point;
	map<string, Mat> result;
};
int  main()
{
	unique_ptr<BLOBFeature> p(new BLOBFeature);
	p->TestBLOB();
	p->Show();
	return 0;
}

OpenCV ORB特征检测(22)_#include_03

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  gBkHYLY8jvYd   2023年12月06日   48   0   0 #includecii++
  gBkHYLY8jvYd   2023年11月19日   27   0   0 #includecic++
  gBkHYLY8jvYd   2023年11月19日   14   0   0 #includeios数据
  gBkHYLY8jvYd   2023年11月19日   23   0   0 #include子树结点
  gBkHYLY8jvYd   2023年11月19日   22   0   0 #includei++数据
  gBkHYLY8jvYd   2023年11月19日   23   0   0 #include数组ci
  gBkHYLY8jvYd   2023年12月10日   17   0   0 #include邻域灰度图像
  gBkHYLY8jvYd   2023年12月10日   22   0   0 #include数组i++
  gBkHYLY8jvYd   2023年12月06日   19   0   0 #includeios数据
  gBkHYLY8jvYd   2023年12月08日   20   0   0 #includecii++
  gBkHYLY8jvYd   2023年11月19日   19   0   0 #includeiosci
  gBkHYLY8jvYd   2023年11月22日   21   0   0 #include十进制高精度
  gBkHYLY8jvYd   2023年11月22日   25   0   0 #includeiosci
Jk5625xsZPHl