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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ykwjt/article/details/89394086

原因: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

源码修改如下:

    // 初始化g2o
    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 );

3d2d报错:

/home/yk/桌面/slambook-master/ch7/pose_estimation_3d2d.cpp: In function ‘void bundleAdjustment(std::vector<cv::Point3_<float> >, std::vector<cv::Point_<float> >, const cv::Mat&, cv::Mat&, cv::Mat&)’:
/home/yk/桌面/slambook-master/ch7/pose_estimation_3d2d.cpp:151:50: error: no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<6, 3> >::BlockSolver(g2o::BlockSolver<g2o::BlockSolverTraits<6, 3> >::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/ch7/pose_estimation_3d2d.cpp:10:
/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<6, 3>; typename Traits::LinearSolverType = g2o::LinearSolver<Eigen::Matrix<double, 6, 6, 0> >]
 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<6, 3> >::LinearSolverType* {aka g2o::LinearSolver<Eigen::Matrix<double, 6, 6, 0> >*}’ to ‘std::unique_ptr<g2o::LinearSolver<Eigen::Matrix<double, 6, 6, 0> >, std::default_delete<g2o::LinearSolver<Eigen::Matrix<double, 6, 6, 0> > > >’
/home/yk/桌面/slambook-master/ch7/pose_estimation_3d2d.cpp:152:104: error: no matching function for call to ‘g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(Block*&)’
 ithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg ( solver_ptr );
                                                                              ^
In file included from /home/yk/桌面/slambook-master/ch7/pose_estimation_3d2d.cpp:11: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<6, 3> >*}’ to ‘std::unique_ptr<g2o::Solver>’
CMakeFiles/pose_estimation_3d2d.dir/build.make:62: recipe for target 'CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o' failed
make[2]: *** [CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/pose_estimation_3d2d.dir/all' failed
make[1]: *** [CMakeFiles/pose_estimation_3d2d.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

源码修改如下:

  // 初始化g2o
        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/weixin_38358435/article/details/79082733
https://blog.csdn.net/robinhjwy/article/details/78084210
https://www.cnblogs.com/xueyuanaichiyu/p/7921382.html
https://blog.csdn.net/pangzilu520/article/details/81087577

展开阅读全文

没有更多推荐了,返回首页