《视觉SLAM十四讲》第十讲g2o求解BA问题报错解决办法

博客介绍了在使用g2o库进行SLAM研究时遇到的编译错误,原因是新旧版本的不兼容。作者提供了解决方案,通过更新代码以适配新版本g2o,包括修改创建优化算法和线性求解器的方式,以避免类型转换错误。此外,还展示了如何根据参数设置优化器和线性求解器。

一、问题描述

编译报错如下:

/home/xxx/slambook/ch10/g2o_custombundle/g2o_bundle.cpp: In function ‘void SetMinimizerOptions(std::shared_ptr<g2o::BlockSolver<g2o::BlockSolverTraits<9, 3> > >&, const BundleParams&, g2o::SparseOptimizer*):
/home/xxx/slambook/ch10/g2o_custombundle/g2o_bundle.cpp:136:74: error: no matching function for call to ‘g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(g2o::BlockSolver<g2o::BlockSolverTraits<9, 3> >*)’
         solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr.get());
                                                                          ^
In file included from /home/xxx/slambook/ch10/g2o_custombundle/g2o_bundle.cpp:18:0:
/usr/local/include/g2o/core/optimization_algorithm_levenberg.h:47:16: note: candidate: g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(std::unique_ptr<g2o::Solver>)
       explicit OptimizationAlgorithmLevenberg(std::unique_ptr<Solver> solver);
                ^
/usr/local/include/g2o/core/optimization_algorithm_levenberg.h:47:16: note:   no known conversion for argument 1 from ‘g2o::BlockSolver<g2o::BlockSolverTraits<9, 3> >*’ to ‘std::unique_ptr<g2o::Solver>/home/xxx/slambook/ch10/g2o_custombundle/g2o_bundle.cpp:139:71: error: no matching function for call to ‘g2o::OptimizationAlgorithmDogleg::OptimizationAlgorithmDogleg(g2o::BlockSolver<g2o::BlockSolverTraits<9, 3> >*)’
         solver = new g2o::OptimizationAlgorithmDogleg(solver_ptr.get());
                                                                       ^
