ORB-SLAM2编译、安装等问题汇总大全(Ubuntu20.04、eigen3、pangolin0.5、opencv3.4.10)
1:环境说明:
使用的Linux发行版本为Ubuntu 20.04
SLAM2下载地址为:git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
2:eigen版本为 3.2.10
下载地址:https://eigen.tuxfamily.org/index.php?title=Main_Page
3:pangolin版本为0.5,高版本在编译ORB-SLAM2时会出现很多问题
下载地址:https://github.com/stevenlovegrove/Pangolin/tree/v0.5
卸载pangolin:https://blog.csdn.net/qq_42257666/article/details/126069335
4:opencv版本为3.4.10,这个版本不会报错
下载地址:https://github.com/opencv/opencv/releases/tag/3.4.10
5:数据
数据下载地址:https://vision.in.tum.de/data/datasets/rgbd-dataset/download
1.安装:eigen版本为 3.2.10
1.1安装步骤
1:安装命令
cd eigen-3.2.10
mkdir build
cd build
cmake..
sudo make install
sudo cp -r /usr/local/include/eigen3 /usr/include
2:查看当前版本,验证是否安装成功
pkg-config --modversion eigen3
2.卸载eigen3
1:查询当前版本
pkg-config --modversion eigen3
2:查看eigen3位置相关文件
sudo updatedb
locate eigen3
3:删除eigen3相关文件
sudo rm -rf /usr/include/eigen3
sudo rm -rf /usr/lib/cmake/eigen3
sudo rm -rf /usr/local/include/eigen3
sudo rm -rf /usr/share/doc/libeigen3-dev
sudo rm -rf /usr/local/share/pkgconfig/eigen3.pc /usr/share/pkgconfig/eigen3.pc /var/lib/dpkg/info/libeigen3-dev.list /var/lib/dpkg/info/libeigen3-dev.md5sums
sudo rm -rf /usr/local/lib/pkgconfig/eigen3.pc
sudo rm -rf /usr/local/share/eigen3
4:查询是否已经删除
pkg-config --modversion eigen3
3:安装opencv
1:安装依赖
sudo apt-get install cmake
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
2:编译安装
在 opencv-3.4.10文件夹中建立名为 build的文件夹,在build 目录下执行 cmake 和 make。
mkdir build
cd build
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=O -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j8
sudo make install
3:环境配置
动态库配置
sudo gedit /etc/ld.so.conf.d/opencv.conf
添加
/usr/local/lib
保存后,终端内执行
sudo ldconfig
更新 PKG_CONFIG_PATH
sudo gedit /etc/bash.bashrc
文末添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
4:保存后,终端执行
source /etc/bash.bashrc
sudo updatedb
若出现 sudo: updatedb: command not found,执行 sudo apt install mlocate 后再次操作即可。
5:验证
pkg-config opencv --modversion
pkg-config --modversion opencv
pkg-config --cflags opencv
pkg-config --libs opencv
4:安装Realsense SDK
1:下载source
git clone https://github.com/IntelRealSense/librealsense
cd librealsense
2:安装依赖项
sudo apt-get install libudev-dev pkg-config libgtk-3-dev
sudo apt-get install libusb-1.0-0-dev pkg-config
sudo apt-get install libglfw3-dev
sudo apt-get install libssl-dev
3:Install Intel Realsense permission scripts located in librealsense source directory:
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && udevadm trigger
4:这边需要注意把realsense拔下来
Build and apply patched kernel modules for:
根据不同的ubuntu版本安装:对于Ubuntu 14/16/18 LTS
./scripts/patch-realsense-ubuntu-lts.sh
sudo dmesg | tail -n 50
这里可以看一下UVC是否安装成功了
5:基于cmake的编译
mkdir build
cd build
cmake ../ -DBUILD_EXAMPLES=true
make
sudo make install
-DBUILD_EXAMPLES=true 这个选项表示带演示和教程的
6:进入/librealsense/build/examples/capture,试一下效果
./rs-capture
5:ros下驱动realsense相机获取点云
安装依赖
sudo apt-get install ros-$ROS_DISTRO-realsense2-camera
方法1:
1:查看内核版本
uname -r : 显示操作系统的发行版号
如果>=4.4.0-50的版本就可以继续向下进行了,否则需要升级你的Ubuntu内核。
读取点云
2:安装rgbd.launch
cd ~/catkin_ws/src/
git clone https://github.com/ros-drivers/rgbd_launch.git
cd ..
catkin_make
将rs_rgbd.launch和rs_camera.launch文件中的<arg name="enable_pointcloud" default="false"/>由false改为true
roslaunch realsense2_camera rs_rgbd.launch
点击add 选择PointCloud2进行display,选择Fixed Frame和Topic,如图所示
方法2:
1:建立workspace,已经有的可以跳过
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src/
catkin_init_workspace
cd ..
catkin_make
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
2:在catkin_ws/src/下载源程序
cd src
git clone https://github.com/intel-ros/realsense.git
3:catkin_make
cd ..
catkin_make
4:如果没有错误说明,已经装好了,启动相机节点
roslaunch realsense2_camera rs_rgbd.launch
5:看一下发布的topic
rostopic list
内参获取
6:若不进行标定,可以先从Realsense ROS Wrapper发布的topic中获得相机的内参。
rostopic echo /camera/color/camera_info
rostopic echo /camera/aligned_depth_to_color/camera_info
3:方法3 Step3 安装基于ROS使用RealSense的包
官方教程
1:安装
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src/
Clone the latest Intel® RealSense™ ROS from here into ‘catkin_ws/src/’
把realsense这个文件下载/克隆到该目录下
catkin_init_workspace
cd ..
catkin_make clean
catkin_make -DCATKIN_ENABLE_TESTING=False -DCMAKE_BUILD_TYPE=Release
catkin_make install
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
2:检验是否能在ros使用realsense相机:
install rgbd_launch
sudo apt-get install ros-kinetic-rgbd-launch
roslaunch realsense2_camera rs_rgbd.launch
再打开一个终端,输入rviz
此时并不能看到什么结果
左上角 Displays 中 Fixed Frame 选项中,下拉菜单选择 camera_link
这是主要到Global Status变成了绿色
点击该框中的Add -> 上方点击 By topic -> /depth_registered 下的 /points 下的/PointCloud2
点击该框中的Add -> 上方点击 By topic -> /color 下的 /image_raw 下的image
见下图:
6:下载ORB_SLAM2:
下载ORB_SLAM2
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
2:修改build.sh文件
这时候打开文件夹里的build.sh文件,默认是make -j,如果不改容易引起系统卡死。改为make -j4即可(数字为电脑CPU的核心数),或者去掉-j。
2.1:如果多线程编译错误
把build.sh的make -j改成make(这是为了防止多线程编译出错,对于build_ros.sh文件也是同理,下面就不说了)
3:为了避免编译时出现usleep的错误,相应文件添加 #include<unistd.h>,具体有
/src/LocalMapping.cc
/src/System.cc
/src/LoopClosing.cc
/src/Tracking.cc
/src/Viewer.cc
/Examples/Monocular/mono_tum.cc
/Examples/Monocular/mono_kitti.cc
/Examples/Monocular/mono_euroc.cc
/Examples/RGB-D/rgbd_tum.cc
/Examples/Stereo/stereo_kitti.cc
/Examples/Stereo/stereo_euroc.cc
4:编译安装
cd ORB_SLAM2
chmod +x build.sh
运行build.sh
./build.sh
5:下载数据集
我使用的是TUM数据集,在
https://vision.in.tum.de/data/datasets/rgbd-dataset/download
6:下载rgbd_dataset_freiburg1_xyz即可,解压
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml PATH_TO_SEQUENCE_FOLDER
PATH_TO_SEQUENCE_FOLDER是你文件的地址。
然后就开始运行例程了,贴图:
7:将PATH_TO_SEQUENCE_FOLDER更换成下载后的文件的地址。
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml /home/ubicast/data/rgbd_dataset_freiburg1_xyz
7:编辑报错
1: 报错及处理:error: ‘AV_PIX_FMT_XVMC_MPEG2_MC’ was not declared in this scope
参考:https://blog.csdn.net/Robert_Q/article/details/121690089
2:详细报错信息
/home/andy/Downloads/Pangolin/src/video/drivers/ffmpeg.cpp: In function ‘std::__cxx11::string pangolin::FfmpegFmtToString(AVPixelFormat)’:
/home/andy/Downloads/Pangolin/src/video/drivers/ffmpeg.cpp:41:41: error: ‘AV_PIX_FMT_XVMC_MPEG2_MC’ was not declared in this scope
参考:https://github.com/stevenlovegrove/Pangolin/pull/318/files?diff=split&w=0
3:解决办法:在/Pangolin/CMakeModules/FindFFMPEG.cmake中63,64行
3.1:更改代码
sizeof(AVFormatContext::max_analyze_duration2);
}" HAVE_FFMPEG_MAX_ANALYZE_DURATION2
换成
sizeof(AVFormatContext::max_analyze_duration);
}" HAVE_FFMPEG_MAX_ANALYZE_DURATION
3.2:/Pangolin/src/video/drivers/ffmpeg.cpp中第37行 namespace pangolin上面加上
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
3.3:更改代码第78,79行
TEST_PIX_FMT_RETURN(XVMC_MPEG2_MC);
TEST_PIX_FMT_RETURN(XVMC_MPEG2_IDCT);
改为
#ifdef FF_API_XVMC
TEST_PIX_FMT_RETURN(XVMC_MPEG2_MC);
TEST_PIX_FMT_RETURN(XVMC_MPEG2_IDCT);
#endif
3.4:更改代码101-105行
TEST_PIX_FMT_RETURN(VDPAU_H264);
TEST_PIX_FMT_RETURN(VDPAU_MPEG1);
TEST_PIX_FMT_RETURN(VDPAU_MPEG2);
TEST_PIX_FMT_RETURN(VDPAU_WMV3);
TEST_PIX_FMT_RETURN(VDPAU_VC1);
改为
#ifdef FF_API_VDPAU
TEST_PIX_FMT_RETURN(VDPAU_H264);
TEST_PIX_FMT_RETURN(VDPAU_MPEG1);
TEST_PIX_FMT_RETURN(VDPAU_MPEG2);
TEST_PIX_FMT_RETURN(VDPAU_WMV3);
TEST_PIX_FMT_RETURN(VDPAU_VC1);
#endif
3.5:更改代码第127行
TEST_PIX_FMT_RETURN(VDPAU_MPEG4);
改为
#ifdef FF_API_VDPAU
TEST_PIX_FMT_RETURN(VDPAU_MPEG4);
#endif
4:error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
#define TEST_PIX_FMT_RETURN(fmt) case AV_PIX_FMT_##fmt: return #fmt; /home/andy/Downloads/Pangolin/src/video/drivers/ffmpeg.cpp: In member
function ‘void
pangolin::FfmpegVideoOutputStream::WriteFrame(AVFrame*)’:
/home/andy/Downloads/Pangolin/src/video/drivers/ffmpeg.cpp:572:39:
error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
if (recorder.oc->oformat->flags & AVFMT_RAWPICTURE) {
4.1:解决办法,在Pangolin/include/pangolin/video/drivers/ffmpeg.h开头加上
#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020
2:报错:error: static assertion failed: std::map must have the same value_type as its allocato
/usr/include/c++/8.1.0/bits/stl_map.h: In instantiation of ‘class std::map<ORB_SLAM2::KeyFrame*, g2o::Sim3, std::less<ORB_SLAM2::KeyFrame*>, Eigen::aligned_allocator<std::pair<const ORB_SLAM2::KeyFrame*, g2o::Sim3> > >’:
/home/zach/Projects/ORB-SLAM/ORB_SLAM2/src/Optimizer.cc:818:37: required from here
/usr/include/c++/8.1.0/bits/stl_map.h:122:21: error: static assertion failed: std::map must have the same value_type as its allocator
static_assert(is_same<typename _Alloc::value_type, value_type>::value,
这个可以参考
https://github.com/raulmur/ORB_SLAM2/pull/585
这篇文字上的解答,具体需要: