跟做高博的《一起做RGB-D SLAM》系列时,出现了挺多bug的(主要因为自己还是个小白),在此记录下解决过程。(ubuntu18.04,opencv3.4.9)
一起做RGB-D SLAM(6):
1.Ubuntu18安装g2o
在ubuntu18.04下安装g2o还是挺容易的,先安装依赖:
sudo apt-get install qtcreator libeigen3-dev libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5
最后一个依赖也可以改为libqglviewer-dev-qt4,分别是基于QT5和4开发的,选择一个需要的就好。这个依赖关乎到g2o的viewer的安装,如果安不上的话,对照官方文档安装libqglviewer(下载解压后用QTcreator打开libQGLViewer-2.7.2/QGLViewer/QGLViewer.pro,构建全部)。
安好依赖后下载g2o安装包:github,然后cd到g2o的根目录下:
mkdir build
cd build
cmake ..
make
sudo make install
2.error: no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<6, 3> >::BlockSolver(SlamLinearSolver*&)’ SlamBlockSolver* blockSolver = new SlamBlockSolver( linearSolver );
这个错误是因为g2o新版本和旧版本在智能指针上不兼容导致的。参照关于关于高博3d2d程序报错的改动,把src/slamEnd.cpp(下图白框处内容)改为:
unique_ptr<SlamBlockSolver::LinearSolverType> linearSolver (new SlamLinearSolver());
unique_ptr<SlamBlockSolver> blockSolver (new SlamBlockSolver(move(linearSolver)));
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(move(blockSolver));
3.CMake Error: The current CMakeCache.txt directory /home/max/slam0.1/slam/build/CMakeCache.txt is different than the directory /home/max/slam0.1/slamt/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
把build文件下的内容都删掉再重新cmake …就行。
4.error: ‘struct FRAME’ has no member named ‘frameID’ f.frameID = index;
在include/slamBase.h里(下图白框处)加上:
int frameID;
5.CMakeFiles/slamEnd.dir/slamEnd.cpp.o:在函数‘main’中:slamEnd.cpp:(.text+0xbf2):对‘g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(std::unique_ptr<g2o::Solver, std::default_deleteg2o::Solver >)’未定义的引用slamEnd.cpp:(.text+0xc17):对‘g2o::SparseOptimizer::SparseOptimizer()’未定义的引用 slamEnd.cpp:(.text+0xc30):对‘g2o::SparseOptimizer::setAlgorithm(g2o::OptimizationAlgorithm*)’未定义的引用slamEnd.cpp:(.text+0xc44):对‘g2o::SparseOptimizer::setVerbose(bool)’未定义的引用 slamEnd.cpp:(.text+0xc59):对‘g2o::VertexSE3::VertexSE3()’未定义的引用 slamEnd.cpp:(.text+0xf71):对‘g2o::VertexSE3::VertexSE3()’未定义的引用 slamEnd.cpp:(.text+0xff3):对‘g2o::EdgeSE3::EdgeSE3()’未定义的引用 slamEnd.cpp:(.text+0x11d1):对‘g2o::OptimizableGraph::addEdge(g2o::OptimizableGraph::Edge*)’未定义的引用 slamEnd.cpp:(.text+0x12a6):对‘g2o::OptimizableGraph::save(char const*, int) const’未定义的引用
src/CMakeLists.txt里添加的slamEnd二进制执行文件要链接一些g2o库,修改为:
ADD_EXECUTABLE( slamEnd slamEnd.cpp )
TARGET_LINK_LIBRARIES( slamEnd
slambase
${ OpenCV_LIBS}
${ PCL_LIBRARIES}
g2o_core g2o_types_slam3d g2o_solver_csparse g2o_stuff g2o_csparse_extension ${ CSPARSE_LIBRARY})
ps:g2o的引用要写在src下的CMakeLists.txt里。