This repository contains code for working with the Intel RealSense D415 camera in ROS 2 for deep learning applications.
- ROS 2 Humble
- Ubuntu 22.04
- Python 3.10
- RealSense SDK v2.56.5
cd ~
git clone --recursive git@github.com:hrc-pme/Deep_learning_d415_ROS2.git
Note: The
--recursive
flag is required to clone submodules properly
cd ~/Deep_Learning_d415_ROS2
git pull
git submodule sync --recursive
git submodule update --init --recursive
cd ~/Deep_learning_d415_ROS2
sudo cp .99-realsense-libusb.rules /etc/udev/rules.d/99-realsense-libusb.rules
Choose the appropriate Docker setup based on your hardware:
- Use GPU version if you have a compatible graphics card
- Use CPU version for systems without GPU
Before starting with GPU container check out your CUDA version first.
The default CUDA version will be 12.4.
# For GPU systems:
# Check your CUDA version first
nvidia-smi
If you want to change your CUDA version Check on this repo. CUDA Version
If you have the correct version, you can open the container.
cd ~/Deep_Learning_d415_ROS2
chmod +x run_gpu.sh # give the permission (you will only do one time)
./run_gpu.sh # default CUDA version 12.4
If you are using VMware or any virtual machine, you only can use CPU version.
# For CPU systems:
cd ~/Deep_Learning_d415_ROS2
chmod +x run_cpu.sh # give the permission (you will only do one time)
./run_cpu.sh
user: hrc
passward: 111111
Inside the Docker container:
cd ~/Workspace/ros2_ws
colcon build --symlink-install
# Or simply use `cb` instead of typing the full command.
Note: The alias
cb
had been defined asalias cb='colcon build --symlink-install
rs-enumerate-devices -s
Expected Output
Device Name Serial Number Firmware Version
Intel RealSense D415 241222061237 5.16.0.1
- Open the launch file:
~/Deep_Learning_d415_ROS2/ros2_ws/src/realsense-ros/realsense2_camera/launch/rs_launch.py
- Update the serial number:
{'name': 'serial_no', 'default': "'YOUR_CAMERA_SERIAL_NUMBER'", 'description': 'choose device by serial number'},
- Rebuild the workspace:
cb
In Terminal 1:
ros2 launch realsense2_camera rs_launch.py
Turn on the Rviz2 to visualize the image.
In Terminal 2:
cd ~/Deep_Learning_d415_ROS2
./run_[your_version].sh #./run_gpu.sh OR ./run_cpu.sh
rviz2
OR you can open rosbridge visualize in foxglove
ros2 launch rosbridge_server rosbridge_websocket_launch.xml
Then in RViz2:
- Click "Add"
- Navigate to: By topic → /camera → /camera → /color → /image_raw → /Image
Check if camera topics are being published:
ros2 topic list
Expected topics:
/camera/camera/color/camera_info
/camera/camera/color/image_raw
/camera/camera/color/image_raw/compressed
/camera/camera/color/image_raw/compressedDepth
/camera/camera/color/image_raw/theora
...
Edit the configuration file:
~/Workspace/ros2_ws/src/bag_recorder/config/bag_recorder.yaml
Default configuration:
topics:
- /tf_static
- /camera/camera/color/image_raw/compressed
output_dir: ~/Workspace/Outputs/rosbags/test
We will start to record a rosbg with camera topics.
Choose one of these methods:
Using GUI will be easier to record mulit bags.
Option 1: Using GUI
ros2 launch bag_recorder record_with_ui.launch.py
Option 2: Using Terminal
ros2 launch bag_recorder record.launch.py
(Press Ctrl + C to stop recording)
Edit the configuration file:
~/Workspace/Script/config/bags2mp4.yaml
Default configuration:
jobs:
- input_paths: # Paths to bag folders
- "/home/hrc/Workspace/Outputs/rosbags/test"
output_root: "/home/hrc/Workspace/Outputs/mp4/test" # Output MP4 folder
topic: "/camera/camera/color/image_raw/compressed"
# Image topic If omit → auto-pick if only one; error if multiple
NOTES: If Image topic omit → auto-pick if only one; error if multiple
cd ~/Workspace/Script
python3 bag2mp4.py