美文网首页
6.4 实践:g2o

6.4 实践:g2o

作者: 陌上尘离 | 来源:发表于2018-04-27 20:33 被阅读0次

    一、g2o的安装

    //安装依赖项
    sudo apt-get install libqt4-dev qt4-qmake libqglviewer-dev libsuitesparse-dev libcxsparse3.1.4 libcholmod3.0.6
    //去git hub下载源码后编译安装
    cd g2o
    mkdir build
    cd build
    cmake ..
    make
    sudo make install

    二、P124页程序

    注意构建图优化,设定g2o时,g2o版本与原作者不同可能导致报错,原因在于:
    Block* solver_ptr = new Block ( linearSolver );
    这里的构造函数BloclSolver更改了,下述博客中给出了较为详细的解释:
    https://blog.csdn.net/robinhjwy/article/details/78084210
    ——————————————分割线————————————————
    在第六章的实验中,只需要把初始化部分函数更改为一下代码即可:

    typedef g2o::BlockSolver< g2o::BlockSolverTraits<3,1> > Block;  // pose 维度为 6, landmark 维度为 3
    
    //Block::LinearSolverType* linearSolver = new g2o::LinearSolverDense<Block::PoseMatrixType>(); // 线性方程求解器
    std::unique_ptr<Block::LinearSolverType> linearSolver ( new g2o::LinearSolverDense<Block::PoseMatrixType>());
    
    //Block* solver_ptr = new Block ( linearSolver );
    //std::unique_ptr<Block> solver_ptr ( new Block ( linearSolver));
    std::unique_ptr<Block> solver_ptr ( new Block ( std::move(linearSolver)));     // 矩阵块求解器
    
    //g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg ( solver_ptr);
    g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg ( std::move(solver_ptr));
    
    g2o::SparseOptimizer optimizer;
    
    optimizer.setAlgorithm ( solver );

    相关文章

      网友评论

          本文标题:6.4 实践:g2o

          本文链接:https://www.haomeiwen.com/subject/cysflftx.html