Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eeff4f404a |
@@ -1,94 +1,332 @@
|
||||
# A ROS Package for the Creation of a 3D Scene Graphs Utilizing Room Classification
|
||||
# Scene Graph Generation Pipeline for ROS 2
|
||||
|
||||
<img src="images/live.png" alt="drawing" width="600"/>
|
||||
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.
|
||||
|
||||
## Description
|
||||
This ROS packages enables the creation of a hierarchical 3D scene graph during runtime. In contrast to other solutions, rooms are segmented, classified and added as nodes as well.
|
||||
A robot using this package has to be equipped with a camera that provides an RGB stream, as well as a depth stream. Optimally, the robot is equipped with a 360° laser scanner.
|
||||
The package generates a 3D scene graph and comes with tools to visualize it using RViz.
|
||||
<p center="align">
|
||||
<img src="images/live.png" alt="Scene Graph Live RViz Visualization" width="700"/>
|
||||
</p>
|
||||
|
||||

|
||||
---
|
||||
|
||||
### Image Segmentation Module
|
||||
Segments the current image from the RGB stream using YOLOv9 after synchronizing and publishes 2D object bounding boxes.
|
||||
## Overview
|
||||
|
||||
#### Subscribers
|
||||
- RGB input stream: `/camera/color/image_raw` using `sensor_msgs/Image` messages
|
||||
- Depth input stream: `/camera/depth/points` using `sensor_msgs/PointCloud2` messages
|
||||
- Odometry input: `/camera/color/odom` using `nav_msgs/Odometry` messages
|
||||
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.
|
||||
|
||||
#### Publishers
|
||||
- Synchronized RGB stream: `/scene_graph/color/image_raw` using `sensor_msgs/Image` messages
|
||||
- Synchronized depth stream: `/scene_graph/depth/points` using `sensor_msgs/PointCloud2` messages
|
||||
- Synchronized odometry stream: `/scene_graph/odom` using `nav_msgs/Odometry` messages
|
||||
- Detected objects in current frame: `/scene_graph/detected_objects` using `scene_graph/DetectedObjects` messages
|
||||
The scene graph hierarchy consists of:
|
||||
1. **Building Node (Root)**: Represents the overall structure / environment centroid.
|
||||
2. **Room Nodes (Intermediate)**: Polygon-bounded spaces classified by functional usage (e.g., kitchen, office, bedroom, bathroom).
|
||||
3. **Object Nodes (Leaf)**: 3D bounding boxes and point clouds of localized objects (e.g., chair, table, monitor, sink).
|
||||
|
||||
### Object Localization Module
|
||||
Places the detected objects in 3D global space using the robot's odometry.
|
||||
<p center="align">
|
||||
<img src="images/overview.png" alt="Pipeline Overview Architecture" width="750"/>
|
||||
</p>
|
||||
|
||||
#### Subscribers
|
||||
- Synchronized RGB stream: `/scene_graph/color/image_raw` using `sensor_msgs/Image` messages
|
||||
- Synchronized depth stream: `/scene_graph/depth/points` using `sensor_msgs/PointCloud2` messages
|
||||
- Synchronized odometry stream: `/scene_graph/odom` using `nav_msgs/Odometry` messages
|
||||
- Detected objects in current frame: `/scene_graph/detected_objects` using `scene_graph/DetectedObjects` messages
|
||||
---
|
||||
|
||||
#### Publishers
|
||||
- Synchronized RGB stream: `/scene_graph/seen_graph_objects` using `scene_graph/GraphObjects` messages
|
||||
## Features
|
||||
|
||||
### Room Classification Module
|
||||
Classifies a single room utilizing a Random Forest Classifier on the base of given objects in that room.
|
||||
- **Open-Vocabulary 2D Object Detection**: Powered by [YOLO-World](https://docs.ultralytics.com/models/yolo-world/) for zero-shot object recognition from RGB camera streams.
|
||||
- **Fast 3D Object Localization**: Combines [FastSAM](https://docs.ultralytics.com/models/fast-sam/) 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.pkl` mapped 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.
|
||||
|
||||
#### Subscribers
|
||||
- Objects in give room: `/scene/graph/room_with_objects` using `scene_graph/RoomWithObjects` messages
|
||||
---
|
||||
|
||||
#### Publishers
|
||||
- Classified room label: `/scene_graph/classified_room` using `scene_graph/ClassifiedRoom` messages
|
||||
## Pipeline Architecture & Nodes
|
||||
|
||||
### Graph Management Module
|
||||
Iteratively generates a 3D scene graph at runtime. Publishes messages to visualize the graph
|
||||
The pipeline consists of six primary ROS 2 nodes:
|
||||
|
||||
#### Subscribers
|
||||
- 3D bounding boxes of seen objects in the frame: `/scene_graph/seen_graph_objects` using `scene_graph/GraphObjects` messages
|
||||
- Polygons of segmented rooms: `/scene_graph/rooms` using `scene_graph/RoomPolygonList` messages
|
||||
- Label of classified room: `/scene_graph/classified_room` using `scene_graph/ClassifiedRoom` messages
|
||||
```
|
||||
+-------------------------+
|
||||
| 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) |
|
||||
+--------------------------+
|
||||
```
|
||||
|
||||
#### Publishers
|
||||
- Objects in the graph: `scene_graph/graph_objects` using `scene_graph/GraphObjects` messages
|
||||
- Objects in a given room to be classified: `/scene/graph/room_with_objects` using `scene_graph/RoomWithObjects` messages
|
||||
- Visualization of object bounding boxes: `/scene_graph/viz/object_bbox_marker` using `visualization_msgs/MarkerArray` messages
|
||||
- Visualization of room nodes: `/scene_graph/viz/room_markers` using `visualization_msgs/MarkerArray` messages
|
||||
- Visualization of building nodes: `/scene_graph/viz/building_markers` using `visualization_msgs/MarkerArray` messages
|
||||
- Visualization of edges: `/scene_graph/viz/line_markers` using `visualization_msgs/MarkerArray` messages
|
||||
- Visualization of node labels: `/scene_graph/viz/text_markers` using `visualization_msgs/MarkerArray` messages
|
||||
### 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
|
||||
|
||||
- ROS Noetic on Ubuntu 20.04 LTS
|
||||
- Camera that provides RGB- and depth-streams (e.g. Orbbec Astra)
|
||||
- High-FOV laser scanner
|
||||
- Robot compatible with ROS that comes with an IMU
|
||||
- **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
|
||||
To install this package, install the [CGAL](https://www.cgal.org/) library and the [ultralytics](https://docs.ultralytics.com/models/yolov9/) package first. After that, clone and build this package.
|
||||
```
|
||||
pip install ultralytics
|
||||
sudo apt-get install libcgal-dev
|
||||
cd <your_catkin_workspace>/src
|
||||
git clone https://github.com/sijanz/scene_graph
|
||||
cd .. && catkin_make
|
||||
|
||||
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:
|
||||
```bash
|
||||
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`:
|
||||
```bash
|
||||
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:
|
||||
```bash
|
||||
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`:
|
||||
|
||||
```bash
|
||||
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:
|
||||
```bash
|
||||
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:
|
||||
```bash
|
||||
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`:
|
||||
|
||||
```bash
|
||||
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
|
||||
Run the whole scene graph creation pipeline as follows. Use a new terminal window for each command.
|
||||
|
||||
### 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:
|
||||
|
||||
```bash
|
||||
ros2 launch scene_graph_generation_pipeline scene_graph_rtabmap_launch.py use_sim_time:=true
|
||||
```
|
||||
rosrun scene_graph ros_yolo_node.py
|
||||
|
||||
### 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:
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
```bash
|
||||
# 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
|
||||
```
|
||||
rosrun scene_graph object_localization_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:
|
||||
|
||||
```bash
|
||||
cd ~/ros2_ws
|
||||
colcon test --packages-select scene_graph_generation_pipeline
|
||||
colcon test-result --all
|
||||
```
|
||||
```
|
||||
rosrun scene_graph room_classification_node
|
||||
```
|
||||
```
|
||||
rosrun scene_graph graph_management_node
|
||||
|
||||
Or run Python tests directly with PyTest:
|
||||
```bash
|
||||
cd ~/ros2_ws/src/scene_graph_generation_pipeline
|
||||
pytest test/
|
||||
```
|
||||
Reference in New Issue
Block a user