opencv3/C++ FLANN特征匹配方式
使用函數(shù)detectAndCompute()檢測(cè)關(guān)鍵點(diǎn)并計(jì)算描述符
函數(shù)detectAndCompute()參數(shù)說(shuō)明:
void detectAndCompute( InputArray image, //圖像 InputArray mask, //掩模 CV_OUT std::vector<KeyPoint>& keypoints,//輸出關(guān)鍵點(diǎn)的集合 OutputArray descriptors,//計(jì)算描述符(descriptors[i]是為keypoints[i]的計(jì)算描述符) bool useProvidedKeypoints=false //使用提供的關(guān)鍵點(diǎn) );
match()從查詢(xún)集中查找每個(gè)描述符的最佳匹配。
參數(shù)說(shuō)明:
void match( InputArray queryDescriptors, //查詢(xún)描述符集 InputArray trainDescriptors, //訓(xùn)練描述符集合 CV_OUT std::vector<DMatch>& matches, //匹配 InputArray mask=noArray() //指定輸入查詢(xún)和描述符的列表矩陣之間的允許匹配的掩碼 ) const;
FLANN特征匹配示例:
#include<opencv2/opencv.hpp> #include<opencv2/xfeatures2d.hpp> using namespace cv; using namespace cv::xfeatures2d; //FLANN對(duì)高維數(shù)據(jù)較快 int main() { Mat src1,src2; src1 = imread("E:/image/image/card2.jpg"); src2 = imread("E:/image/image/cards.jpg"); if (src1.empty() || src2.empty()) { printf("can ont load images....\n"); return -1; } imshow("image1", src1); imshow("image2", src2); int minHessian = 400; //選擇SURF特征 Ptr<SURF>detector = SURF::create(minHessian); std::vector<KeyPoint>keypoints1; std::vector<KeyPoint>keypoints2; Mat descriptor1, descriptor2; //檢測(cè)關(guān)鍵點(diǎn)并計(jì)算描述符 detector->detectAndCompute(src1, Mat(), keypoints1, descriptor1); detector->detectAndCompute(src2, Mat(), keypoints2, descriptor2); //基于Flann的描述符匹配器 FlannBasedMatcher matcher; std::vector<DMatch>matches; //從查詢(xún)集中查找每個(gè)描述符的最佳匹配 matcher.match(descriptor1, descriptor2, matches); double minDist = 1000; double maxDist = 0; for (int i = 0; i < descriptor1.rows; i++) { double dist = matches[i].distance; printf("%f \n", dist); if (dist > maxDist) { maxDist = dist; } if (dist < minDist) { minDist = dist; } } //DMatch類(lèi)用于匹配關(guān)鍵點(diǎn)描述符的 std::vector<DMatch>goodMatches; for (int i = 0; i < descriptor1.rows; i++) { double dist = matches[i].distance; if (dist < max(2.5*minDist, 0.02)) { goodMatches.push_back(matches[i]); } } Mat matchesImg; drawMatches(src1, keypoints1, src2, keypoints2, goodMatches, matchesImg, Scalar::all(-1), Scalar::all(-1), std::vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); imshow("output", matchesImg); waitKey(); return 0; }
以上這篇opencv3/C++ FLANN特征匹配方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
在Visual Studio中用C++語(yǔ)言創(chuàng)建DLL動(dòng)態(tài)鏈接庫(kù)圖文教程
這篇文章主要介紹了在Visual Studio中用C++語(yǔ)言創(chuàng)建DLL動(dòng)態(tài)鏈接庫(kù)圖文教程,本文詳細(xì)講解了DLL庫(kù)的創(chuàng)建過(guò)程,并給出了代碼示例,需要的朋友可以參考下2014-09-09c語(yǔ)言中abs()和fabs()的區(qū)別點(diǎn)整理
在本篇文章里小編給大家分享的是關(guān)于c語(yǔ)言abs()和fabs()的區(qū)別,有需要的朋友們可以參考學(xué)習(xí)下。2020-02-02初識(shí)C++的const關(guān)鍵字,常量與常變量
這篇文章主要為大家詳細(xì)介紹了C++的const關(guān)鍵字,常量與常變量,使用數(shù)據(jù)庫(kù),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-03-03C/C++?QT實(shí)現(xiàn)自定義對(duì)話(huà)框的示例代碼
對(duì)話(huà)框分為多種,常見(jiàn)的有通用對(duì)話(huà)框,自定義對(duì)話(huà)框,模態(tài)對(duì)話(huà)框,非模態(tài)對(duì)話(huà)框等,本文主要介紹了QT自定義對(duì)話(huà)框,感興趣的可以了解一下2021-11-11C數(shù)據(jù)結(jié)構(gòu)之雙鏈表詳細(xì)示例分析
以下是對(duì)c語(yǔ)言中的雙鏈表進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下2013-08-08