高博十四讲中第六章非线性优化 由于g2o更新出现的问题解决

在高博视觉slam十四讲中的第6讲中实践g2o中出现了编译错误:

/home/yk/桌面/slambook-master/ch6/g2o_curve_fitting/main.cpp: In function ‘int main(int, char**)’:
/home/yk/桌面/slambook-master/ch6/g2o_curve_fitting/main.cpp:77:49: error: no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<3, 1> >::BlockSolver(g2o::BlockSolver<g2o::BlockSolverTraits<3, 1> >::LinearSolverType*&)’
     Block* solver_ptr = new Block( linearSolver );      // 矩阵块求解器
                                                 ^
In file included from /usr/local/include/g2o/core/block_solver.h:199:0,
                 from /home/yk/桌面/slambook-master/ch6/g2o_curve_fitting/main.cpp:4:
/usr/local/include/g2o/core/block_solver.hpp:40:1: note: candidate: g2o::BlockSolver<Traits>::BlockSolver(std::unique_ptr<typename Traits::LinearSolverType>) [with Traits = g2o::BlockSolverTraits<3, 1>; typename Traits::LinearSolverType = g2o::LinearSolver<Eigen::Matrix<double, 3, 3> >]
 BlockSolver<Traits>::BlockSolver(std::unique_ptr<LinearSolverType> linearSolver
 ^
/usr/local/include/g2o/core/block_solver.hpp:40:1: note:   no known conversion for argument 1 from ‘g2o::BlockSolver<g2o::BlockSolverTraits<3, 1> >::LinearSolverType* {aka g2o::LinearSolver<Eigen::Matrix<double, 3, 3> >*}’ to ‘std::unique_ptr<g2o::LinearSolver<Eigen::Matrix<double, 3, 3> >, std::default_delete<g2o::LinearSolver<Eigen::Matrix<double, 3, 3> > > >’
/home/yk/桌面/slambook-master/ch6/g2o_curve_fitting/main.cpp:79:103: error: no matching function for call to ‘g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(Block*&)’
 rithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg( solver_ptr );
                                                                              ^
In file included from /home/yk/桌面/slambook-master/ch6/g2o_curve_fitting/main.cpp:5: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 ‘Block* {aka g2o::BlockSolver<g2o::BlockSolverTraits<3, 1> >*}’ to ‘std::unique_ptr<g2o::Solver>’
CMakeFiles/curve_fitting.dir/build.make:62: recipe for target 'CMakeFiles/curve_fitting.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/curve_fitting.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/curve_fitting.dir/all' failed
make[1]: *** [CMakeFiles/curve_fitting.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

通过查找百度查询,看到一篇博客展现了也是在编译高博视觉slam十四讲g2o环节出现问题的解决方案,(转载于->)https://blog.csdn.net/weixin_38358435/article/details/79082733模仿这位作者的解决过程,修改了我的代码。

typedef g2o::BlockSolver<g2o::BlockSolverTraits<3,1> > Block;  // 每个误差项优化变量维度为3,误差值维度为1
std::unique_ptr<Block::LinearSolverType> linearSolver ( new g2o::LinearSolverDense<Block::PoseMatrixType>());
//Block::LinearSolverType* linearSolver = new g2o::LinearSolverDense<Block::PoseMatrixType>(); // 线性方程求解器
std::unique_ptr<Block> solver_ptr ( new Block ( std::move(linearSolver))); 
//Block* solver_ptr = new Block( linearSolver );      // 矩阵块求解器
// 梯度下降方法,从GN, LM, DogLeg 中选
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg ( std::move(solver_ptr));
//g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg( solver_ptr );

然后就编译成功了。

g2o安装步骤:
1.看14讲安装。
github下载包。
按照书中安装依赖项。(会出现libcholmod-dev文件找不到:可能由于版本不同吧,所以安装这个依赖项的时候,建议这样做:输入sudo apt-get install libcholmod然后按Tab键,Tab键就是自动补充命令,当你记不住完整命令的时候,你按下它,他会自动搜索!我在这里出来的是libcholmod2.1.2,然后安装就好!接着在输入:sudo apt-get install libqt4-dev qt4-qmake libqglviewer-dev libsuitesaprse-dev libcxsparse3.1.2) 原文:https://blog.csdn.net/hitfangyu/article/details/72665455
再之后的话,建议去github上面下载源码https://github.com/RainerKuemmerle/g2o

将压缩的文件解压,然后到文件目录下,

mkdir build

cd build

cmake …

make

sudo make install

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值