您好,登錄后才能下訂單哦!
這篇文章主要介紹了opencv3/C++怎么實(shí)現(xiàn)FLANN特征匹配的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇opencv3/C++怎么實(shí)現(xiàn)FLANN特征匹配文章都會(huì)有所收獲,下面我們一起來看看吧。
使用函數(shù)detectAndCompute()檢測(cè)關(guān)鍵點(diǎn)并計(jì)算描述符
函數(shù)detectAndCompute()參數(shù)說明:
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()從查詢集中查找每個(gè)描述符的最佳匹配。
參數(shù)說明:
void match( InputArray queryDescriptors, //查詢描述符集 InputArray trainDescriptors, //訓(xùn)練描述符集合 CV_OUT std::vector<DMatch>& matches, //匹配 InputArray mask=noArray() //指定輸入查詢和描述符的列表矩陣之間的允許匹配的掩碼 ) 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; //從查詢集中查找每個(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類用于匹配關(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; }
關(guān)于“opencv3/C++怎么實(shí)現(xiàn)FLANN特征匹配”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“opencv3/C++怎么實(shí)現(xiàn)FLANN特征匹配”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。