← Work

ros2_bag_exporter

C++ ROS2 package that exports bag files to images, PCD, IMU, GPS, and CSV — YAML-configured, sqlite3 and MCAP support

Creator & Maintainer · 2024 · maintained · GitHub ↗

Problem

ROS2 bag files capture everything — camera images, LiDAR scans, IMU readings, GPS coordinates, odometry paths — but all data is locked inside a binary sqlite3 or MCAP format. Extracting it for ML training, offline visualisation, or pipeline debugging requires either heavy ROS2 tooling or writing custom reader code for every message type and every project.

Approach

A single ROS2 C++ node that reads a bag file and exports topics to standard formats based on message type, configured entirely via a YAML file. One command, one config, all topics exported in parallel. Topic type is declared in the config; the node selects the correct serialiser automatically.

Both sqlite3 (ROS2 default) and MCAP storage formats are supported. Sample interval configuration allows writing every Nth message — essential for large bags where writing every frame would produce hundreds of thousands of files.

Results

Supported message types and output formats:

Message TypeOutput Format
sensor_msgs/PointCloud2.pcd (intensity / RGB / RGBA / XYZ, auto-detected)
sensor_msgs/Image.png (rgb8 / bgr8 / mono8 / mono16)
sensor_msgs/CompressedImage.jpg or .png
IR Image.png
sensor_msgs/Image (depth).png (bgr8 visualisation / 16UC1 raw / mono8 greyscale)
sensor_msgs/LaserScanexported per-scan
sensor_msgs/Imu.csv
GPS.csv
nav_msgs/Path.csv (timestamp, frame_id, pose x/y/z, orientation x/y/z/w per waypoint)
nav_msgs/Odometry.csv (timestamp, position, orientation, linear/angular velocity)
  • YAML config: bag path, output directory, storage format, per-topic type + encoding + sample interval
  • Automatic output directory creation per topic
  • Comprehensive error logging and graceful shutdown on critical errors
  • Used internally for creating annotated datasets from AMR field recordings
  • 105 stars on GitHub

Stack

  • C++17
  • ROS2 Humble
  • rosbag2-cpp
  • OpenCV
  • PCL
  • YAML-CPP
  • cv_bridge
  • colcon

Technologies

  • C++17
  • ROS2
  • rosbag2
  • OpenCV
  • PCL
  • YAML-CPP