相关软硬件版本说明
系统:Ubuntu18.04
显卡:RTX2060
显卡驱动:440.95.01
Cuda版本:Cuda10.1
Cudnn: 7.6.5
系统安装了ROS: Melodic
BADSLAM具有预编译和源码编译两个版本,本文选择后者,下载源码进行编译。
相关资源我已经上传到网盘中,可供下载:
链接:https://rec.ustc.edu.cn/share/9c98adf0-5ac3-11eb-afd7-632b29b78667
密码:af71
1、克隆源码
git clone https://github.com/ETH3D/badslam.git
2、安装依赖
按照官方网站上的说明安装即可,如下图所示:
其实可以直接进行下一步编译,然后发现缺少哪个库就直接在点击上面图中官网的链接安装即可。
记住安装g2o时,源码编译成功之后需要执行:
sudo make install
3、安装SuiteSparse
sudo apt-get install libsuitesparse-dev
3、开始编译
mkdir build_RelWithDebInfo
cd build_RelWithDebInfo
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CUDA_FLAGS="-arch=sm_61" ..
make -j badslam
4、报错解决
(1)
/usr/local/include/DVision/BRIEF256.h:207:11: error: ‘cvtColor’ is not a member of ‘cv’
/usr/local/include/DVision/BRIEF256.h:284:12: error: ‘DUtils’ has not been declared
解决:
cd /usr/local/include/DVision
sudo gedit BRIEF256.h
添加下列三行:
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <DUtils/DUtils.h>
(2) Target “badslam_test” links to target “g2o::csparse_extension” but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
解决办法:
找到文件夹applications/badslam/目录下的CMakeLists.txt文件
将如下代码进行更改,
target_link_libraries(badslam_baselib
PRIVATE
opengv
g2o::core
g2o::types_slam3d
g2o::solver_csparse
g2o::csparse_extension
${SuiteSparse_LIBRARIES}
g2o::stuff
${OpenCV_LIBS}
${DLib_LIBS}
DBoW2
${realsense2_LIBRARY}
${OPENGL_LIBRARY}
${GLEW_LIBRARIES}
${X11_LIBRARIES}
${Boost_LIBRARIES}
PUBLIC
libvis
libvis_cuda
)
更改为:
target_link_libraries(badslam_baselib
PRIVATE
opengv
/usr/local/lib/libg2o_core.so
/usr/local/lib/libg2o_types_slam3d.so
/usr/local/lib/libg2o_solver_csparse.so
/usr/local/lib/libg2o_csparse_extension.so
${SuiteSparse_LIBRARIES}
/usr/local/lib/libg2o_stuff.so
${OpenCV_LIBS}
${DLib_LIBS}
DBoW2
${realsense2_LIBRARY}
${OPENGL_LIBRARY}
${GLEW_LIBRARIES}
${X11_LIBRARIES}
${Boost_LIBRARIES}
PUBLIC
libvis
libvis_cuda
)
(3)/usr/local/include/g2o/core/base_fixed_sized_edge.h:174:32: error: ‘index_sequence’ is not a member of ‘std’
解决办法:
导致这个错误的原因是g2o版本过高,将20201220.git更换为20170730_git即可。
4、进行功能测试
make -j badslam_test
./build_RelWithDebInfo/applications/badslam/badslam_test
程序出现错误,无法运行:
libGLEW.so.2.2: cannot open shared object file: No such file or directory
解决办法:
在/根目录下查找libGLEW.so.2.2,发现文件在/usr/lib64中,将其加入到动态链接库的搜索路径中:
sudo gedit /etc/ld.so.conf
在文件末尾第二行直接添加/usr/lib64,然后执行下列命令即可:
sudo ldconfig
注:/etc/ld.so.conf.d/*目录下的文件和/etc/ld.so.conf记录了动态链接库的路径,系统默认搜索/lib和 /usr/lib,在其他路径下的库文件就需在这些文件中指定。
此时可能会报错:
"too many resources requested for launch",
不用担心,后期会解决它。
5、数据集准备
新建calibration.txt文件,向其中输入内参,如下图所示:
准备rgb和depth文件夹,其中的图片以时间戳命名,点击链接下载TUM提供的时间戳对齐工具,然后输入以下命令:
python associate.py rgb.txt depth.txt > associated.txt
由此可以生成时间戳对齐文件associated.txt。
到此为止,就得到了BADSLAM需要的完整的数据集,一共有rgb、depth、calibration.txt和associated.txt四项,如下图所示:
6、resource文件准备
点击链接下载resource文件夹,官网提供的这个下载地址是谷歌网盘,一般用户可能无法登录,这里我将其上传到了本人的网盘中供大家下载地址为:
链接:https://rec.ustc.edu.cn/share/9c98adf0-5ac3-11eb-afd7-632b29b78667
密码:af71
在/ build_RelWithDebInfo/applications/badslam/下面新建一个resources文件夹,然后拷贝其中的brief_k10L6.voc 和 brief_pattern.yml两个文件到该文件夹中,此时文件结构如下:
- build_RelWithDebInfo
- applications
- badslam
- badslam (executable file)
- resources
- brief_k10L6.voc (notice that this is compressed in the archive and needs to be extracted separately)
- brief_pattern.yml
7、GPU测试
测试的数据集我已上传到网盘中,可供下载
python3 scripts/auto_tune_parameters.py /home/shiqi/MyProject/badslam/build_RelWithDebInfo/applications/badslam/badslam /media/shiqi/Dataset/AzureKinectDK/test --sequential_ba --sequential_loop_detection
命令执行完之后会发现在/badslam/applications/badslam/下生成一个auto_tuning_result.txt文件,将其拷贝到resource文件夹下。
8、运行badslam
./build_RelWithDebInfo/applications/badslam/badslam
在第一行选择后面“…”按钮中选择数据集路径,设置一下End frame,然后点击start即可,运行结果如下图所示: