高博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 );