一、安装ROS
建议按照官网操作
cn/melodic/Installation/Ubuntu - ROS Wikihttp://wiki.ros.org/cn/melodic/Installation/Ubuntu
二、安装eigen3.3.7
Releases · libeigen / eigen · GitLabEigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.https://gitlab.com/libeigen/eigen/-/releases
找到3.3.7下载源码压缩包,然后解压,进入eigen文件夹
mkdir build && cd build
cmake ..
make
sudo make install
sudo cp -r /usr/local/include/eigen3/Eigen/ /usr/local/include/
三、安装pangolin-0.5
主要参考ubuntu18.04下 安装SLAM-Pangolin(亲测有效)_清虞的博客-CSDN博客_ubuntu安装pangolin首先安装Pangolin所需依赖sudo apt install libgl1-mesa-devsudo apt install libglew-devsudo apt install cmakesudo apt install libpython2.7-devsudo apt install python-pipsudo python -mpip install numpy pyopengl Pillow pybind11sudo apt install pkg-configsudohttps://blog.csdn.net/qq_43647590/article/details/120226747?ops_request_misc=&request_id=&biz_id=102&utm_term=SLAM-Pangolin&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-6-120226747.142%5Ev30%5Econtrol,185%5Ev2%5Econtrol&spm=1018.2226.3001.4187
GitHub - stevenlovegrove/Pangolin: Pangolin is a lightweight portable rapid development library for managing OpenGL display / interaction and abstracting video input.Pangolin is a lightweight portable rapid development library for managing OpenGL display / interaction and abstracting video input. - GitHub - stevenlovegrove/Pangolin: Pangolin is a lightweight portable rapid development library for managing OpenGL display / interaction and abstracting video input.https://github.com/stevenlovegrove/Pangolin
sudo apt install libgl1-mesa-dev
sudo apt install libglew-dev
sudo apt install cmake
sudo apt install libpython2.7-dev
sudo apt install python-pip
sudo python -mpip install numpy pyopengl Pillow pybind11
sudo apt install pkg-config
sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols
sudo apt install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev
sudo apt install libdc1394-22-dev libraw1394-dev
sudo apt install libjpeg-dev libpng-dev libtiff5-dev libopenexr-dev
然后编译
mkdir build && cd build
cmake ..
make
sudo make install
#然后验证
cd ~/Pangolin/build/examples/HelloPangolin
./HelloPangolin
四、安装opencv3.4.5+contrib3.4.5
主要参考
ubuntu 18.04 配置opencv3.4.5+contrib_钦替的博客-CSDN博客一 文件准备去opencv官网下载opencv-3.4.5,你也可以选择其他版本,但是opencv的版本必须和opencv_contrib版本一致,官网地址:opencv官网,选择对应版本的Sources文件如下图所示,接下来下载opencv_contrib-3.4.5,链接:opencv_contrib-3.4.5具体文件如下图,其中zip格式或tar.gz格式选择一个下载即可。二 命...https://blog.csdn.net/weixin_45117253/article/details/103861245
Releases - OpenCVhttps://opencv.org/releases/
https://github.com/opencv/opencv_contrib/tagshttps://github.com/opencv/opencv_contrib/tags
分别找到3.4.5下载source压缩包,安装依赖
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt-get install qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen openjdk-8-jdk pylint libvtk6-dev
sudo apt-get install pkg-config
sudo apt-get install libtiff5-dev libswscale-dev
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
sudo apt install cmake-qt-gui
解压缩opencv,然后把解压缩的contrib文件夹重命名为opencv_contrib复制到opencv文件夹中
我们这里采用cmake-gui的方式
cd opencv-3.4.5
mkdir build && cd build
cmake-gui
一开始打开是空白的,我们填入源码地址,以及build地址,然后点击configure
需要注意几个地方
然后点击Generate,这一步相当于cmake,下面这个也可以。
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv-3.4.5/opencv_contrib-3.4.5/modules/ -DOPENCV_ENABLE_NONFREE=True ..
中间会因为网络原因而无法下载,解决方案有很多,就不阐述了,直接上链接
一次性解决opencv源码安装文件下载问题:ippicv_2017u3_lnx, face_landmark_model.dat, tiny-dnn_虎啊虎啊里的博客-CSDN博客
cd build
sudo make -j8
sudo make install
然后配置环境
sudo gedit /etc/ld.so.conf.d/opencv.conf
末尾加入
/usr/local/lib
运行
sudo ldconfig
sudo gedit /etc/bash.bashrc
#末尾加入
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
#保存退出
source /etc/bash.bashrc
sudo updatedb
五、ORB-SLAM3编译
GitHub - UZ-SLAMLab/ORB_SLAM3: ORB-SLAM3: An Accurate Open-Source Library for Visual, Visual-Inertial and Multi-Map SLAMORB-SLAM3: An Accurate Open-Source Library for Visual, Visual-Inertial and Multi-Map SLAM - GitHub - UZ-SLAMLab/ORB_SLAM3: ORB-SLAM3: An Accurate Open-Source Library for Visual, Visual-Inertial and Multi-Map SLAMhttps://github.com/UZ-SLAMLab/ORB_SLAM3
由于这里ros安装了一个opencv3.2.0,我们又安装了opencv3.4.5,所以会有cv_bridge的问题
除了将cmakelist中opencv都改为3.4.5,还有set(cv_bridge路径),参考另一篇博客
Ubuntu18.04 ROS Melodic的cv_bridge指向问题_XiangrongZ的博客-CSDN博客由于ROS Melodic自带的是Opencv3.2.0,而我自己下载的是opencv3.4.5,所以需要将cv_bridge的指向改为我自己安装的opencv。https://blog.csdn.net/llllldm/article/details/126334841然后编译即可,注意编译之前进入build.sh文件,把make -j都改为make -j8
cd ORB-SLAM3/
chmod +x build.sh
./build.sh
cd Examples/ROS/ORB_SLAM3/src
修改对应你要运行文件里的话题,这里以ros_stereo_inertial.cc为例
因为我这里需要跟airsim连接,所以我要将左右目以及IMU话题修改进去。
ros::Subscriber sub_imu = n.subscribe("/airsim_node/drone_1/imu/imu", 1000, &ImuGrabber::GrabImu, &imugb);
ros::Subscriber sub_img_left = n.subscribe("/airsim_node/drone_1/front_left/Scene", 100, &ImageGrabber::GrabImageLeft,&igb);
ros::Subscriber sub_img_right = n.subscribe("/airsim_node/drone_1/front_right/Scene", 100, &ImageGrabber::GrabImageRight,&igb);
保存退出,然后返回最开始的ORB-SLAM3文件夹,注意编译之前进入build_ros.sh文件,把make -j都改为make -j8
cd ORB-SLAM3
chmod +x build_ros.sh
./build_ros.sh
六、ROS下运行
kmavvisualinertialdatasets – ASL Datasetshttps://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets#downloads在官网中下载MH01的ROS bag
返回ORB-SLAM3的上一级目录,在终端一中
rosrun ORB_SLAM3 Stereo_Inertial $PWD/ORB_SLAM3-0.4-beta/Vocabulary/ORBvoc.txt $PWD/ORB_SLAM3-0.4-beta/Examples/Stereo-Inertial/EuRoC.yaml true
这里有人最后面不是true,是1或者do_rectify [do_equalize],我试着运行了,但是提取的特征点特别少,地图也会跟丢。
在终端二中
rosbag play -q MH_01_easy.bag /cam0/image_raw:=/airsim_node/drone_1/front_left/Scene /cam1/image_raw:=/airsim_node/drone_1/front_right/Scene /imu0:=/airsim_node/drone_1/imu/imu
-q是为了不要在终端显示运行rosbag的时间戳。
运行结果: