這篇文章主要介紹了opencv3/C++怎么實現(xiàn)FLANN特征匹配的相關(guān)知識,內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇opencv3/C++怎么實現(xiàn)FLANN特征匹配文章都會有所收獲,下面我們一起來看看吧。
目前創(chuàng)新互聯(lián)已為上1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、網(wǎng)站運營、企業(yè)網(wǎng)站設(shè)計、湖口網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。使用函數(shù)detectAndCompute()檢測關(guān)鍵點并計算描述符
函數(shù)detectAndCompute()參數(shù)說明:
void detectAndCompute( InputArray image, //圖像 InputArray mask, //掩模 CV_OUT std::vector& keypoints,//輸出關(guān)鍵點的集合 OutputArray descriptors,//計算描述符(descriptors[i]是為keypoints[i]的計算描述符) bool useProvidedKeypoints=false //使用提供的關(guān)鍵點 );
match()從查詢集中查找每個描述符的很好匹配。
參數(shù)說明:
void match( InputArray queryDescriptors, //查詢描述符集 InputArray trainDescriptors, //訓(xùn)練描述符集合 CV_OUT std::vector& matches, //匹配 InputArray mask=noArray() //指定輸入查詢和描述符的列表矩陣之間的允許匹配的掩碼 ) const;
FLANN特征匹配示例:
#include#include using namespace cv; using namespace cv::xfeatures2d; //FLANN對高維數(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 detector = SURF::create(minHessian); std::vector keypoints1; std::vector keypoints2; Mat descriptor1, descriptor2; //檢測關(guān)鍵點并計算描述符 detector->detectAndCompute(src1, Mat(), keypoints1, descriptor1); detector->detectAndCompute(src2, Mat(), keypoints2, descriptor2); //基于Flann的描述符匹配器 FlannBasedMatcher matcher; std::vector matches; //從查詢集中查找每個描述符的很好匹配 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)鍵點描述符的 std::vector 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 (), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); imshow("output", matchesImg); waitKey(); return 0; }
關(guān)于“opencv3/C++怎么實現(xiàn)FLANN特征匹配”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“opencv3/C++怎么實現(xiàn)FLANN特征匹配”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。