准备工作:
安装 ros noetic/Installation/Ubuntu - ROS Wiki
安装 docker Ubuntu Docker 安装 | 菜鸟教程
note:
如果要制作 Ubuntu 16.04 下的 vins-fusion 镜像只需完全按照下面的步骤进行
如果要制作 Ubuntu 18.04 下的 vins-fusion 镜像只需将下面代码中出现的 kinetic 替换为melodic
创建工作目录
mkdir -r ~/catkin_ws/src/
cd ~/catkin_ws/src/
git clone https://github.com/HKUST-Aerial-Robotics/VINS-Fusion.git
进入 vins-fusion 的 docker 文件夹
cd ./VINS-Fusion/docker
替换 Dockerfile 文件内容替换为下面的代码,以制作 Ubuntu 16.04 下的 vins-fusion 镜像(只有第一行出现了 kinetic)
FROM ros:kinetic-perception
ENV CERES_VERSION="1.14.0"
ENV CATKIN_WS=/root/catkin_ws
# set up thread number for building
RUN if [ "x$(nproc)" = "x1" ] ; then export USE_PROC=1 ; \
else export USE_PROC=$(($(nproc)/2)) ; fi && \
apt-get update && apt-get install -y \
cmake \
libatlas-base-dev \
libeigen3-dev \
libgoogle-glog-dev \
libsuitesparse-dev \
python-catkin-tools \
ros-${ROS_DISTRO}-cv-bridge \
ros-${ROS_DISTRO}-image-transport \
ros-${ROS_DISTRO}-message-filters \
ros-${ROS_DISTRO}-tf && \
rm -rf /var/lib/apt/lists/* && \
# Build and install Ceres
git clone https://github.com/ceres-solver/ceres-solver.git && \
cd ceres-solver && \
git checkout tags/${CERES_VERSION} && \
mkdir build && cd build && \
cmake .. && \
make -j8 install && \
rm -rf ../../ceres-solver && \
mkdir -p $CATKIN_WS/src/VINS-Fusion/
# Copy VINS-Fusion
COPY ./ $CATKIN_WS/src/VINS-Fusion/
# use the following line if you only have this dockerfile
# RUN git clone https://github.com/HKUST-Aerial-Robotics/VINS-Fusion.git
# Build VINS-Fusion
WORKDIR $CATKIN_WS
ENV TERM xterm
ENV PYTHONIOENCODING UTF-8
RUN catkin config \
--extend /opt/ros/$ROS_DISTRO \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release && \
catkin build && \
sed -i '/exec "$@"/i \
source "/root/catkin_ws/devel/setup.bash"' /ros_entrypoint.sh
替换 Makefile 文件内容(出现两次 kinetic)
all: help
help:
@echo ""
@echo "-- Help Menu"
@echo ""
@echo " 1. make build - build all images"
# @echo " 1. make pull - pull all images"
@echo " 1. make clean - remove all images"
@echo ""
build:
@docker build --tag ros-kinetic:vins-fusion -f ./Dockerfile ..
clean:
@docker rmi -f ros-kinetic:vins-fusion
在 catkin_ws/src/VIN-Fusion/docker 的终端下进行编译,
make build
编译时间较长,请耐心等待,如果中途出现错误一般是网络问题,国外网站下载会比较慢,只需要重新执行编译命令即可,编译完成后 vins-fusion 镜像就制作完成了。
创建工作目录
mkdir -r ~/catkin_ws/src/
cd ~/catkin_ws/src/
git clone https://github.com/HKUST-Aerial-Robotics/VINS-Fusion.git
进入 vins-fusion 的 docker 文件夹
cd ./VINS-Fusion/docker
替换 Dockerfile 文件内容替换为下面的代码,注意noetic 用的是 python3,因此 python-catkin-tools应该替换为 pytho3-catkin-tools
FROM ros:noetic-perception
ENV CERES_VERSION="1.14.0"
ENV CATKIN_WS=/root/catkin_ws
# set up thread number for building
RUN if [ "x$(nproc)" = "x1" ] ; then export USE_PROC=1 ; \
else export USE_PROC=$(($(nproc)/2)) ; fi && \
apt-get update && apt-get install -y \
git \
cmake \
libatlas-base-dev \
libeigen3-dev \
libgoogle-glog-dev \
libsuitesparse-dev \
python3-catkin-tools \
ros-${ROS_DISTRO}-cv-bridge \
ros-${ROS_DISTRO}-image-transport \
ros-${ROS_DISTRO}-message-filters \
ros-${ROS_DISTRO}-tf && \
rm -rf /var/lib/apt/lists/* && \
# Build and install Ceres
git clone https://github.com/ceres-solver/ceres-solver.git && \
cd ceres-solver && \
git checkout tags/${CERES_VERSION} && \
mkdir build && cd build && \
cmake .. && \
make -j8 install && \
rm -rf ../../ceres-solver && \
mkdir -p $CATKIN_WS/src/VINS-Fusion/
# Copy VINS-Fusion
COPY ./ $CATKIN_WS/src/VINS-Fusion/
# use the following line if you only have this dockerfile
# RUN git clone https://github.com/HKUST-Aerial-Robotics/VINS-Fusion.git
# Build VINS-Fusion
WORKDIR $CATKIN_WS
ENV TERM xterm
ENV PYTHONIOENCODING UTF-8
RUN catkin config \
--extend /opt/ros/$ROS_DISTRO \
--cmake-args \
-DCMAKE_BUILD_TYPE=Release && \
catkin build && \
sed -i '/exec "$@"/i \
source "/root/catkin_ws/devel/setup.bash"' /ros_entrypoint.sh
替换 Makefile 文件内容(出现两次 kinetic)
all: help
help:
@echo ""
@echo "-- Help Menu"
@echo ""
@echo " 1. make build - build all images"
# @echo " 1. make pull - pull all images"
@echo " 1. make clean - remove all images"
@echo ""
build:
@docker build --tag ros-noetic:vins-fusion -f ./Dockerfile ..
clean:
@docker rmi -f ros-noetic:vins-fusion
在 catkin_ws/src/VIN-Fusion/docker 的终端下进行编译,
make build
开始制作 vins-fusion 镜像。
在第五步 vins-fusion 的编译步骤中会报错,原因是使用 ros:noetic-perception 镜像中 Ubuntu 20.04,而 Ubuntu 20.04 对应于 ros:noetic 版本,而 noetic 自带 opencv 4,但是vins-fuion用的版本 opencv 3,因此需要将其匹配,有两种方案:
(1)不推荐。下载并安装 opencv 3 (opencv 3.4.1),然后将 cv-bridge 桥接到自己安装的 opencv 3,使其适配 vins-fusion 代码。可以参考vins-fusion环境配置、安装与测试_vins fusion安装_6¿6的博客-CSDN博客
(2)推荐。修改 vins-fusion 代码,使其适配 opencv 4
在ubuntu20.04上配置VINS_Fusion(亲测有效,一应俱全)_Waygoer的博客-CSDN博客
考虑到算法也需要与时俱进,修改代码是后期必不可少的工作,因此这里我们采用第二种方案。
事实上只需替换 vins-fusion 中对应于 opencv 的部分即可。
在 catkin_ws/src/VIN-Fusion/ (必须在这个目录下,谨慎!)下打开终端调用如下命令
sed -i 's/CV_FONT_HERSHEY_SIMPLEX/cv::FONT_HERSHEY_SIMPLEX/g' `grep CV_FONT_HERSHEY_SIMPLEX -rl ./`
sed -i 's/CV_LOAD_IMAGE_GRAYSCALE/cv::IMREAD_GRAYSCALE/g' `grep CV_LOAD_IMAGE_GRAYSCALE -rl ./`
sed -i 's/CV_BGR2GRAY/cv::COLOR_BGR2GRAY/g' `grep CV_BGR2GRAY -rl ./`
sed -i 's/CV_RGB2GRAY/cv::COLOR_RGB2GRAY/g' `grep CV_RGB2GRAY -rl ./`
sed -i 's/CV_GRAY2RGB/cv::COLOR_GRAY2RGB/g' `grep CV_GRAY2RGB -rl ./`
sed -i '5a #include \
#include ' ./camera_models/include/camodocal/chessboard/Chessboard.h
sed -i '5i #include \
#include ' ./camera_models/include/camodocal/calib/CameraCalibration.h
其中前五行分别对应前面提到的三种错误,剩下的对应于还有一个问题是前面提到的 noetic 自带 opencv 4,但是vins-fuion用的版本 opencv 3,需要将其匹配的问题。
然后在 catkin_ws/src/VIN-Fusion/docker 的终端下重新编译,
make build
编译时间较长,请耐心等待,如果中途出现错误一般是网络问题,国外网站下载会比较慢,只需要重新执行编译命令即可,编译完成后 vins-fusion 镜像就制作完成了。
在第五步 vins-fusion 的编译步骤中会报错,错误大体为如下三种:
(1)编译报错 error: ‘CV_FONT_HERSHEY_SIMPLEX’ was not declared in this scope
解决方案:在文件中搜索 CV_FONT_HERSHEY_SIMPLEX 并替换成 cv::FONT_HERSHEY_SIMPLEX
(2)编译报错 error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
解决方案:在文件中搜索 CV_LOAD_IMAGE_GRAYSCALE 并替换成 cv::IMREAD_GRAYSCALE
(3)编译报错 error: ‘CV_BGR2GRAY’ was not declared in this scope
解决方案:在文件中搜索 CV_BGR2GRAY 并替换成 cv::COLOR_BGR2GRAY
此外: noetic 自带 opencv 4,但是vins-fuion用的版本 opencv 3,因此需要将其匹配。
在 Chessboard.h 头文件,地址如下
~/catkin_ws/src/VIN-Fusion/camera_models/include/camodocal/chessboard/Chessboard.h
添加两个头文件
#include
#include
在 CameraCalibration.h 头文件,地址如下
~/catkin_ws/src/VIN-Fusion/camera_models/include/camodocal/calib/CameraCalibration.h
添加两个头文件
#include
#include
解决方案中采用 grep 正则表达式指令和 sed指令完美解决了这些问题,不需要自己去一个个添加和替换,节省了不必要的重复劳动。
配套的运行方式见 Docker & VINS-Fusion 跑数据集_想要个小姑娘的博客-CSDN博客