Docker下运行ORB-Slam2

1 硬件介绍

主机:
–系统:ubuntu 18.04
–显卡:NVIDIA GeForce GT 1030 驱动版本:470.86

2 软件安装:

2.1 docker

参考:https://docs.docker.com/engine/install/ubuntu/

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo docker run hello-world # check docker installed success
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world # Verify that you can run docker commands without sudo

2.2 gpu驱动安装

# 使用下面命令查看ubuntu推荐的驱动
ubuntu-drivers devices
# 安装推荐的驱动
sudo apt install nvidia-driver-470

2.3 libnvidia-container

参考:
https://nvidia.github.io/libnvidia-container/
https://www.cnblogs.com/journeyonmyway/p/11234572.html

DIST=$(. /etc/os-release; echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/libnvidia-container/gpgkey | \
  sudo apt-key add -
curl -s -L https://nvidia.github.io/libnvidia-container/$DIST/libnvidia-container.list | \
  sudo tee /etc/apt/sources.list.d/libnvidia-container.list
sudo apt-get update
sudo apt-get install nvidia-container-toolkit
sudo apt-get install libnvidia-container-tools
sudo systemctl restart docker
docker run --gpus all nvidia/cuda:9.0-base nvidia-smi # check nvidia container installed success

2.4 orbslam2的导入

  • 宿主机软件安装:
sudo apt install  libglew-dev
sudo apt install libglu1-mesa-dev
  • orbslam2 docker项目
    继承:
    https://gitee.com/wycan/orbslam2_runin_docker
    修改:
    https://gitee.com/feisonzl/orbslam2_runin_docker/commit/93a6d266c4ddc2c067a3a6cd786f13e88cb10470

这里主要是坑在运行pangolin的时候,会出现:

libGL error: No matching fbConfigs or visuals found
libGL error: failed to load driver: swrast
X11 Error: BadMatch (invalid parameter attributes)
X11 Error: BadValue (integer parameter out of range for operation)
terminate called after throwing an instance of 'std::runtime_error'
what(): Pangolin X11: Failed to create an OpenGL context
Aborted (core dumped)

导致coredump
最后通过添加宿主机的库路径解决:

"-v", "/usr/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu",

不过需要在宿主机上安装 libglew-dev libglu1-mesa-dev才能解决,否则slam工程无法编译通过

3.小结

本次在docker中成功运行ORB-SLAM2,历经坎坷,自己本身在工作,林林总总花了两个周末才最终run起来,感谢各路大神提供的文章,也希望给需要的小伙伴一些参考

你可能感兴趣的:(Docker,ORB-SLAM2,docker,ubuntu)