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<iostream>
#include<vector>

#include<opencv2\core\core.hpp>
#include<opencv2\features2d\features2d.hpp>
#include<opencv2\highgui\highgui.hpp>

using namespace std;
using namespace cv;


int main()
{
    //读取图片
    Mat rgbd1 = imread("自己的图片Path");
    Mat rgbd2 = imread("自己的图片Path");
    //imshow("rgbd1", depth2);
    //waitKey(0);
    Ptr<ORB> orb = ORB::create();
    vector<KeyPoint> Keypoints1,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
    vector<DMatch> matches;
    Ptr<DescriptorMatcher> matcher =DescriptorMatcher::create("BruteForce");
    matcher->match(descriptors1, descriptors2, matches);
    cout << "find out total " << matches.size() << " matches" << endl;

    //可视化
    Mat ShowMatches;
    drawMatches(rgbd1,Keypoints1,rgbd2,Keypoints2,matches,ShowMatches);
    imshow("matches", ShowMatches);
    waitKey(0);


    return 0;
}

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

Ptr<ORB> orb = ORB::create();

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

Ptr<DescriptorMatcher> matcher =DescriptorMatcher::create("BruteForce");
static Ptr<ORB> cv::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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM