OPENCV中特征提取和匹配的步驟


1.定義特征提取器和描述子提取器:

cv::Ptr<cv::FeatureDetector> detector; cv::Ptr<cv::DescriptorExtractor> descriptor;

2.設置提取器的類型(ORB\SIFT\SURF)

detector=cv::FeatureDetector::create("ORB"); // 如果使用 sift, surf ,之前要初始化nonfree模塊 // cv::initModule_nonfree(); // _detector = cv::FeatureDetector::create( "SIFT" ); // _descriptor = cv::DescriptorExtractor::create( "SIFT" ); descriptor = cv::DescriptorExtractor::create("ORB");

3.提取關鍵點

vector<cv::KeyPoint> kp1,kp2;//關鍵點
detector->detect(rgb1,kp1);//提取關鍵點
detector->detect(rgb2,kp2);//提取關鍵點

4.計算描述子

cv::Mat desp1, desp2; descriptor->compute( rgb1, kp1, desp1 ); descriptor->compute( rgb2, kp2, desp2 );

5.匹配描述子

vector< cv::DMatch > matches; cv::BFMatcher matcher; matcher.match( desp1, desp2, matches );

6.篩選匹配的特征點(去掉大於最小距離的二倍的匹配點)

// 篩選匹配,把距離太大的去掉 // 這里使用的准則是去掉大於2倍最小距離的匹配
    vector< cv::DMatch > goodMatches; double minDis = 9999; for ( size_t i=0; i<matches.size(); i++ ) { if ( matches[i].distance < minDis ) minDis = matches[i].distance; }for ( size_t i=0; i<matches.size(); i++ ) { if (matches[i].distance < 2*minDis) goodMatches.push_back( matches[i] ); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM