Ubuntu18.04 realsenseD435i ROS orbslam2

感谢大佬的文章:基于深度相机 RealSense D435i 的 ORB SLAM 2 - 简书

 之前一直使用Kinect进行尝试,但是一直点云都出不来

环境安装

OpenCV、ROS

Ubuntu安装、重装_echo_gou的博客-CSDN博客

Eigen3

wget  https://gitlab.com/libeigen/eigen/-/archive/3.2.10/eigen-3.2.10.tar.gz

tar -xvzf eigen-3.2.10.tar.gz 
mkdir build
cd build
cmake ..
sudo make install

Pangolin

在 ORB SLAM 2 中那些很炫酷的实时建图画面是通过 Pangolin 实现的。
Pangolin 是一个轻量级的开发库,控制 OpenGL 的显示、交互等。
Pangolin 的核心依赖是 OpenGL 和 GLEW。

# OpenGL
sudo apt install libgl1-mesa-dev

# Glew
sudo apt install libglew-dev

# CMake
sudo apt install cmake

# python 
sudo apt install libpython2.7-dev
sudo python -mpip install numpy pyopengl Pillow pybind11

# Wayland
sudo apt install pkg-config
sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols

# FFMPEG (For video decoding and image rescaling)
sudo apt install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev

# DC1394 (For firewire input)
sudo apt install libdc1394-22-dev libraw1394-dev

# libjpeg, libpng, libtiff, libopenexr (For reading still-image sequences)
sudo apt install libjpeg-dev libpng-dev libtiff5-dev libopenexr-dev

# build Pangolin
git clone https://github.com/stevenlovegrove/Pangolin.git

cd Pangolin

mkdir build

cd build

cmake ..

cmake --build .    # 注意最后那个点

测试:

cd ~/Pangolin/build/examples/HelloPangolin
./HelloPangolin 

PCL

sudo apt install libpcl-dev

代码运行前期操作

git clone https://github.com/gaoxiang12/ORBSLAM2_with_pointcloud_map.git

其中是一个压缩包和文件夹,我们只需要其中的子文件夹 ORB_SLAM2_modified。

把原本 ORB SLAM2 repo 中的 Vocabulary 文件夹和它里面的 ORBvoc.txt.tar.gz 文件拷贝过来,放到 ORB_SLAM2_modified 路径下。

~/ORB_SLAM2_modified/build, ~/ORB_SLAM2_modified/Thirdparty/DBoW2/build~/ORB_SLAM2_modified/Thirdparty/g2o/build

 ~/ORB_SLAM2_modified/Examples/ROS/ORB_SLAM2/build这四个 build 文件夹删掉

 在/opt/ros/melodic/setup.bash中的最后加入对应的路径,即:

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:xxx/xxx/catkin_ws/src/ORB_SLAM2_modified/Examples/ROS

记得每次运行的时候要source一下/opt/ros/melodic/setup.bash,或者在.bashrc中加上上面的export,但是在多个orbslam代码的时候容易出错,所以需要时刻用下面的语句检查路径是否export成功。 

查看自己的rospath:

echo $ROS_PACKAGE_PATH

输出里面需要有刚刚加入的ROS路径,即xxx/xxx/catkin_ws/src/ORB_SLAM2_modified/Examples/ROS,才可以在ROS下执行。

修改 ~/ORB_SLAM2_modified/Examples/ROS/ORB_SLAM2/CMakeLists.txt 文件,加入pcl

...
find_package(Eigen3 3.1.0 REQUIRED)
find_package(Pangolin REQUIRED)
find_package( PCL 1.7 REQUIRED )    ####### 1

include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../../../
${PROJECT_SOURCE_DIR}/../../../include
${Pangolin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}  ####### 2
)

add_definitions( ${PCL_DEFINITIONS} )   ####### 3
link_directories( ${PCL_LIBRARY_DIRS} ) ####### 4

set(LIBS 
${OpenCV_LIBS} 
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
${PCL_LIBRARIES} ####### 5
)
...

这里因为作者除了这个代码还有其他的orbslam代码,所以ROS空间下的文件夹的名字要作区分,这里我将 ORB_SLAM2_modified/Examples/ROS/下的文件夹改成了ORB_SLAM2-2,同时需要在build_ros.sh中进行相应的路径修改。

 然后运行 ORB_SLAM2_modified 中的

./build.sh
./build_ros.sh

Ubuntu18.04 realsenseD435i ROS orbslam2_第1张图片

 

运行

下载数据集:

rgbd_dataset_freiburg1_xyz

下面网址下载好以后拷贝associate.py至ORB_SLAM2主文件夹内。在associate.py所在的目录执行:(将RGB信息和深度信息链接到一起)

cvpr-ros-pkg - Revision 232: /trunk/rgbd_benchmark/rgbd_benchmark_tools/src/rgbd_benchmark_tools

python associate.py data/rgbd_dataset_freiburg1_xyz/rgb.txt data/rgbd_dataset_freiburg1_xyz/depth.txt > data/rgbd_dataset_freiburg1_xyz/associations.txt

运行:

./bin/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml data/rgbd_dataset_freiburg1_xyz data/rgbd_dataset_freiburg1_xyz/associations.txt

Ubuntu18.04 realsenseD435i ROS orbslam2_第2张图片

 

修改为彩色:

你可能感兴趣的:(slam)