高博14讲:第七讲中g20报错

13 篇文章 3 订阅

高博14讲:第七讲中g20 3d3d 3d2d 报错的改动

原因:g2o版本更新引起的错误修改

3d3d报错:

/home/yk/桌面/slambook-master/ch7/pose_estimation_3d3d.cpp: In function ‘void bundleAdjustment(const std::vector<cv::Point3_<float> >&, const std::vector<cv::Point3_<float> >&, cv::Mat&, cv::Mat&)’:
/home/yk/桌面/slambook-master/ch7/pose_estimation_3d3d.cpp:280:74: error: ‘LinearSolverCSparse’ in namespace ‘g2o’ does not name a template type
    std::unique_ptr<Block::LinearSolverType> linearSolver ( new g2o::LinearSolve
                                                                     ^
/home/yk/桌面/slambook-master/ch7/pose_estimation_3d3d.cpp:280:115: error: expected primary-expression before ‘>’ token
 verType> linearSolver ( new g2o::LinearSolverCSparse<Block::PoseMatrixType>());
                                                                           ^
/home/yk/桌面/slambook-master/ch7/pose_estimation_3d3d.cpp:280:117: error: expected primary-expression before ‘)’ token
 verType> linearSolver ( new g2o::LinearSolverCSparse<Block::PoseMatrixType>());
                                                                             ^
/home/yk/桌面/slambook-master/ch7/pose_estimation_3d3d.cpp:287:9: error: ‘OptimizationAlgorithmLevenberg’ is not a member of ‘g2o’
         g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgo
         ^
/home/yk/桌面/slambook-master/ch7/pose_estimation_3d3d.cpp:287:46: error: ‘solver’ was not declared in this scope
         g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgo
                                              ^
/home/yk/桌面/slambook-master/ch7/pose_estimation_3d3d.cpp:287:59: error: expected type-specifier
         g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgo
                                                           ^
CMakeFiles/pose_estimation_3d3d.dir/build.make:62: recipe for target 'CMakeFiles/pose_estimation_3d3d.dir/pose_estimation_3d3d.cpp.o' failed
make[2]: *** [CMakeFiles/pose_estimation_3d3d.dir/pose_estimation_3d3d.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/pose_estimation_3d3d.dir/all' failed
make[1]: *** [CMakeFiles/pose_estimation_3d3d.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

将pose_estimation_3d3d.cpp中的 bundleAdjustment() 函数中初始g2o修改一下:

原始代码:

    typedef g2o::BlockSolver< g2o::BlockSolverTraits<6,3> > Block;  // pose维度为 6, landmark 维度为 3
    Block::LinearSolverType* linearSolver = new g2o::LinearSolverEigen<Block::PoseMatrixType>(); // 线性方程求解器
    Block* solver_ptr = new Block( linearSolver );      // 矩阵块求解器


    g2o::OptimizationAlgorithmGaussNewton* solver = new g2o::OptimizationAlgorithmGaussNewton( solver_ptr );
    g2o::SparseOptimizer optimizer;
    optimizer.setAlgorithm( solver );

修改为:

    typedef g2o::BlockSolver< g2o::BlockSolverTraits<6,3> > Block;  // pose维度为 6, landmark 维度为 3

    // Block::LinearSolverType* linearSolver = new g2o::LinearSolverEigen<Block::PoseMatrixType>(); // 线性方程求解器
    std::unique_ptr<Block::LinearSolverType> linearSolver ( new g2o::LinearSolverEigen<Block::PoseMatrixType>());

    //Block* solver_ptr = new Block( linearSolver );      // 矩阵块求解器
    std::unique_ptr<Block> solver_ptr ( new Block ( std::move(linearSolver)));

    //g2o::OptimizationAlgorithmGaussNewton* solver = new g2o::OptimizationAlgorithmGaussNewton( solver_ptr );
    g2o::OptimizationAlgorithmGaussNewton* solver = new g2o::OptimizationAlgorithmGaussNewton ( std::move(solver_ptr));

    g2o::SparseOptimizer optimizer;
    optimizer.setAlgorithm( solver );

将pose_estimation_3d2d.cpp中的 bundleAdjustment() 函数中初始g2o修改一下:

原始代码:

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

修改为;

     typedef g2o::BlockSolver< g2o::BlockSolverTraits<6,3> > Block;  // pose 维度为 6, landmark 维度为 3

     //Block::LinearSolverType* linearSolver = new g2o::LinearSolverCSparse<Block::PoseMatrixType>(); // 线性方程求解器
     std::unique_ptr<Block::LinearSolverType> linearSolver ( new g2o::LinearSolverCSparse<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 );

参考:https://blog.csdn.net/ykwjt/article/details/89394086

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值