stella_vslam
适配的相机硬件有:
stella_vslam is a monocular, stereo, and RGBD visual SLAM system.
该算法支持单目、双目还有RGBD的视觉SLAM系统
- 它兼容各种类型的相机型号,并可以轻松定制其他相机型号。
- 创建的地图可以存储和加载,然后 stella_vslam 可以根据预先构建的地图定位新图像。
- 该系统是完全模块化的。它是通过使用易于理解的 API 将多个功能封装在单独的组件中而设计的。
- 我们提供了一些代码片段来理解这个系统的核心功能。
stella_vslam 的一个显着特点是系统可以处理各种类型的相机模型,例如透视、鱼眼和等距柱状。如果需要,用户可以轻松实现额外的相机模型(例如双鱼眼、折反射)。例如,使用等距柱状相机模型(如RICOH THETA系列、insta360系列等)的视觉SLAM算法如上所示。
官网指导的安装方法:
Installation — stella_vslam documentation
一、环境搭建
1.1 基础环境的依赖包的安装
sudo apt update -y
sudo apt upgrade -y --no-install-recommends
# basic dependencies
sudo apt install -y build-essential pkg-config cmake git wget curl unzip
# g2o dependencies
sudo apt install -y libatlas-base-dev libsuitesparse-dev
# OpenCV dependencies
sudo apt install -y libgtk-3-dev ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev libtbb-dev
# eigen dependencies
sudo apt install -y gfortran
# backward-cpp dependencies (optional)
sudo apt install -y binutils-dev
# other dependencies
sudo apt install -y libyaml-cpp-dev libgflags-dev sqlite3 libsqlite3-dev
# (if you plan on using PangolinViewer)
# Pangolin dependencies
sudo apt install -y libglew-dev
# (if you plan on using SocketViewer)
# Protobuf dependencies
sudo apt install -y autogen autoconf libtool
# Node.js
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install -y nodejs
1.2 下载源码
git clone --recursive https://github.com/stella-cv/stella_vslam.git
下载过程中遇到错误:
首先使用国内的gitee将要下拉的仓库下拉到自己的仓库中
然后执行:
git clone --recursive 此处换成码云的地址 这样就可以完成下拉代码了。
也可以直接使用下面的链接下载:https://download.csdn.net/download/YOULANSHENGMENG/87631448
1.3 依赖包的编译和安装
1)build and install g2o
cd /tmp
git clone https://github.com/RainerKuemmerle/g2o.git
cd g2o
git checkout ed40a5bb028566fd56a78fd7b04921b613492d6f
mkdir build && cd build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_UNITTESTS=OFF \
-DG2O_USE_CHOLMOD=OFF \
-DG2O_USE_CSPARSE=ON \
-DG2O_USE_OPENGL=OFF \
-DG2O_USE_OPENMP=OFF \
-DG2O_BUILD_APPS=OFF \
-DG2O_BUILD_EXAMPLES=OFF \
-DG2O_BUILD_LINKED_APPS=OFF \
..
make -j4 && sudo make install
2)build and install backward-cpp
cd /tmp
git clone https://github.com/bombela/backward-cpp.git
cd backward-cpp
git checkout 5ffb2c879ebdbea3bdb8477c671e32b1c984beaa
mkdir build && cd build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
..
make -j4 && sudo make install
3)build and install Pangolin from source
cd /tmp
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
git checkout eab3d3449a33a042b1ee7225e1b8b593b1b21e3e
mkdir build && cd build
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DBUILD_EXAMPLES=OFF \
-DBUILD_PANGOLIN_DEPTHSENSE=OFF \
-DBUILD_PANGOLIN_FFMPEG=OFF \
-DBUILD_PANGOLIN_LIBDC1394=OFF \
-DBUILD_PANGOLIN_LIBJPEG=OFF \
-DBUILD_PANGOLIN_LIBOPENEXR=OFF \
-DBUILD_PANGOLIN_LIBPNG=OFF \
-DBUILD_PANGOLIN_LIBTIFF=OFF \
-DBUILD_PANGOLIN_LIBUVC=OFF \
-DBUILD_PANGOLIN_LZ4=OFF \
-DBUILD_PANGOLIN_OPENNI=OFF \
-DBUILD_PANGOLIN_OPENNI2=OFF \
-DBUILD_PANGOLIN_PLEORA=OFF \
-DBUILD_PANGOLIN_PYTHON=OFF \
-DBUILD_PANGOLIN_TELICAM=OFF \
-DBUILD_PANGOLIN_UVC_MEDIAFOUNDATION=OFF \
-DBUILD_PANGOLIN_V4L=OFF \
-DBUILD_PANGOLIN_ZSTD=OFF \
..
make -j4 && sudo make install
4)Install Protobuf
apt install -y libprotobuf-dev protobuf-compiler
1.4 源码编译
在支持 PangolinViewer 的情况下构建时,请指定以下 cmake 选项:-DUSE_PANGOLIN_VIEWER=ON和-DUSE_SOCKET_PUBLISHER=OFF.
cd /path/to/stella_vslam
mkdir build && cd build
cmake \
-DUSE_STACK_TRACE_LOGGER=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DUSE_PANGOLIN_VIEWER=ON \
-DINSTALL_PANGOLIN_VIEWER=ON \
-DUSE_SOCKET_PUBLISHER=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_EXAMPLES=ON \
..
make -j4 && sudo make install
编译成功后的显示为:
1.5 运行
# download an ORB vocabulary from GitHub
curl -sL "https://github.com/stella-cv/FBoW_orb_vocab/raw/main/orb_vocab.fbow" -o orb_vocab.fbow
# download a sample dataset from Google Drive
FILE_ID="1d8kADKWBptEqTF7jEVhKatBEdN7g0ikY"
curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=${FILE_ID}" > /dev/null
CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
curl -sLb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=${FILE_ID}" -o aist_living_lab_1.zip
unzip aist_living_lab_1.zip
# download a sample dataset from Google Drive
FILE_ID="1TVf2D2QvMZPHsFoTb7HNxbXclPoFMGLX"
curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=${FILE_ID}" > /dev/null
CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
curl -sLb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=${FILE_ID}" -o aist_living_lab_2.zip
unzip aist_living_lab_2.zip
# run tracking and mapping
./run_video_slam -v ./orb_vocab.fbow -m ./aist_living_lab_1/video.mp4 -c ../example/aist/equirectangular.yaml --frame-skip 3 --no-sleep --map-db-out map.msg
# click the [Terminate] button to close the viewer
# you can find map.msg in the current directory
# run localization
./run_video_slam --disable-mapping -v ./orb_vocab.fbow -m ./aist_living_lab_2/video.mp4 -c ../example/aist/equirectangular.yaml --frame-skip 3 --no-sleep --map-db-in map.msg
我使用的是视频进行测试的:
./run_video_slam -v /home/nvidia/XXX/stella_vslam/orb_vocab.fbow -m /home/nvidia/XXX/stella_vslam/data/aist_entrance_hall_1/video.mp4 -c /home/nvidia/XXX/stella_vslam/example/aist/equirectangular.yaml --frame-skip 3 --no-sleep --map-db-out map.msg
运行过程中会报错误:
./run_video_slam: error while loading shared libraries: libg2o_csparse_extension.so: cannot open shared object file: No such file or directory
解决办法:
在终端直接导入库所在的位置:
export LD_LIBRARY_PATH=/home/nvidia/XXX/g2o/lib:$LD_LIBRARY_PATH
或者在配置文件中写入:
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
数据集的下载直接可以在网页中下载:
Simple Tutorial — stella_vslam documentation
运行的结果如图所示:
上述所有搭建环境的依赖包,可以到下面的链接中下载:
https://download.csdn.net/download/YOULANSHENGMENG/87631603
二、ROS 环境下的安装
Ubuntu 20.04. ros noetic
安装ROS版本的前提是先装好ROS和文章上述第一部分的源码。
2.1 安装基础依赖包
1)
sudo apt update -y
sudo apt install ros-noetic-image-transport
2)
git clone --branch noetic --depth 1 https://github.com/ros-perception/vision_opencv.git
cp -r vision_opencv/cv_bridge ~/catkin_ws/src
rm -rf vision_opencv
3)下拉ROS版本的源码
cd ~/catkin_ws/src
git clone --branch ros --depth 1 https://github.com/stella-cv/stella_vslam_ros.git
cd stella_vslam_ros
git submodule update --init --recursive
cd ~/catkin_ws
catkin_make -DUSE_PANGOLIN_VIEWER=ON -DUSE_SOCKET_PUBLISHER=OFF
编译过程中,出现下面的错误,从网上找到原因是G20的版本不兼容导致的。所以需要确定官方使用的版本是什么版本。
下载最新版本的g20,但是提示eigen库版本过低,卸载和升级eigen版本的方法为:eigen下载的网站为:Eigen
1)卸载
sudo updatedb
locate eigen3sudo 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.md5sums2)查看查看自己的Eigen版本
sudo gedit /usr/include/eigen3/Eigen/src/Core/util/Macros.h
在这个文件开头有如下代表版本为3.3.3#define EIGEN_WORLD_VERSION 3
#define EIGEN_MAJOR_VERSION 3
#define EIGEN_MIINOR_VERSION 33)安装
sudo tar -xvzf eigen-3.4.0.tar.gz
cd eigen-3.4.0
sudo mkdir build
cd buildsudo cmake ..
sudo make install
sudo cp -r /usr/local/include/eigen3 /usr/include
重新编译g20后,重新编译ros版本的
参考链接为:
ROS Package — stella_vslam documentation
运行:
1)发布数据基于视频的方法
rosrun image_publisher image_publisher ./aist_living_lab_1/video.mp4 /image_raw:=/camera/image_raw
2)发布数据基于一般摄像头的
apt install ros-${ROS_DISTRO}-usb-cam
rosparam set usb_cam/pixel_format yuyv
rosrun usb_cam usb_cam_node
rosrun image_transport republish \
raw in:=/usb_cam/image_raw raw out:=/camera/image_raw
3)运行(Tracking and Mapping 源码位置:stella_vslam_ros/src/run_slam.cc)
source ~/catkin_ws/devel/setup.bash
rosrun stella_vslam_ros run_slam \
-v /path/to/orb_vocab.fbow \
-c /path/to/config.yaml \
--map-db-out /path/to/map.msg
4)运行(Localization 源码位置:stella_vslam_ros/src/run_slam.cc)
source ~/catkin_ws/devel/setup.bash
rosrun stella_vslam_ros run_slam \
--disable-mapping \
-v /path/to/orb_vocab.fbow \
-c /path/to/config.yaml \
--map-db-in /path/to/map.msg
我运行的命令的记录:
rosrun stella_vslam_ros run_slam -v /home/nvidia/XXX/stella_vslam/orb_vocab.fbow -c /home/nvidia/XXX/stella_vslam/example/aist/equirectangular.yaml --map-db-out map.msg
但是运行后,没有结果输出,查询是使用下面的语句是没有办法发出/camera/image_raw话题的内容的。实际发出的话题中视没有/image_raw这个话题的,且每次运行publisher发出来的话题后面的ID是个变化的,导致使用固定的映射是不行的。
rosrun image_publisher image_publisher video.mp4 /image_raw:=/camera/image_raw
解决该问题,记录一些对话题的处理方法:
1)将图像更改为话题发布出去
roscore
rosrun image_publisher image_publisher /opt/ros/melodic/share/rviz/images/splash.png
2)播放bag包,将指定的话题进行新话题名的映射
rosbag play 2023-03-15-19-28-26.bag /camera/infra1/image_rect_raw:=/camera/image_raw
3)显示图像的话题
rosrun image_view image_view image:=/image_publisher_1603025741590002479/image_raw
4)读取视频
rosrun image_publisher image_publisher /xxx/1.mp4
5)读取摄像头数据,将参数改为摄像头设备号或者设备文件,执行以下指令:
rosrun image_publisher image_publisher 0
与以下指令等价:
rosrun image_publisher image_publisher /dev/video0
解决办法:
将视频发布的话题录制成bag 包。然后再进行播放。