欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

G2O

程序员文章站 2022-05-28 18:20:46
...

slam十四讲:g20代码运次错误

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 );
双击报错内容,定位到报错代码位置,修改代码:

typedef g2o::BlockSolver< g2o::BlockSolverTraits<3,1> > Block;
Block::LinearSolverType* linearSolver = new g2o::LinearSolverDense<Block::PoseMatrixType>();
Block* solver_ptr = new Block( std::unique_ptr<Block::LinearSolverType>(linearSolver) );
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(std::unique_ptr<Block>(solver_ptr) );
g2o::SparseOptimizer optimizer;   
optimizer.setAlgorithm( solver );   
optimizer.setVerbose( true ); 

参考链接:https://www.cnblogs.com/xueyuanaichiyu/p/7921382.html

g2o CmakeLists.txt 写法:

方法1:

set( CMAKE_CXX_FLAGS "-std=c++11" )
list(APPEND CMAKE_MODULE_PATH  /home/XXX/g2o/cmake_modules)
  set(G2O_ROOT /home/XXX/g2o)
  find_package( G2O REQUIRED )
  include_directories(
        ${G2O_INCLUDE_DIRS}
        "/usr/include/eigen3" )

方法2:

CMAKELIsts.txt:
set( CMAKE_CXX_FLAGS "-std=c++11" )
list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules )
# 寻找G2O
#不使用 find_package( G2O REQUIRED )命令,否则会报错。
find_package( G2O )
include_directories( 
    ${G2O_INCLUDE_DIRS}
    "/usr/include/eigen3"
)
# OpenCV
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_DIRS} )
add_executable( curve_fitting main.cpp )
# 与G2O和OpenCV链接
target_link_libraries( curve_fitting 
    ${OpenCV_LIBS}
    g2o_core g2o_stuff
)

参考链接:https://blog.csdn.net/zhiwei121/article/details/89053469

相关标签: Linux Kdevelop