In file included from /home/xxx/slambook/ch10/g2o_custombundle/g2o_bundle.cpp:19:0:
/usr/local/include/g2o/core/optimization_algorithm_dogleg.h:56:16: note: candidate: g2o::OptimizationAlgorithmDogleg::OptimizationAlgorithmDogleg(std::unique_ptr<g2o::BlockSolverBase>)
       explicit OptimizationAlgorithmDogleg(std::unique_ptr<BlockSolverBase> sol
                ^
/usr/local/include/g2o/core/optimization_algorithm_dogleg.h:56:16: note:   no known conversion for argument 1 from ‘g2o::BlockSolver<g2o::BlockSolverTraits<9, 3> >*’ to ‘std::unique_ptr<g2o::BlockSolverBase>/home/xxx/slambook/ch10/g2o_custombundle/g2o_bundle.cpp: In function ‘void SetSolverOptionsFromFlags(BALProblem*, const BundleParams&, g2o::SparseOptimizer*):
/home/xxx/slambook/ch10/g2o_custombundle/g2o_bundle.cpp:186:49: error: no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<9, 3> >::BlockSolver(g2o::LinearSolver<Eigen::Matrix<double, 9, 9, 0, 9, 9> >*&)’
     solver_ptr = new BalBlockSolver(linearSolver
<think>嗯,用户想学习高翔的《视觉SLAM十四》,需要学习方法推荐。这本书是SLAM领域的经典教材,理论性和实践性都很强,对数学和编程要求较高。 用户可能是刚接触SLAM的研究生或工程师,需要系统性的学习路径。ta特意提到"学习方法",说明更关注如何高效掌握而非单纯获取资料列表。 这本书的核心难点在于:多传感器融合(视觉+惯性)、非线性优化(李群李代数)、实时地图构建。建议分三个阶段学习: 第一阶段夯实基础(第1-5章),重点吃透三维旋转的多种表示法(旋转矩阵/四元数/欧拉角),以及李群李代数微分。这里需要补充多元微积分和线性代数的前置知识,比如Jacobian矩阵的计算。 第二阶段突破优化(第6-10章),Bundle Adjustment和位姿图优化是重点。建议结合g2o或Ceres源码理解优化过程,同时动手实现高斯牛顿法。非线性优化部分可参考《Numerical Optimization》第10章补充。 第三阶段工程实践(第11-14章),特别要掌握ORB-SLAM的代码结构。实际调试时注意:特征点匹配的RANSAC参数、闭环检测的词袋模型参数对系统稳定性影响很大。 用户可能遇到的典型卡点:第4章李代数求导(式4.35的推导)、第7章PnP问题(EPnP算法原理)、第10章位姿图优化(g2o的边顶点定义)。这些需要配合课后习题反复练习。 推荐三个辅助资源:一是作者在B站的配套座(关键章节有演示),二是GitHub上高翔的ch7代码(orb_cv3中有PNP的详细注释),三是《State Estimation for Robotics》第7章作为数学补充。如果学习VO部分遇到困难,可以先从MonoSLAM这类经典论文入手理解框架。 最后提醒用户:SLAM系统对初始值敏感,调试时先用TUM数据集等标准数据,避免过早接触复杂场景。实践中相机标定误差控制在0.1像素以下效果较好。</think>学习高翔的《视觉SLAM十四》需要系统规划,以下是分阶段学习建议: ### 一、基础准备阶段(1-2周) 1. **数学基础强化** - 线性代数:矩阵运算($A\mathbf{x}=\mathbf{b}$)、特征分解 - 微积分:偏导数($\frac{\partial f}{\partial x}$)、雅可比矩阵($J=\begin{bmatrix} \frac{\partial f_1}{\partial x_1} & \cdots \\ \vdots & \ddots \end{bmatrix}$) - 李群与李代数:SO(3)/SE(3)群($T = \begin{bmatrix} R & t \\ 0^T & 1 \end{bmatrix}$) *推荐《线性代数应该这样学》补充理论[^1]* 2. **编程能力** - C++核心语法(类/模板/STL) - OpenCV基础操作(图像处理、特征提取) - CMake编译工具 ```bash # CMake示例 cmake_minimum_required(VERSION 3.10) project(SLAM_Learning) find_package(OpenCV REQUIRED) add_executable(hello_slam hello.cpp) target_link_libraries(hello_slam ${OpenCV_LIBS}) ``` ### 二、书本精读阶段(8-12周) | 章节 | 重点内容 | 实践建议 | |------|----------|----------| | 前5章 | 三维刚体运动($R\mathbf{p} + \mathbf{t}$)、相机模型($\frac{1}{Z}\begin{pmatrix} u \\ v \\ 1 \end{pmatrix} = K(R|t)\begin{pmatrix} X \\ Y \\ Z \\ 1 \end{pmatrix}$) | 实现PnP求解器 | | 6-10章 | 非线性优化($\min_{\Delta x} \|f(x+\Delta x)\|^2$)、VO/SLAM框架 | 用g2o优化BA问题 | | 11-14章 | 回环检测(词袋模型)、地图构建 | 运行ORB-SLAM2代码 | 3. **关键实践** - 完成所有课后习题(GitHub有官方答案) - 复现核心算法: ```cpp // 李代数扰动模型示例 Sophus::SE3d update_SE3(const Vec6d& delta) { return SE3d::exp(delta) * current_pose; } ``` ### 三、工程深化阶段(4-6周) 1. **框架实战** - 编译调试ORB-SLAM2/3(注意OpenCV版本兼容) - 修改特征提取参数(FAST阈值、描述子距离) ```yaml # ORB-SLAM2配置文件片段 ORBextractor.nFeatures: 2000 ORBextractor.scaleFactor: 1.2 ``` 2. **数据集验证** | 数据集 | 特点 | 适用场景 | |--------|------|----------| | KITTI | 车载双目+IMU | 定位精度评估 | | TUM RGB-D | 室内深度图 | 重建实验 | | EuRoC MAV | 无人机微震数据 | IMU融合研究 | ### 四、拓展提升 - **理论延伸**:阅读原始论文(PTAM、LSD-SLAM) - **硬件实践**:用Realsense D455搭建实验平台 - **社区参与**:GitHub提交代码修复/知乎专栏「SLAM之路」 > 避坑提示:安装g2o时注意依赖suitesparse,建议使用Ubuntu 20.04+ROS Noetic环境[^2]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值