【视觉 SLAM】OpenCV 3 特征点匹配

本文为特征点匹配学习总结,讲解 OpenCV 3 中的特征点匹配。
摘要由CSDN通过智能技术生成

本文为特征点匹配学习总结,讲解 OpenCV 3 中的特征点匹配。

特征点匹配

OpenCV 中封装了常用的特征点算法(如 SIFT,SURF,ORB等),提供了统一的接口便于调用。 下面代码是 OpenCV 中使用其 feature 2D 模块的示例代码:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

int main ( int argc, char** argv )
{
   
    if ( argc != 3 )
    {
   
        cout<<"usage: feature_extraction img1 img2"<<endl;
        return 1;
    }
    // 读取图像
    Mat img1 = imread ( argv[1], CV_LOAD_IMAGE_COLOR );
    Mat img2 = imread ( argv[2], CV_LOAD_IMAGE_COLOR );

    // 初始化
    std::vector<KeyPoint> keypoints1, keypoints2;
    Mat descriptors1, descriptors2;
    Ptr<ORB> orb = ORB::create();
    
    // 提取特征点
    orb->detect(img1, keypoints1);
    orb->detect(img2, keypoints2);
    
    // 绘制特征点
    Mat outimg1;
    drawKeypoints(img1, keypoints1, outimg1, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
    imshow("ORB特征点", outimg1);

    // 计算 BRIEF 描述子
    orb->compute ( img1, keypoints1, descriptors1 );
    orb->compute ( img2, keypoints2, descriptors2 );    

    // 对两幅图像中的描述子进行匹配,使用 Hamming 距离
    vector<DMatch> matches;
    BFMatcher bfMatcher ( NORM_HAMMING );
    bfMatcher.match ( descriptors1, descriptors2, matches );
    
    Mat img_match;
    drawMatches(img1, keypoints1, img2, keypoints2, matches, img_match);
    imshow("所有匹配点对", img_match
  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值