To capture point clouds and RGB data using Kinect V2 and save it in a Rosbag. It can be visualized in RVIZ and replay the bag. This procedure have been tested in Xbox One Kinect and Ubuntu 20.04.
In this procedure, you need to open several terminals. Always run the following command on each one:
source /opt/ros/noetic/setup.bash
In one terminal run:
roscore
In other terminal run:
rosrun rviz rviz
Keep this terminals open until the end of execution.
Most important topics are the following:
Rosbag are heavy files. For example 15 s of recording are equivalent to 3.5 Gb aproximately, make sure you have space available in your hard drive.
First, in new terminal, run the driver of kinect and start capture data using openni2:
roslaunch openni2_launch openni2.launch load_driver:=true
In this part, load_driver:=true
means that Kinect is going to capture data in real time, but is not keeping it in hard drive.
Now, go to RVIZ window. At left side search for Fixed Frame
and choose camera_link
. Now, go add buttom at bottom and left side of the window and choose PointCloud2
. After this, go to the left side and look for PointCloud2, in Topic
select: /camera/depth_registered/points
and go to Style
and select Points
. In this moment, you should be visualizing a point cloud in the grid of RVIZ.
To record data, in a new terminal, is necessary to specify which topic you want to record. In order to get an RGB point cloud run the following command:
rosbag record camera/depth_registered/image_raw camera/depth_registered/camera_info camera/rgb/image_raw camera/rgb/camera_info camera/depth/points camera/depth_registered/points --limit=60 -O kinect
Is possible to specify capture time, in this case limit=60
is aproximately 16 s.
If execution does not stop, feel free to use ctrl+c to stop capture. This will not affect your data. This happens because of the limit in order to avoid an overflow.
To verify properties of your bag, for example size, topics, execution time, among others, just run the following command in any free terminal:
rosbag info kinect.bag
In this moment, your bag is ready to use.
Make sure roscore is running in one terminal
After recording data, you can replay it and visualize it in RVIZ. To do this, stop opennni2 terminal process, in the same terminal run this:
roslaunch openni2_launch openni2.launch load_driver:=false
All topics related to Kinect are up, but is not recording anything. This is necessary for RVIZ. Is possible that you have to reconfigure RVIZ again even relaunch it. Just repeat the steps of RVIZ configuration
that we explain before.
You can replay your bag using the following command:
rosbag play --clock kinect.bag
In this moment, you should be visualizing your point cloud in RVIZ. As an extra, in a new terminal, you can suscribe to one topic using the following command:
rostopic hz /camera/depth_registered/points
That is it. You have finished this tutorial and your bag is ready to send to ROS2.