java opencv orb_Opencv3中ORB算法的使用

相信很多小伙伴在使用ORB算法的时候,一般会从网上搜一些代码作为参考,那么问题来了:在好多ORB程序中都会这么写:

ORB orb;

如果你使用的是Opencv3的版本,编译器就会报错:ORB是一个纯虚类,无法进行实例化。但在opencv2的版本中可以正常使用。这是为什么呢?

于是乎就在opencv3官方的Documents中寻找答案,ORB属于features2d模块中。在它的文档中终于发现了原因

Public Member Functions:virtual int getEdgeThreshold () const =0

virtual int getFastThreshold () const =0

virtual int getFirstLevel () const =0

virtual int getMaxFeatures () const =0

virtual int getNLevels () const =0

virtual int getPatchSize () const =0

virtual double getScaleFactor () const =0

virtual int getScoreType () const =0

virtual int getWTA_K () const =0

virtual void setEdgeThreshold (int edgeThreshold)=0

virtual void setFastThreshold (int fastThreshold)=0

virtual void setFirstLevel (int firstLevel)=0

virtual void setMaxFeatures (int maxFeatures)=0

virtual void setNLevels (int nlevels)=0

virtual void setPatchSize (int patchSize)=0

virtual void setScaleFactor (double scaleFactor)=0

virtual void setScoreType (int scoreType)=0

virtual void setWTA_K (int wta_k)=0

Static Public Member Functions:static Ptr< ORB > create (int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31, int firstLevel=0, int WTA_K=2, int scoreType=ORB::HARRI

S_SCORE, int patchSize=31, int fastThreshold=20)

#include#include#include#include#include

using namespacestd;using namespacecv;intmain()

{//读取图片

Mat rgbd1 = imread("自己的图片Path");

Mat rgbd2= imread("自己的图片Path");//imshow("rgbd1", depth2);//waitKey(0);

Ptr orb =ORB::create();

vectorKeypoints1,Keypoints2;

Mat descriptors1,descriptors2;

orb->detectAndCompute(rgbd1, Mat(), Keypoints1, descriptors1);

orb->detectAndCompute(rgbd2, Mat(), Keypoints2, descriptors2);//cout << "Key points of image" << Keypoints.size() << endl;//可视化,显示关键点

Mat ShowKeypoints1, ShowKeypoints2;

drawKeypoints(rgbd1,Keypoints1,ShowKeypoints1);

drawKeypoints(rgbd2, Keypoints2, ShowKeypoints2);

imshow("Keypoints1", ShowKeypoints1);

imshow("Keypoints2", ShowKeypoints2);

waitKey(0);//Matching

vectormatches;

Ptr matcher =DescriptorMatcher::create("BruteForce");

matcher->match(descriptors1, descriptors2, matches);

cout<< "find out total" << matches.size() << "matches" <

Mat ShowMatches;

drawMatches(rgbd1,Keypoints1,rgbd2,Keypoints2,matches,ShowMatches);

imshow("matches", ShowMatches);

waitKey(0);return 0;

}

这是一个对两幅图片进行ORB提取特征,并进行Match的程序。可以看到对于orb的使用程序变成了

Ptr orb = ORB::create();

细心的读者应该已经发现Match类也变成了一个纯虚类使用方法与ORB类似:

Ptr matcher =DescriptorMatcher::create("BruteForce");

static Ptrcv::ORB::create (int nfeatures = 500,float scaleFactor = 1.2f,int nlevels = 8,int edgeThreshold = 31,int firstLevel = 0,int WTA_K = 2,int scoreType =ORB::HARRIS_SCORE,int patchSize = 31,int fastThreshold = 20)

下面是关于具体参数的解释有点多,就附上网址吧:

http://docs.opencv.org/3.2.0/db/d95/classcv_1_1ORB.html#adc371099dc902a9674bd98936e79739c

点赞 12

————————————————

版权声明:本文为CSDN博主「bingoplus」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/bingoplus/article/details/60133565

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ORB_create是OpenCV的一个函数,用于创建一个ORB(Oriented FAST and Rotated BRIEF)特征检测器和描述子提取器的实例。ORB是一种基于FAST角点检测器和BRIEF描述子的特征提取算法,常用于计算机视觉的特征匹配、目标检测和SLAM(Simultaneous Localization and Mapping)等任务。 使用ORB_create函数可以创建一个ORB对象,然后可以使用该对象来检测图像的特征点,并提取这些特征点的描述子。ORB_create函数接受一些参数,例如指定特征点数目、金字塔层数、FAST角点检测器的阈值等,以便根据具体应用场景进行设置。 示例代码如下: ```python import cv2 # 创建ORB对象 orb = cv2.ORB_create() # 读取图像 image = cv2.imread('image.jpg') # 转换为灰度图像 gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # 检测特征点并提取描述子 keypoints, descriptors = orb.detectAndCompute(gray, None) # 绘制特征点 output_img = cv2.drawKeypoints(image, keypoints, None, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) # 显示结果 cv2.imshow('ORB keypoints', output_img) cv2.waitKey(0) cv2.destroyAllWindows() ``` 上述代码,我们首先创建了一个ORB对象,然后读取图像并转换为灰度图像。接下来,使用ORB对象的detectAndCompute函数检测特征点,并提取这些特征点的描述子。最后,我们使用drawKeypoints函数绘制特征点,并显示结果图像。 注意:以上代码仅为示例,实际应用可能需要根据具体需求进行参数调整和异常处理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值