How do I create a rosbag for multiple camera?

classic Classic list List threaded Threaded
7 messages Options
Lex
Reply | Threaded
Open this post in threaded view
|

How do I create a rosbag for multiple camera?

Lex
Hi! I am using two Kinect with RTAB-Map, I'm using the launch file that is included in the demo folder without any problem. But I want to be able to record the topics from my Kinect and play the data back; I modified the launch file to this: (basically removed the launch of freenect driver)
<launch>
   
  <!-- Multi-cameras demo with 2 Kinects -->
   <param name="use_sim_time" type="bool" value="True"/>



 <!-- Frames: Kinects are placed at 90 degrees, clockwise and 35.32 cm aside on Y axis -->
  <node pkg="tf2_ros" type="static_transform_publisher" name="base_to_camera1_tf"
      args="0.0 0.0 0.0 0.0 0.0 0.0 /base_link /camera1_link" />
  <node pkg="tf2_ros" type="static_transform_publisher" name="base_to_camera2_tf"
      args="0.0 0.3532 0.0 1.570796327 0.0 0.0 /base_link /camera2_link" />

 
  <!-- Publish tf for camera1 -->
  <include file="$(find rgbd_launch)/launch/kinect_frames.launch">
    <arg name="camera" value="camera1" />
  </include>

  <!-- Publish tf for camera2 -->
  <include file="$(find rgbd_launch)/launch/kinect_frames.launch">
    <arg name="camera" value="camera2" />
  </include>


   <!-- Choose visualization -->
   <arg name="rviz"       default="false" />
   <arg name="rtabmapviz" default="true" /> 
   
   <!-- ODOMETRY MAIN ARGUMENTS: 
        -"strategy"        : Strategy: 0=Frame-to-Map 1=Frame-to-Frame
        -"feature"         : Feature type: 0=SURF 1=SIFT 2=ORB 3=FAST/FREAK 4=FAST/BRIEF 5=GFTT/FREAK 6=GFTT/BRIEF 7=BRISK
        -"nn"              : Nearest neighbor strategy : 0=Linear, 1=FLANN_KDTREE, 2=FLANN_LSH, 3=BRUTEFORCE 
                             Set to 1 for float descriptor like SIFT/SURF                  
                             Set to 3 for binary descriptor like ORB/FREAK/BRIEF/BRISK  
        -"max_depth"       : Maximum features depth (m)  
        -"min_inliers"     : Minimum visual correspondences to accept a transformation (m)  
        -"inlier_distance" : RANSAC maximum inliers distance (m)  
        -"local_map"       : Local map size: number of unique features to keep track 
        -"odom_info_data"  : Fill odometry info messages with inliers/outliers data.
    -->
   <arg name="strategy"        default="0" />
   <arg name="feature"         default="6" />
   <arg name="nn"              default="3" />
   <arg name="max_depth"       default="4.0" />
   <arg name="min_inliers"     default="20" />
   <arg name="inlier_distance" default="0.02" />
   <arg name="local_map"       default="1000" />
   <arg name="odom_info_data"  default="true" />
   <arg name="wait_for_transform"  default="true" />
   
   <!-- sync rgb/depth images per camera -->
   <group ns="camera1">
    <node pkg="nodelet" type="nodelet" name="rgbd_sync" args="load rtabmap_ros/rgbd_sync camera1_nodelet_manager">
      <remap from="rgb/image"         to="rgb/image_rect_color"/>
      <remap from="depth/image"       to="depth_registered/image_raw"/>
      <remap from="rgb/camera_info"   to="rgb/camera_info"/>
     
    </node>
   </group>
   <group ns="camera2">
    <node pkg="nodelet" type="nodelet" name="rgbd_sync" args="load rtabmap_ros/rgbd_sync camera2_nodelet_manager">
      <remap from="rgb/image"         to="rgb/image_rect_color"/>
      <remap from="depth/image"       to="depth_registered/image_raw"/>
      <remap from="rgb/camera_info"   to="rgb/camera_info"/>

    </node>
   </group>
        
  <group ns="rtabmap">
  
    <!-- Odometry -->
    <node pkg="rtabmap_ros" type="rgbd_odometry" name="rgbd_odometry" output="screen">
      <remap from="rgbd_image0"       to="/camera1/rgbd_image/"/>
      <remap from="rgbd_image1"       to="/camera2/rgbd_image/"/>

	  
	  <param name="subscribe_rgbd"           type="bool"   value="true"/>
	  <param name="frame_id"                 type="string" value="base_link"/>
	  <param name="rgbd_cameras"             type="int"    value="2"/>
	  <param name="wait_for_transform"       type="bool"   value="$(arg wait_for_transform)"/>
	  <param name="Odom/Strategy"            type="string" value="$(arg strategy)"/> 
	  <param name="OdomF2M/BundleAdjustment" type="string" value="0"/> <!-- should be 0 for multi-cameras -->
	  <param name="Vis/EstimationType"      type="string" value="0"/> <!-- should be 0 for multi-cameras -->
	  <param name="Vis/FeatureType"         type="string" value="$(arg feature)"/> 
	  <param name="Vis/CorGuessWinSize"     type="string" value="0"/> 
	  <param name="Vis/CorNNType"           type="string" value="$(arg nn)"/>
	  <param name="Vis/MaxDepth"            type="string" value="$(arg max_depth)"/>  
	  <param name="Vis/MinInliers"          type="string" value="$(arg min_inliers)"/> 
	  <param name="Vis/InlierDistance"      type="string" value="$(arg inlier_distance)"/>       
      <param name="OdomF2M/MaxSize" type="string" value="$(arg local_map)"/> 
      <param name="Odom/FillInfoData"        type="string" value="$(arg odom_info_data)"/>   
    </node>
  
    <!-- Visual SLAM (robot side) -->
    <!-- args: "delete_db_on_start" and "udebug" -->
    <node name="rtabmap" pkg="rtabmap_ros" type="rtabmap" output="screen" args="--delete_db_on_start">
      <param name="subscribe_depth"  type="bool"   value="false"/>
      <param name="subscribe_rgbd"   type="bool"   value="true"/>
      <param name="rgbd_cameras"    type="int"    value="2"/>
	  <param name="frame_id"         type="string" value="base_link"/>
	  <param name="gen_scan"         type="bool"   value="true"/>
	  <param name="wait_for_transform" type="bool"   value="$(arg wait_for_transform)"/>
	  <param name="map_negative_poses_ignored" type="bool"   value="false"/>        
