opencv 中用orb算法提取,优化特征点步骤以及keypoints,Dmatches的数据结构,保存匹配好的关键点

         最近在研究orb slam,发现经常出现特征点跟丢情况,打算slam中VO中的特征提取方式用深度学习模型去尝试,首先需要提取出比较准确的特征点.废话不多说直接上代码:

            cv::Ptr<cv::ORB> orb=cv::ORB::create();
            std::vector<cv::KeyPoint>keypoints1,keypoints2;
            cv::Mat descriptors1,descriptors2;
            orb->detectAndCompute(img_left,cv::Mat(),keypoints1,descriptors1);
            orb->detectAndCompute(img_right,cv::Mat(),keypoints2,descriptors2);

            cv::Mat showKeypoints1,showKeypoints2;
            cv::drawKeypoints(img_left,keypoints1,showKeypoints1);
            cv::drawKeypoints(img_right,keypoints2,showKeypoints2);
            std::vector<cv::DMatch>matches;
            cv::Ptr<cv::DescriptorMatcher>matcher=cv::DescriptorMatcher::create("BruteForce-Hamming");
            matcher->match(descriptors1,descriptors2,matches);

            double min_dist=0,max_dist=0;
            for (int i = 0; i <descriptors1.rows ; ++i) {
                double dist=matches[i].distance;
                if(dist<min_dist)min_dist=dist;
                if(dist>max_dist)max_dist=dist;
            }
            std::vector<cv::DMatch>good_matches;
            for (int j = 0; j <descriptors1.rows ; ++j) {
                if(matches[j].distance <= std::max(2*min_dist,25.0)){
                    good_matches.push_back(matches[j]);
                }
            }
            cv::Mat showMatches;
            cv::drawMatches(img_left,keypoints1,img_right,keypoints2,good_matches,showMatches);
            cv::imshow("matches",showMatches);
            cv::waitKey();

步骤:

1:检测角点位置并计算描述子

2:对描述子进行匹配

3:遍历matches数组,找出距离的最大值和最小值;

4:根据最小距离对匹配点进行筛选

5:绘制匹配结果


6.打印出匹配点和保存图片已备后面训练用


  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值