在ROS下使用摄像头调试ORB-SLAM2

摄像头驱动安装

先安装显示工具:

sudo apt-get update
sudo apt-get install ros-indigo-image-view, v4l-utils

然后安装驱动;

sudo apt-get update
sudo apt-get install ros-indigo-image-view, v4l-utils

cd ~/catkin_ws/src
git git clone https://github.com/bosch-ros-pkg/usb_cam.git
cd ..
catkin_make
source ~/catkin-ws/devel/setup.bash

进入~/catkin-ws/usb_cam/src/usb_cam/launch/usb_cam-test.launch,以usb_cam-test.launch为参考新建usb_cam.launch,修改里面内容(主要是video_device的值):

<launch>
<node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
<param name="video_device" value="/dev/video0" />
<param name="image_width" value="640" />
<param name="image_height" value="480" />
<param name="pixel_format" value="yuyv" />
<param name="camera_frame_id" value="usb_cam" />
<param name="io_method" value="mmap"/>
</node>
<node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
<remap from="image" to="/usb_cam/image_raw"/>
<param name="autosize" value="true" />
</node>
</launch>

现在一个新窗口运行roscore。 然后在另外一个新窗口:

cd ~/catkin_ws/
source devel/setup.sh
roslaunch usb_cam usb_cam.launch

安装ORB-SLAM2

sudo apt-get install libblas-dev
sudo apt-get install liblapack-dev

git clone https://github.com/raulmur/ORB_SLAM2.git
cd ORB_SLAM2
chmod +x build.sh
./build.sh
cd ~
sudo gedit .bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS

其中PATH/ORB_SLAM2/Examples/ROS为你的实际位置(如/home/luohanjie/SLAM/Code/slam_catkin_ws/src/ORB_SLAM2/Examples/ROS)。

ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_mono.cc中某代码修改为:

ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);
cd PATH/ORB_SLAM2/Examples/ROS/ORB_SLAM2
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make -j

运行

打开一个窗口运行roscore 然后在另外一个新窗口:

cd ~/catkin_ws/
source devel/setup.sh
roslaunch usb_cam usb_cam.launch

然后在另外一个新窗口:

cd ~/catkin_ws/
source devel/setup.sh
rosrun ORB_SLAM2 Mono PATH_TO_VOCABULARY PATH_TO_SETTINGS_FILE

PATH_TO_VOCABULARY是词典的位置,PATH_TO_SETTINGS_FILE是摄像头标定的yaml文件。

如:

rosrun ORB_SLAM2 Mono /home/luohanjie/SLAM/Code/slam_catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/luohanjie/SLAM/Code/slam_catkin_ws/src/usb_cam/calib/camera_slam.yml
rosrun ORB_SLAM2 Mono /home/luohanjie/SLAM/Code/catkin_ws_orbslam_loadmap/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/luohanjie/SLAM/Code/catkin_ws_orbslam_loadmap/src/usb_cam/calib/camera_slam.yml