<!-- refresh grid map even if we are not moving-->
	  <param name="map_negative_scan_empty_ray_tracing" type="bool" value="false"/> <!-- don't fill empty space between the generated scans-->
	
      <remap from="rgbd_image0"       to="/camera1/rgbd_image/"/>
      <remap from="rgbd_image1"       to="/camera2/rgbd_image/"/>

      <param name="Grid/FromDepth"     type="string" value="false"/>
      <param name="Vis/EstimationType" type="string" value="0"/> <!-- should be 0 for multi-cameras -->
      <param name="Vis/MinInliers"     type="string" value="10"/>
      <param name="Vis/InlierDistance" type="string" value="$(arg inlier_distance)"/>


    </node>
  
    <!-- Visualisation RTAB-Map -->
    <node if="$(arg rtabmapviz)" pkg="rtabmap_ros" type="rtabmapviz" name="rtabmapviz" args="-d $(find rtabmap_ros)/launch/config/rgbd_gui.ini" output="screen">
      <param name="subscribe_depth"  type="bool"   value="false"/>
      <param name="subscribe_rgbd"   type="bool"   value="true"/>
      <param name="subscribe_odom_info" type="bool"   value="$(arg odom_info_data)"/>
      <param name="frame_id"            type="string" value="base_link"/>
      <param name="rgbd_cameras"       type="int"    value="2"/>
      <param name="wait_for_transform"  type="bool"   value="$(arg wait_for_transform)"/>
    
      <remap from="rgbd_image0"       to="/camera1/rgbd_image/"/>
      <remap from="rgbd_image1"       to="/camera2/rgbd_image/"/>

    </node>
  
  </group>
  
  <!-- Visualization RVIZ -->
  <node if="$(arg rviz)" pkg="rviz" type="rviz" name="rviz" args="-d $(find rtabmap_ros)/launch/config/rgbd.rviz"/>

