基于ORB特征点匹配的对极几何约束实现(源码+讲解)

//前几篇博客说了双目校正回顾一下代码

stereoCalibrate(objectPoints, image_leftPoints,  image_rightPoints, intrinsic_left, distCoeffs_left, intrinsic_right, distCoeffs_right, s1, R_total, T_total, E, F);
		printf("Starting Rectification\n");
stereoRectify(intrinsic_left, distCoeffs_left, intrinsic_right, distCoeffs_right, s1, R_total, T_total, R_L, R_R, P1, P2, Q, CALIB_ZERO_DISPARITY, -1, s1, &validROIL, &validROIR);

在这里插入图片描述
在这里插入图片描述
//这种校正方式,实现通过物点像点内参以及畸变矩阵求得两个相机相对的R,T
//再将R,T拆分成左右相机的r,t

//参考SLAM十四讲的解法,思路是先求出ORB匹配点(我上一篇博客有源码),通过匹配点,焦距f,光轴与成像面的交点坐标求出E,SVD方法分解E求出两个相机相对的R,T

  //计算本质矩阵
        Point2d principal_point(3251,249.7);//相机光心 标定值
        double focal_lengh=521 ;//相机焦距
        Mat essential_matrix;
        essential_matrix=findEssentialMat(points1,points2,focal_lengh,principal_point);
        cout<<"essential_matrix is"<<endl<<essential_matrix<<endl;
         //从本质矩阵恢复旋转,平移
        recoverPose(essential_matrix,points1,points2,R,t,focal_lengh,principal_point);
        cout<<"R :"<<R<<endl;
        cout<<"t is"<<t<<endl;

//先求ORB匹配点

oid find_feature_matches(const Mat &img_1, const Mat &img_2,
                          std::vector<KeyPoint> &keypoints_1,
                          std::vector<KeyPoint> &keypoints_2,
                          std::vector<DMatch> &matches) {
   
  //-- 初始化
  Mat descriptors_1, descriptors_2;
  // used in OpenCV3
  //FeatureDetector是虚类,通过定义FeatureDetector对象使用多种特征检测方法  
  Ptr<FeatureDetector> detector = ORB::create();
  
  //DescriptorExtractor提取关键点的描述子基类
  Ptr<DescriptorExtractor> descriptor = ORB::create();

  //描述子匹配方式,此处是汉明距离
  Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming");
  
  //-- 第一步:检测 Oriented FAST 角点位置
  detector->detect(img_1, keypoints_1);
  detector->detect(img_2, keypoints_2);

  //-- 第二步:根据角点位置计算 BRIEF 描述子
  descriptor->compute(img_1, keypoints_1, descriptors_1);
  descriptor->compute(img_2, keypoints_2, descriptors_2);

  //-- 第三步:对两幅图像中的BRIEF描述子进行匹配,使用 Hamming 距离
  //match中存放匹配的描述子信息
  vector<DMatch> match;
  matcher->match(descriptors_1, descriptors_2
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值