https://blog.csdn.net/learning_tortosie/article/details/81157805
安装Kinect2驱动
参考:https://blog.csdn.net/learning_tortosie/article/details/81151128
安装ORB-SLAM2
参考:https://blog.csdn.net/learning_tortosie/article/details/79881165
因为要使用ROS,所以要进行到编译ROS下的ORB-SLAM2。
3.1 首先安装必要的依赖
(1)更新apt库,更新软件列表
$ sudo apt-get update
- 1
(2)安装git,用于从Github上克隆项目到本地
$ sudo apt-get install git
- 1
(3)安装cmake,用于程序的编译
$ sudo apt-get install cmake
- 1
(4)安装Pangolin 作为可视化和用户界面
a. 安装依赖项
$ sudo apt-get install libglew-dev libpython2.7-dev
- 1
b. 从Github将项目下载到本地
$ git clone https://github.com/stevenlovegrove/Pangolin.git
c. 编译安装
$ cd Pangolin
$ mkdir build
$ cd build
$ cmake ..
$ make –j
$ sudo make install
- (5)安装OpenCV ,用于处理图像和特征
要求版本最低为2.4.3,并在OpenCV 2.4.11和OpenCV 3.2上做了测试。
注意:这里的版本问题非常重要,不同的版本号可能会不兼容,会出现各种错误,只能重新编译,对没有经验的开发者还会花费大量的时间寻找错误和解决问题。
在本次实验中,我首次使用的OpenCV 3.2,但是最后出现了错误,改用OpenCV 2.4.11后成功。
a. 安装依赖项
[compiler]
[required]
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional]
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
- 1
b. 在OpenCV官网(http://opencv.org)下载OpenCV 2.4.11的source版本,然后解压到本地
c. 编译安装
$ cd ~/opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=Release –D CMAKE_INSTALL_PREFIX=/usr/local ..
$ make –j8
$ sudo make install
编译过程会花费较长时间,电脑CPU性能较低的建议不要使用make -j
,容易卡死;CPU性能较高的可以使用make -jx
,x代表线程,可加速编译。
(6)安装Eigen3,它是一个开源线性库,可进行矩阵运算
$ sudo apt-get install libeigen3-dev
(7)安装DBoW2和g2o
DBoW2是DBow库的改进版本,DBow库是一个开源的C++库,用于索引图像并将其转换为单词表示形式。
g2o是一个开源的C ++框架,用于优化基于图的非线性误差函数。
这两个库在ORB-SLAM2项目的第三方文件夹中,在此不单独编译,后续统一编译。
(8)安装ORB-SLAM2
a. 克隆仓库
$ git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
b. 编译ORB-SLAM2,第三方库中的DBoW2和g2o,并解压ORB词典
$ cd ORB_SLAM2
$ chmod +x build.sh
$ ./build.sh
为了能够在线实时地运行ORB-SLAM2,需要借助ROS。关于ROS的安装,官网(http://wiki.ros.org/indigo/Installation/Ubuntu)有详细的安装教程,在此不再赘述。
本实验在上篇博客——摄像头图像信息的读取和显示的基础上进行开发,实现了摄像头数据的读取和显示,采集的图像数据可作为ORB-SLAM2系统的输入。
上篇博客创建了工作空间catkin_ws
,将ORB-SLAM2项目移动到其子文件夹src
下。
(1)将包含Examples/ROS/ORB_SLAM2
的路径添加到ROS_PACKAGE_PATH
环境变量中。打开.bashrc
文件并在最后添加以下行。
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS
- 1
其中PATH为ORB-SLAM2项目所在路径,我的路径为/home/wb/catkin_ws/src
。此外,还要在./bashrc
文件写入
source /home/wb/catkin_ws/devel/setup.sh
- 1
最后在终端执行命令
source ./bashrc
- 1
(2)编译ROS下的ORB-SLAM2
ORB-SLAM默认订阅的话题为/camera/image_raw
,而usb_cam
节点发布的话题为/usb_cam/image_raw
,因此需要在ros_mono.cc
中修改订阅的话题,这点要特别注意。因为源文件的更改必须要重新编译,这非常耗时。
$ chmod +x build_ros.sh
$ ./build_ros.sh
然后这里使用/kinect2/qhd/image_color
和/kinect2/qhd/image_depth_rect
。
打开ORB-SLAM2/Example/ROS/ORBSLAM2/src/ros_rgbd.cc
,将对应语句修改为:
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh,"/kinect2/qhd/image_color",1);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh,"/kinect2/qhd/image_depth_rect",1);
修改后执行./build_ros.bash
重新编译。
问题解决:参考https://blog.csdn.net/sinat_38343378/article/details/78883919
我在执行/build_ros.bash遇到如下报错:
/usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: undefined reference to symbol ‘_ZN5boost6system15system_categoryEv’
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/RGBD.dir/build.make:218: recipe for target ‘…/RGBD’ failed
make[2]: *** […/RGBD] Error 1
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/RGBD.dir/all’ failed
make[1]: *** [CMakeFiles/RGBD.dir/all] Error 2
make[1]: *** 正在等待未完成的任务…
/usr/bin/ld: CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: undefined reference to symbol ‘_ZN5boost6system15system_categoryEv’
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/Stereo.dir/build.make:218: recipe for target ‘…/Stereo’ failed
make[2]: *** […/Stereo] Error 1
CMakeFiles/Makefile2:104: recipe for target ‘CMakeFiles/Stereo.dir/all’ failed
make[1]: *** [CMakeFiles/Stereo.dir/all] Error 2
Makefile:127: recipe for target ‘all’ failed
make: *** [all] Error 2
- 出错原因为:libboost_system.so 与libboost_filesystem.so找不到链接目录
- 解决方案为
locate boost_system
//查找到目录
/usr/lib/x86_64-linux-gnu/libboost_system.a
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libboost_system.so.1.56.0
locate boost_filesystem
//查找到目录
/usr/lib/x86_64-linux-gnu/libboost_filesystem.a
/usr/lib/x86_64-linux-gnu/libboost_filesystem.so
/usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libboost_filesystem.so.1.56.0
将libboost_system.so与libboost_filesystem.so复制到ORB_SLAM2/lib下,并且将ORBSLAM2/Examples/ROS/ORBSLAM2下的Cmakelists.txt中加入库目录,具体为
在set(LIBS ${OpenCV_LIBS} ${EIGEN3_LIBS} ${Pangolin_LIBRARIES} ${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so ${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so ${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
之后加入${PROJECT_SOURCE_DIR}/../../../lib/libboost_filesystem.so ${PROJECT_SOURCE_DIR}/../../../lib/libboost_system.so
问题得以解决
[ 0%] Built target rospack_genmsg_libexe
[ 0%] Built target rosbuild_precompile
[ 11%] Linking CXX executable ../Mono
[ 22%] Linking CXX executable ../RGBD
[ 33%] Linking CXX executable ../Stereo
[ 44%] Linking CXX executable ../MonoAR
[ 55%] Built target Mono
[ 66%] Built target RGBD
[ 77%] Built target Stereo
[100%] Built target MonoAR
最后运行:
安装好Kinect2的驱动后,执行:
roslaunch kinect2_bridge kinect2_bridge.launch
参考https://github.com/code-iai/iai_kinect2/tree/master/kinect2_calibration#calibrating-the-kinect-one标定Kinect2,获取内参和畸变系数后,新建kinect2.yaml
,参照Examples/RGB-D/TUM1.yaml
,修改对应参数。
最后执行以下命令即可启动ORB-SLAM2。
cd ~/catkin_ws/src/ORB_SLAM2
rosrun ORB_SLAM2 RGBD Vocabulary/ORBvoc.txt Examples/RGB-D/kinect2.yaml