Realsense RGBD msg format and Rtabmap RGBD msg format diffrent !
I am trying to use realsense D435i Depth camera with rtabmap. I can able to get map with depth and color images combination. But when I want to connect to the rgbd topic, I see that the rgbd msg formats are different. Is there a setting I can make for this?
Cannot echo topic '/camera/rgbd', as it contains more than one type: [realsense2_camera_msgs/msg/RGBD, rtabmap_msgs/msg/RGBDImage]
Looks like realsense2 has their own version of rgbd msg.
- Realsense: https://github.com/IntelRealSense/realsense-ros/blob/ros2-master/realsense2_camera_msgs/msg/RGBD.msg (created in 2023)
- Rtabmap: https://github.com/introlab/rtabmap_ros/blob/ros2/rtabmap_msgs/msg/RGBDImage.msg (created in 2016)
You cannot connect realsense's RGBD msg to rtabmap nodes. I think however that it would not be difficult to convert a realsense2_camera_msgs/RGBD topic to rtabmap_msgs/RGBDImage topic, as the same fields exist in the rtabmap_msgs version.
Here a chatgpt example to convert them (I didn't test it, but looks roughly what I was thinking):
import rclpy
from rclpy.node import Node
from realsense2_camera_msgs.msg import RGBD as RealSenseRGBD
from rtabmap_msgs.msg import RGBDImage as RtabmapRGBDImage
from std_msgs.msg import Header
from sensor_msgs.msg import CameraInfo, Image, CompressedImage
class RGBDConverter(Node):
def __init__(self):
super().__init__('rgbd_converter')
self.subscription = self.create_subscription(
RealSenseRGBD,
'/camera/rgbd', # Change to your actual input topic
self.rgbd_callback,
10)
self.publisher = self.create_publisher(
RtabmapRGBDImage,
'/rtabmap/rgbd_image', # Output topic
10)
def rgbd_callback(self, msg: RealSenseRGBD):
converted = RtabmapRGBDImage()
# Copy shared fields
converted.header = msg.header
converted.rgb_camera_info = msg.rgb_camera_info
converted.depth_camera_info = msg.depth_camera_info
converted.rgb = msg.rgb
converted.depth = msg.depth
# Optional: Leave other fields empty/default
converted.rgb_compressed = CompressedImage()
converted.depth_compressed = CompressedImage()
converted.key_points = []
converted.points = []
converted.descriptors = []
# global_descriptor can be left default or initialized if needed
self.publisher.publish(converted)
self.get_logger().info('Converted and published RGBDImage')
def main(args=None):
rclpy.init(args=args)
node = RGBDConverter()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()