相信很多小伙伴在使用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