用KinectV2+ROS跑通ORB-SLAM
阿新 • • 發佈:2018-11-17
更多:請檢視~/ORB_SLAM2/REAME.md
首先感謝高博分享的基本流程https://www.cnblogs.com/gaoxiang12/p/5161223.html該流程是在自己試坑後做出的總結
1.編譯執行Kinect2
cd ~/catkin_ws
catkin_make -DCMAKE_BUILD_TYPE="Release"
roslaunch kinect2_bridge kinect2_bridge.launch
2.下載ORB_SLAM2並做適當改動
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
改動1main函式
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/camera/rgb/image_raw", 1);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "camera/depth_registered/image_raw", 1);
改成:
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "yourtopic", 1);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "yourtopic", 1);
這裡的yourtopic是按照下文rostopic list查到的/kinect2/hd/image_color_rect和/kinect2/hd/image_depth_rect修改儲存
//因為kinect釋出的topic改變了,不是程式中預設的,所以需要改動,在啟動
roslaunch kinect_bridge kinect_bridge.launch 後,執行rostopic list,檢視釋出的話題,本文為:
"/kinect2/hd/image_color"和"kinect2/hd/image_depth_rect"
改動2
$ sudo gedit ~/.bashrc
把路徑export ROS_PACKAGE_PATH = $ROS_PACKAGE_PATH:/home/junwang/ORB_SLAM2/Examples/ROS加進去,
$ source ~/.bashrc//報錯bash: export: `.......': 不是有效的識別符號,並且還是找不對目錄。
再嘗試
$ sudo gedit /opt/ros/indigo/setup.sh
最後加export ROS_PACKAGE_PATH = $ROS_PACKAGE_PATH:/home/junwang/ORB_SLAM2/Examples/ROS$ source /opt/ros/indigo/setup.sh//成功
參考:https://blog.csdn.net/poulang5786/article/details/79150902
改動3:設定標定相機引數,仿照/Examples/RGB-D/TUM1.yaml並另存為kinect2.yaml,我自己的引數為:
%YAML:1.0
# Camera calibration and distortion parameters (OpenCV)Camera.fx: 1.0599465578241038e+03
Camera.fy: 1.0539326808799726e+03
Camera.cx: 9.5488326677588441e+02
Camera.cy: 5.2373858291060583e+02
Camera.k1: 5.6268441170930321e-02
Camera.k2: -7.4199141308694802e-02
Camera.p1: 1.4250797540545752e-03
Camera.p2: -1.6951722389720336e-03
Camera.k3: 2.4107681263086548e-02
Camera.width: 1920
Camera.height: 1080
參考:https://blog.csdn.net/rainvictor1/article/details/72854137
https://blog.csdn.net/qq_30356613/article/details/71075244
3.編譯ORB_SLAM2
cd ~/ORB_SLAM2
chmod +x build.sh
./build.sh
source /opt/ros/indigo/setup.sh
chmod +x build_ros.sh
./build_ros.sh
4.執行
cd ~/ORB_SLAM2/Examples/ROS
rosrun ORB_SLAM2 RGBD /home/junwang/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/junwang/ORB_SLAM2/Examples/RGB-D/kinect2.yaml
參考:https://www.cnblogs.com/bigzhao/p/6635770.html
5.彩蛋:MonoAR(注意:單目!開始平穩前後移動相機使其初始化,左下角顯示SLAM ON才可以再正常執行,跑Mono同理)
cd ~/catkin_ws/src/ORB_SLAM2
chmod +x build.sh
./build.sh
chmod +x build_ros.sh
./build_ros.sh
cd ~/catkin_ws/src/ORB_SLAM2/Examples/ROS
rosrun ORB_SLAM2 MonoAR /home/junwang/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/junwang/catkin_ws/src/ORB_SLAM2/Examples/Monocular/kinect2.yaml
#若將ORB_SLAM2安裝在catkin_ws/src下則不需要每次執行ros時都設定環境變數