Scene Graph Generation Pipeline for ROS 2
A ROS 2 package for real-time creation, fusion, and visualization of dynamic hierarchical 3D Scene Graphs integrating 3D object localization, room segmentation, and room classification.
Overview
This repository provides a complete ROS 2 pipeline for generating a 3D hierarchical scene graph during robot navigation. Unlike traditional mapping solutions, this pipeline segments and classifies rooms in real time, placing 3D objects, rooms, and structural relationships into a unified graph representation.
The scene graph hierarchy consists of:
- Building Node (Root): Represents the overall structure / environment centroid.
- Room Nodes (Intermediate): Polygon-bounded spaces classified by functional usage (e.g., kitchen, office, bedroom, bathroom).
- Object Nodes (Leaf): 3D bounding boxes and point clouds of localized objects (e.g., chair, table, monitor, sink).
Features
- Open-Vocabulary 2D Object Detection: Powered by YOLO-World for zero-shot object recognition from RGB camera streams.
- Fast 3D Object Localization: Combines FastSAM instance segmentation with depth imagery, camera intrinsics, and TF transforms to construct accurate 3D object bounding boxes and point clouds.
- Occupancy-Based Room Segmentation: Uses distance-transform and watershed segmentation algorithms on 2D occupancy maps (
/rtabmap/map) to extract room polygon boundaries. - Object-Based Room Classification: Applies a pre-trained Random Forest model (
rf_classifier.pklmapped to MPcat40 categories) to predict room labels based on object composition within each room. - Real-Time Graph Fusion & Tracking: Backed by NetworkX, maintaining 3D IoU data association, room containment reasoning, and dynamic graph updates upon RTAB-Map SLAM loop closure events.
- RTAB-Map SLAM Integration: Works out-of-the-box with RTAB-Map SLAM for real-time localization and global map graph optimization.
- RViz2 Visualization: Real-time rendering of graph nodes (building, rooms, objects), relationships (edges), object bounding boxes, trajectories, and text labels.
Pipeline Architecture & Nodes
The pipeline consists of six primary ROS 2 nodes:
+-------------------------+
| Sensors / SLAM |
| (RGB-D, Odom, /scan) |
+------------+------------+
|
+----------------------+----------------------+
| | |
v v v
+--------------------+ +------------------+ +-------------------+
| object_detection | | RTAB-Map SLAM | | odom_vizualization|
| _node (YOLO-World) | | (/rtabmap/map) | | _node (TF Filter) |
+---------+----------+ +--------+---------+ +-------------------+
| |
v v
+--------------------+ +------------------+
|object_localization | |room_segmentation |
| _node (FastSAM) | | _node |
+---------+----------+ +--------+---------+
| |
+-----------+-----------+
|
v
+--------------------------+
| scene_graph_fusion_node |
| (NetworkX 3D Graph) |
+------------+-------------+
|
v
+--------------------------+
| room_classification_node |
| (Random Forest / MPcat) |
+--------------------------+
1. Object Detection Node (object_detection_node)
Performs open-vocabulary object detection on incoming RGB camera frames using YOLO-World.
- Subscribers:
/camera/color/image_raw(sensor_msgs/msg/Image)/camera/depth/image_raw(sensor_msgs/msg/Image)/odom(nav_msgs/msg/Odometry)
- Publishers:
/scene_graph/sync/color/image_raw(sensor_msgs/msg/Image)/scene_graph/sync/depth/image_raw(sensor_msgs/msg/Image)/scene_graph/sync/odom(nav_msgs/msg/Odometry)/scene_graph/yolo(scene_graph_interfaces/msg/ObjectList)/scene_graph/debug/yolo(sensor_msgs/msg/Image)
2. Object Localization Node (object_localization_node)
Computes 3D global bounding boxes and extracts object point clouds using FastSAM segmentation and camera intrinsics.
- Subscribers:
/camera/depth/camera_info(sensor_msgs/msg/CameraInfo)/scene_graph/sync/color/image_raw(sensor_msgs/msg/Image)/scene_graph/sync/depth/image_raw(sensor_msgs/msg/Image)/scene_graph/yolo(scene_graph_interfaces/msg/ObjectList)
- Publishers:
/bounding_boxes_3d/yolo(scene_graph_interfaces/msg/Object3DBoundingBoxList)/object_clouds/yolo(sensor_msgs/msg/PointCloud2)/scene_graph/viz/current_bounding_boxes_3d(visualization_msgs/msg/MarkerArray)/bounding_boxes_3d/point_cloud_markers(visualization_msgs/msg/MarkerArray)/scene_graph/debug/depth_colored,/scene_graph/debug/segmented_rgb,/scene_graph/debug/segments_overlay(sensor_msgs/msg/Image)
3. Room Segmentation Node (room_segmentation_node)
Segments 2D occupancy grid maps generated by SLAM into distinct room polygons.
- Subscribers:
/rtabmap/map(nav_msgs/msg/OccupancyGrid)
- Publishers:
/scene_graph/rooms(scene_graph_interfaces/msg/RoomPolygonList)/scene_graph/viz/rooms(visualization_msgs/msg/MarkerArray)
4. Room Classification Node (room_classification_node)
Classifies room functionality based on object types inside each segmented room boundary using a Random Forest classifier.
- Subscribers:
/scene/graph/room_with_objects(scene_graph_interfaces/msg/RoomWithObjects)
- Publishers:
/scene_graph/classified_room(scene_graph_interfaces/msg/ClassifiedRoom)
5. Scene Graph Fusion Node (scene_graph_fusion_node)
Maintains the hierarchical graph structure, handles object fusion and tracking (3D IoU), processes SLAM loop closure updates, and assigns objects to room nodes.
- Subscribers:
/bounding_boxes_3d/yolo(scene_graph_interfaces/msg/Object3DBoundingBoxList)/scene_graph/rooms(scene_graph_interfaces/msg/RoomPolygonList)/scene_graph/classified_room(scene_graph_interfaces/msg/ClassifiedRoom)/rtabmap/info(rtabmap_msgs/msg/Info)/rtabmap/mapGraph(rtabmap_msgs/msg/MapGraph)
- Publishers:
/scene/graph/room_with_objects(scene_graph_interfaces/msg/RoomWithObjects)/scene_graph/viz/object_bbox_marker(visualization_msgs/msg/MarkerArray)/scene_graph/viz/room_markers(visualization_msgs/msg/MarkerArray)/scene_graph/viz/building_markers(visualization_msgs/msg/MarkerArray)/scene_graph/viz/line_markers(visualization_msgs/msg/MarkerArray)/scene_graph/viz/text_markers(visualization_msgs/msg/MarkerArray)
6. Odom Visualization & TF Node (odom_vizualization_node)
Handles coordinate transform filtering, forwards static TFs with TRANSIENT_LOCAL durability, and publishes trajectory visualization markers.
- Subscribers:
/tf_old,/tf_static_old,/rtabmap/info,/rtabmap/mapGraph - Publishers:
/tf,/tf_static,/scene_graph/viz/robot_pose,/scene_graph/viz/trajectory
Prerequisites
- Operating System: Ubuntu 22.04 LTS
- ROS Version: ROS 2 Humble Hawksbill
- Python: Python 3.10+
- Hardware:
- RGB-D Camera (e.g., Orbbec Astra, Intel RealSense, or Gazebo simulated RGB-D stream)
- 2D Laser Scanner (
/scan) - Mobile Robot / Odometry source (
/odom) - CUDA-capable GPU (recommended for real-time object detection and FastSAM segmentation)
Installation
Follow these step-by-step instructions to set up the workspace, install system dependencies, build RTAB-Map, and install Python dependencies.
Step 1: Install ROS 2 Humble & Core Build Tools
Ensure ROS 2 Humble is installed and properly sourced:
source /opt/ros/humble/setup.bash
sudo apt-get update && sudo apt-get install -y \
python3-colcon-common-extensions \
python3-rosdep \
python3-pip \
git
Step 2: Install RTAB-Map & RTAB-Map ROS 2
RTAB-Map is required for SLAM, occupancy grid map generation (/rtabmap/map), and map graph updates (/rtabmap/info, /rtabmap/mapGraph).
Option A: Binary Package Installation (Recommended)
Install pre-compiled RTAB-Map packages for ROS 2 Humble via apt:
sudo apt-get update && sudo apt-get install -y \
ros-humble-rtabmap \
ros-humble-rtabmap-ros \
ros-humble-rtabmap-msgs \
ros-humble-rtabmap-launch \
ros-humble-rtabmap-conversions \
ros-humble-rtabmap-util
Option B: Source Installation (For Custom RTAB-Map Builds)
If you require building RTAB-Map from source inside your ROS 2 workspace:
cd ~/ros2_ws/src
# Clone RTAB-Map standalone library and ROS 2 package
git clone https://github.com/introlab/rtabmap.git
git clone --branch humble-devel https://github.com/introlab/rtabmap_ros.git
# Install build dependencies for RTAB-Map
sudo apt-get install -y \
ros-humble-rtabmap-otb \
libpcl-dev \
libopencv-dev \
liboctomap-dev
Step 3: Set Up Workspace & Clone Repositories
Create a ROS 2 workspace (if not already created) and clone scene_graph_generation_pipeline along with its custom interface package scene_graph_interfaces:
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws/src
# Clone custom message definitions and pipeline
git clone https://github.com/sijanz/scene_graph_interfaces.git
git clone https://github.com/sijanz/scene_graph_generation_pipeline.git
Step 4: Install System Dependencies & Python Requirements
Install required ROS 2 libraries:
sudo apt-get update && sudo apt-get install -y \
ros-humble-cv-bridge \
ros-humble-tf2-ros \
ros-humble-message-filters \
ros-humble-visualization-msgs \
ros-humble-nav-msgs \
ros-humble-sensor-msgs \
ros-humble-geometry-msgs
Install Python package requirements for object detection, segmentation, geometry processing, and graph management:
cd ~/ros2_ws/src/scene_graph_generation_pipeline
pip3 install -r requirements.txt
Note: requirements.txt installs packages including ultralytics>=8.2.0, opencv-python, networkx, scipy, shapely, open3d, huggingface-hub, and clip.
Step 5: Build and Source the Workspace
Initialize rosdep, resolve any remaining dependencies, and build the workspace using colcon:
cd ~/ros2_ws
# Update rosdep and install missing package dependencies
rosdep update
rosdep install --from-paths src --ignore-src -r -y
# Build workspace
colcon build --symlink-install
# Source workspace setup
source install/setup.bash
Usage
1. Complete Pipeline with RTAB-Map SLAM & RViz2
Launch RTAB-Map SLAM, all six scene graph pipeline nodes, and pre-configured RViz2 visualization in a single command:
ros2 launch scene_graph_generation_pipeline scene_graph_rtabmap_launch.py use_sim_time:=true
2. Standalone Pipeline (With Existing SLAM / Bag Playback)
If RTAB-Map or another SLAM node is already running or playing back a ROS 2 bag file:
ros2 launch scene_graph_generation_pipeline scene_graph_launch.py use_sim_time:=true
3. Running Nodes Individually
Alternatively, launch each node separately in individual terminal windows:
# Sourcing workspace in each terminal
source ~/ros2_ws/install/setup.bash
# Terminal 1: 2D Object Detection (YOLO-World)
ros2 run scene_graph_generation_pipeline object_detection_node
# Terminal 2: 3D Object Localization (FastSAM)
ros2 run scene_graph_generation_pipeline object_localization_node
# Terminal 3: Room Segmentation (Distance-Transform / Watershed)
ros2 run scene_graph_generation_pipeline room_segmentation_node
# Terminal 4: Room Classification (Random Forest)
ros2 run scene_graph_generation_pipeline room_classification_node
# Terminal 5: Scene Graph Fusion Core
ros2 run scene_graph_generation_pipeline scene_graph_fusion_node
# Terminal 6: Odom Visualization & TF Filter
ros2 run scene_graph_generation_pipeline odom_vizualization_node
Custom Messages (scene_graph_interfaces)
The pipeline relies on custom ROS 2 messages defined in scene_graph_interfaces:
ObjectList.msg: 2D bounding boxes and class labels from object detection.Object3DBoundingBox.msg/Object3DBoundingBoxList.msg: 3D bounding box coordinates, extents, and spatial centroids.RoomPolygon.msg/RoomPolygonList.msg: Vertices of segmented room boundaries.RoomWithObjects.msg: Association list mapping room polygons to contained 3D objects.ClassifiedRoom.msg: Predicted room classification label and probability scores.
Testing & Verification
To run unit and lint tests for the pipeline:
cd ~/ros2_ws
colcon test --packages-select scene_graph_generation_pipeline
colcon test-result --all
Or run Python tests directly with PyTest:
cd ~/ros2_ws/src/scene_graph_generation_pipeline
pytest test/

