Kinect2 runs RGB-D interface under orb slam2 through ROS

Keywords: Linux Ubuntu github OpenCV

Written in front

In the last article, I recorded the driver of Kinect2 installed in Ubuntu and the bridge running in ROS. Now I can't wait to run the RGB-D interface under ORB-SLAM2.

Modify ORB-SLAM2

After installing the Kinect2 driver, execute:

roslaunch kinect_bridge kinect_bridge.launch

Then execute the following command to query the topics released by ROS

rostopic list

The topics are as follows:

/kinect2/bond
/kinect2/hd/camera_info
/kinect2/hd/image_color
/kinect2/hd/image_color/compressed
/kinect2/hd/image_color_rect
/kinect2/hd/image_color_rect/compressed
/kinect2/hd/image_depth_rect
/kinect2/hd/image_depth_rect/compressed
/kinect2/hd/image_mono
/kinect2/hd/image_mono/compressed
/kinect2/hd/image_mono_rect
/kinect2/hd/image_mono_rect/compressed
/kinect2/hd/points
/kinect2/qhd/camera_info
/kinect2/qhd/image_color
/kinect2/qhd/image_color/compressed
/kinect2/qhd/image_color_rect
/kinect2/qhd/image_color_rect/compressed
/kinect2/qhd/image_depth_rect
/kinect2/qhd/image_depth_rect/compressed
/kinect2/qhd/image_mono
/kinect2/qhd/image_mono/compressed
/kinect2/qhd/image_mono_rect
/kinect2/qhd/image_mono_rect/compressed
/kinect2/qhd/points
/kinect2/sd/camera_info
/kinect2/sd/image_color_rect
/kinect2/sd/image_color_rect/compressed
/kinect2/sd/image_depth
/kinect2/sd/image_depth/compressed
/kinect2/sd/image_depth_rect
/kinect2/sd/image_depth_rect/compressed
/kinect2/sd/image_ir
/kinect2/sd/image_ir/compressed
/kinect2/sd/image_ir_rect
/kinect2/sd/image_ir_rect/compressed
/kinect2/sd/points
/rosout
/rosout_agg

Use / kinect2 / QHD / image? Color and / kinect2 / QHD / image? Depth? Rect here.
Open orb? Slam2 / example / ROS / orb? Slam2 / SRC / ROS? Rgbd.cc, and modify the corresponding statement to:

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);

 

2. Kinect 2 Calibration

Reference resources https://github.com/code-iai/iai_kinect2/tree/master/kinect2_calibration#calibrating-the-kinect-one Calibrate Kinect2, obtain the internal distortion coefficient, and create kinect2.yaml under Examples/RGB-D /. Refer to Examples/RGB-D/TUM1.yaml, and modify the corresponding parameters.

# Camera calibration and distortion parameters (OpenCV) 
Camera.fx: 1050.6
Camera.fy: 1051.3
Camera.cx: 938.0
Camera.cy: 554.4

Camera.k1: 0.0
Camera.k2: 0.0
Camera.p1: 0.0
Camera.p2: 0.0

Camera.width: 1920
Camera.height: 1080
# Camera frames per second 
Camera.fps: 30.0

Finally, execute the following command to start ORB-SLAM2.

rosrun ORB_SLAM2 RGBD  Vocabulary/ORBvoc.txt Examples/RGB-D/kinect2.yaml

3. Compile the build ros.sh script file

Configure the ROS package path environment variable

source ~/.zshrc

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/xuzifeng/ORB_SLAM2/Examples/ROS

 

 

Enter the orb slam2 main path to compile the ros node:

chmod +x build_ros.sh

./build_ros.sh

 

To ensure that the original program can be compiled, I encountered the following problems during the compilation phase:

/usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'

-The reason for the error is: libboost? System.so and libboost? Filesystem.so cannot find the linked directory

-The solution is:

locate boost_system

//Directory found

/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

 

locate boost_filesystem

 

//Directory found

/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

 

 

Copy libboost ﹣ system.so and libboost ﹣ filesystem.so to orb ﹣ slam2 / lib, and add the stock in directory to Cmakelists.txt under orb ﹣ slam2 / examples / ROS / orb ﹣ slam2. Before modification, it is as follows:

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
)

 

 

After that, add - lboost Gu system, and modify 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
-lboost_system
)

4. Recompile project

//Recompile project
chmod +x build_ros.sh
./build_ros.sh

Compilation succeeded!! The next step is to start the driver and bridge of Kinect 2 and run Examples/ROS/RBGD

5. Operation procedure

Open a terminal and run:

roscore
//Open a new terminal. I have set the starting path of ROS here. I don't need source devel/setup.sh
roslaunch kinect2_bridge kinect2_bridge.launch

Then cd to orb slam2 / examples / ROS / orb slam2 path to open a new terminal input:

rosrun ORB_SLAM2 RGBD /home/xuzifeng/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/xuzifeng/ORB_SLAM2/Examples/RGB-D/kinect2.yaml

Run successfully!!!

 

Posted by potatoCode on Tue, 17 Dec 2019 14:05:40 -0800