SLAM十四讲 ch7 demo 复写

识别特征点并实现匹配

博主刚刚入门SLAM,之后可能会更多分享SLAM相关的学习总结。

刚刚学习1个多星期的SLAM,感觉自己的知识基础、论文阅读能力严重不足。幸好有高翔的《视觉SLAM十四讲》,由此书入门,觉得更容易了一些。之后应该会把全书通读一遍,而后找时间进行笔记整理和分享,也便于自己以后的复习。

我是看过1,2讲后直接入手第7讲,由于有需求的督促想尽快达到应用级别的了解,后续再补上数学基础。

纸上得来终觉浅,深知此事要躬行。读懂ch7的代码后,博主重写了一遍以加深印象,也加了一些备注以共查看。

 

#include 
#include 
#include 
#include 

using namespace std;
using namespace cv;

int main ( int argc, char** argv )
{
    if ( argc != 3 )
    {
        cout<<"usage: feature_extraction img1 img2"< keypoints_1, Keypoints_2;
    
    //(2)Save descriptors (BRIEF)
    Mat descriptors_1, descriptors_2;
    
    //(3)Save results of matching
    std::vector matches;
    
    //(4)Create KeyPoint detector( a tool for geting keypoints)
    Ptr detector = ORB::create();
 
    //(5)Create descriptor extractor( a tool for geting descriptor)
    Ptr extractor = ORB::create();
    
    //(6)Create descriptor matcher( a tool for geting keypoint pairing in two pictures by descriptor) 
    Ptr matcher = DescriptorMatcher::create( "BruteForce-Hamming" );
    
    
    //3.Get key points
    detector->detect( img_1, keypoints_1 );
    detector->detect( img_2, Keypoints_2 );
    
    
    //4.Draw key points and disply the image
    Mat outimg_1;
    drawKeypoints( img_1, keypoints_1, outimg_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
    imshow( "ORB key points" , outimg_1 );
    
    
    //5.Get keypoints descriptions
    extractor->compute(img_1, keypoints_1, descriptors_1);
    extractor->compute(img_2, Keypoints_2, descriptors_2);
    
    
    //6.Get matches 
    matcher->match(descriptors_1, descriptors_2, matches);
    
    
    //7.Draw all matches and disply picture
    Mat img_match;
    drawMatches(img_1, keypoints_1, img_2, Keypoints_2, matches, img_match);
    imshow( "all matches" , img_match );
    
    
    //8.Remove inaccurate matches(optimization)
    
    //Get minimum and maximum distances
    double min_dist=100000.0, max_dist=0.0;
    for(int i=0; itemp_dist) min_dist = temp_dist;
	if(max_dist accurate_match;
    for(int i=0; i

 

你可能感兴趣的:(SLAM十四讲)