DSO(Direct Sparse Odometry)是慕尼黑工业大学Engel于2016年发布在arXiv上的一种基于直接法,构建稀疏点云地图的视觉里程计。VSLAM中Direct Sparse Odometry(DSO)是业内很流行的lsd_slam系统作者的学生Jakob Engel开发的,实测性能和精度优于lsd_slam。DSO已经被作者开源到github,同时还一并开源了DSO在ros系统下的使用代码实例dso_ros.
操作系统:Ubuntu 16.04
下载源码
1. 当然,先下载源码:
$ git clone https://github.com/JakobEngel/dso.git
2. 安装相应的依赖项
$ sudo apt-get install libsuitesparse-dev libeigen3-dev libboost-all-dev
最好将ziplib装上(下载的源码里有安装包),因为在运行数据集的时候,可以直接读取.zip文件。在libzip解压文件下,敲下面几行命令:
$ ./configure
$ make
$ sudo make install
$ sudo cp lib/zipconf.h /usr/local/include/zipconf.h
3. 安装DSO,在dso文件下输入:
$ mkdir build
$ cd build
$ cmake ..
$ make -j
4. 启动数据集,在安装了OpenCV和Pangolin的前提下,在命令行输入:
$ ~/dso/build/bin/dso_dataset \
files=PATH/sequence_14/images.zip \
calib=PATH/sequence_14/camera.txt \
gamma=PATH/sequence_14/pcalib.txt \
vignette=PATH/sequence_14/vignette.png \
preset=0 \
mode=0
其中,PATH为自己放置sequence_14数据集的路径,运行的结果如下:
____________________________________________________________
安装dso:
1.首先安装相关依赖包(如果你没有安装的话):
➜ ~ sudo apt-get install libsuitesparse-dev libeigen3-dev libboost-dev
➜ ~ sudo apt-get install libopencv-dev
2. 下载dso包:
➜ ~ mkdir ~/dso_pkg
➜ dso_pkg git clone https://github.com/JakobEngel/dso.git
3 .根据DSO官方的要求是要配置Pangolin(用于3D可视化和GUI)和ziplib(用于读取图像为.zip的数据集):
安装zlibzp并编译dso
➜ ~ sudo apt-get install zlib1g-dev
➜ ~ cd ~/dso_pkg/dso/thirdparty
➜ thirdparty git:(master) tar -zxvf libzip-1.1.1.tar.gz
➜ thirdparty git:(master) cd libzip-1.1.1/
➜ libzip-1.1.1 git:(master) ./configure
➜ libzip-1.1.1 git:(master) make
➜ libzip-1.1.1 git:(master) sudo make install
➜ libzip-1.1.1 git:(master) sudo cp lib/zipconf.h /usr/local/include/zipconf.h
安装Pangolin
➜ ~ cd dso_pkg
➜ dso_pkg git clone https://github.com/stevenlovegrove/Pangolin.git
➜ ~ cd Pangolin
➜ Pangolin git:(master) mkdir build
➜ build git:(master) cd build
➜ build git:(master) cmake -DCPP11_NO_BOOST=1 ..
➜ build git:(master) make -j
————————————————
数据集
数据集:https://vision.in.tum.de/data/datasets/mono-dataset?redirect=1
在TUM单目数据集上运行DSO
下载TUM单目数据集请到https://vision.in.tum.de/data/datasets/mono-dataset?redirect=1下载你所需要的zip包,我下载的是sequence_14,根据需要自行下载。下载好把zip包放到dso的bin目录下并解压,我的是
➜ bin git:(master) pwd
/home/zpq/dso_pkg/dso/build/bin
➜ bin git:(master) unzip sequence_14.zip
在bin目录下运行启动数据集:
./dso_dataset files=./sequence_14/images.zip calib=./sequence_14/camera.txt gamma=./sequence_14/pcalib.txt vignette=./sequence_14/vignette.png preset=0 mode=0
运行成功啦
摄像头:笔记本摄像头
5.下面在线跑自己的摄像头,我们需要dso_ros (catkin版本),下载地址:https://github.com/JakobEngel/dso_ros/tree/catkin
此时需要电脑中安装了ROS,安装步骤可以参考:https://www.linuxidc.com/Linux/2019-03/157199.htm
将下载的文件放置在catkin_ws/src目录下,执行:
$ cd ~/catkin_ws
$ catkin_make
$ cd ./src/dso_ros
$ export DSO_PATH=PATH/dso
$ rosmake
一样的,PATH为自己安装dso的路径,注意是dso路径,不是dso_ros路径!!!
6. 在第一个终端中执行:
$ roscore
第二个终端,在usb_cam/lauch路径下执行:
roslaunch usb_cam usb_cam-test.launch
第三个终端就要执行runros操作了:
rosrun dso_ros dso_live image:=/usb_cam/image_raw calib=PATH/camera.txt mode=1
其中,PATH为自己的相机标定文件的路径。
不出意外,就能在线运行自己的摄像头了。
参考:https://github.com/JakobEngel/dso
——————————————————————————————————————
利用外接摄像头实时运行DSO
Engel同时发布了dso_ros,用ROS来实时获取图片,程序代码很简短,实际上它是作者提供的一个如何把DSO当做一个黑盒子来使用的样例。这里需要用到ros啦,没有装好ros系统的同学,可以先装好ros并搭建好一个工作空间,传送门https://blog.csdn.net/bflong/article/details/80936914,
第一个坑:原作者提供的源代码有两个分支,master分支对应rosbuild版,catkin分支对应catkin版。对于现代ROS版本,推荐使用catkin版本,安装使用更方便。但是作者的catkin分支存在代码缺陷,rosmake 找不到包,实际无法安装使用,这让是人百思不得其解,之后我就查了好多的资料,绝大数的都不适用,也许是我的版本配置的问题吧,最后我找到蓝鲸智能修改之后的dso_ros版本,终于是看到希望啦,真是谢谢大佬:https://blog.csdn.net/smilinglamb/article/details/80656872?utm_source=blogxgwz2
下载并编译
➜ ~ cd catkin_ws/src
➜ src git clone https://github.com/BlueWhaleRobot/dso_ros.git
➜ ~ cd ..
➜ catkin_ws export DSO_PATH=/home/zpq/dso_pkg/dso
➜ catkin_ws catkin_make
安装编译usb_cam
➜ ~ cd ~/catkin_ws/src
➜ src git clone https://github.com/bosch-ros-pkg/usb_cam.git
➜ catkin_ws cd ..
➜ catkin_ws catkin_make
➜ catkin_ws source ~/catkin_ws/devel/setup.bas
如果使用外接USB摄像头的话:修改launch中的usb_cam-test.launch的video0为video1就可以了
修改相机参数文件
➜ ~ gedit ~/catkin_ws/src/dso_ros/camera.txt
我的是(根据需求你们自行修改):
446.867338 446.958766 298.082779 234.334299 -0.324849 0.1205156 -0.000186 -0.000821
640 480
crop
640 480
运行dso_ros:
新开终端运行:roscore
再开一终端运行usb_cam:roslaunch usb_cam usb_cam-test.launch
再开一终端运行dso_live:rosrun dso_ros dso_live image:=/usb_cam/image_raw calib=/home/zpq/catkin_ws/src/dso_ros/camera.txt mode=1
第二个坑运行usb_cam时提示我的相机没有进行光度校准的,一般这个是不会影响我的dso_ros的运行,但是在后遇见的问题中我也不确定是否与这个问题有关,因此我查找了大量有关资料,终于找到一位大佬的博客解决的 传送门:https://blog.csdn.net/qq_25241325/article/details/82705003
第三个坑是我根据别人的运行启动dso_live的时候,我可以看我的rostopic ,导致我的imge view 设置错误,我的usb_cam的topic是/usb_cam 因此我的启动dso_live 的image参数是:rosrun dso_ros dso_live image:=/usb_cam/image_raw calib=/home/zpq/catkin_ws/src/dso_ros/camera.txt mode=1
1.DSO的安装
注:因为小强开发平台已经提前安装好了不少DSO需要的依赖包,下文将跳过这些包的安装,请其它开发平台的读者参考github上的完整安装教程进行安装。
1.A安装依赖包
-
sudo apt-get install libsuitesparse-dev libeigen3-dev libboost-dev
-
sudo apt-get install libopencv-dev
1.B下载源代码
-
cd ~/Documents/
-
git clone https://github.com/JakobEngel/dso.git
1.C继续配置依赖包
-
sudo apt-get install zlib1g-dev
-
cd ~/Documents/dso/thirdparty
-
tar -zxvf libzip-1.1.1.tar.gz
-
cd libzip-1.1.1/
-
./configure
-
make
-
sudo make install
-
sudo cp lib/zipconf.h /usr/local/include/zipconf.h
1.D编译安装
-
cd ~/Documents/dso/
-
mkdir build
-
cd build
-
cmake ..
-
make -j
2.dso_ros的安装
注:原作者提供的源代码有两个分支,master分支对应rosbuild版,catkin分支对应catkin版。对于现代ROS版本,推荐使用catkin版本,安装使用更方便。但是作者的catkin分支存在代码缺陷,实际无法安装使用,因此下文将安装我们蓝鲸智能修改之后的dso_ros版本。
-
cd ~/Documents/ros/src
-
git clone https://github.com/BlueWhaleRobot/dso_ros.git
-
cd ..
-
export DSO_PATH=/home/xiaoqiang/Documents/dso
-
catkin_make
3.开始使用
注:小强开发平台的摄像头标定文件是相同的,因此可以直接运行下列命令,请其它开发平台的读者自行修改camera.txt文件中的内容(留意每行的最后结尾不能有空格)以及命令中的image topic名字
rosrun dso_ros dso_live image:=/camera_node/image_raw calib=/home/xiaoqiang/Documents/ros/src/dso_ros/camera.txt mode=1
现在移动摄像头,就能开始对周围环境进行三维建模,移动过程避免急转弯和剧烈运动。对于小强用户,请先遥控小强运动同时用rosbag录制/camera_node/image_raw这个image topic数据,然后重放,这样可以实现大范围的建模。rosbag重放前,需要关闭usb摄像头节点(sudo service startup stop),否则会有图像发布冲突。