</launch>
And I record the topics from my Kinect with this command:
rosbag record -O kinectBig /camera1/rgb/camera_info /camera1/depth_registered/image_raw  /camera1/rgb/image_rect_color  /camera2/rgb/camera_info /camera2/depth_registered/image_raw /camera2/rgb/image_rect_color
However I can't make this work, when I play the bag nothing happends, I can only make it work if I also record the topic /rgbd_image, but this topic should be created with the rgbd_sync node that is the launch right? Also I want to record the compressed topic to save bandwidth but I don't know if that is possible when recording the /rgbd_image topic directly like this:
rosbag record -O kinectBig /camera1/rgb/camera_info /camera1/depth_registered/image_raw /camera1/rgbd_image /camera1/rgb/image_rect_color  /camera2/rgb/camera_info /camera2/depth_registered/image_raw /camera2/rgbd_image /camera2/rgb/image_rect_color
(Also here I am recording information twice as far as I can understand)
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a rosbag for multiple camera?

Eric Schleicher
Might it have something to do with clock and ros param: use_sim_time when you're playing?

this might be helpful:
https://answers.ros.org/question/12577/when-should-i-need-clock-parameter-on-rosbag-play/
Lex
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a rosbag for multiple camera?

Lex
Yes! I set the use_sim_time to true. The thing that I do not understand is that if I also suscribe to the topics: /camera1/rgbd_image and /camera2/rgbd_image everythings works correctly but I don't undersant why do I have to suscribe to those topics since, as far as i know, those topics are created with the rgdb_sync in the launch file node using rgbd and depth.

The only thing that comes to my mind is that the rgbd_sync does not work with publishing the topics from a bag? But then how can I get the /cameraX/rgbd_image topic.
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a rosbag for multiple camera?

matlabbe
Administrator
Hi,

Can you do a rosbag info on your bag?
Lex
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a rosbag for multiple camera?

Lex
Hello! Sorry for the late response, here you go
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
lex@lex-MS-7816:~/tfg/TFG-2021-Kinect/bag$ rosbag info kinectBig.bag 
path:        kinectBig.bag
version:     2.0
duration:    4.4s
start:       May 19 2021 16:34:50.16 (1621434890.16)
end:         May 19 2021 16:34:54.53 (1621434894.53)
size:        384.1 MB
messages:    787
compression: none [394/394 chunks]
types:       sensor_msgs/CameraInfo [c9a58c1b0b154e0e6da7578cb991d214]
             sensor_msgs/Image      [060021388200f6f0f447d0fcd9c64743]
topics:      /camera1/depth_registered/image_raw   131 msgs    : sensor_msgs/Image     
             /camera1/rgb/camera_info              132 msgs    : sensor_msgs/CameraInfo
             /camera1/rgb/image_rect_color         131 msgs    : sensor_msgs/Image     
             /camera2/depth_registered/image_raw   131 msgs    : sensor_msgs/Image     
             /camera2/rgb/camera_info              131 msgs    : sensor_msgs/CameraInfo
             /camera2/rgb/image_rect_color         131 msgs    : sensor_msgs/Image
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a rosbag for multiple camera?

matlabbe
Administrator
I don't see a problem with the bag.

Based on your code above (setting nodelet as standalone because the camera nodelets don't exist with the rosbag):
<group ns="camera1">
    <node pkg="nodelet" type="nodelet" name="rgbd_sync" args="standalone rtabmap_ros/rgbd_sync">
      <remap from="rgb/image"         to="rgb/image_rect_color"/>
      <remap from="depth/image"       to="depth_registered/image_raw"/>
      <remap from="rgb/camera_info"   to="rgb/camera_info"/>
     
    </node>
   </group>
   <group ns="camera2">
    <node pkg="nodelet" type="nodelet" name="rgbd_sync" args="standalone rtabmap_ros/rgbd_sync">
      <remap from="rgb/image"         to="rgb/image_rect_color"/>
      <remap from="depth/image"       to="depth_registered/image_raw"/>
      <remap from="rgb/camera_info"   to="rgb/camera_info"/>

    </node>
   </group>
the /camera1/rgbd_image and /camera2/rgbd_image should be published. The other thing is that if the stamps in header of the topics are not synchronized, that could block rgbd_sync to synchronize the input topics.
Lex
Reply | Threaded
Open this post in threaded view
|

Re: How do I create a rosbag for multiple camera?

Lex
That fixed it! Thank you so much