This repository provides a high-performance ROS 2 package for streaming USB camera feeds using GStreamer and OpenCV. It features hardware-aware pipelines for both x86 (amd64) and NVIDIA Jetson platforms, along with dynamic configuration services.
- Hardware-Optimized Pipelines: Specific GStreamer strings for Jetson (
v4l2srcwithjpegdec) and amd64 (decodebin) architectures. - Dynamic Control: Change resolution and framerate at runtime via ROS 2 services without restarting nodes.
- Persistant Mapping: Includes utilities to map USB serial IDs to device paths, ensuring the correct camera is used even if
/dev/videoXindices change. - Built-in Filtering: Includes a "daylight" filter to enhance image warmth.
- Transport Support: Fully compatible with
image_transportfor compressed image streams.
Ensure you have the following installed on your system:
- ROS 2 Compressed Image Transport:
sudo apt install ros-humble-compressed-image-transport
- System Libraries:
sudo apt install libsystemd-dev
- OpenCV 4.x (typically included with ROS 2 Humble desktop installations).
- Clone this repository into your ROS 2 workspace:
cd ~/ros2_ws/src git clone <repository_url>
- Build the workspace (ensure
custom_interfacesis built first):cd ~/ros2_ws colcon build --packages-select custom_interfaces camera_streamer source install/setup.bash
1. Identify Your Camera Run the utility script to find the serial ID for your USB camera:
bash utils/find_devpath.bash2. Configure the Encoder
Edit camera_streamer/launch/encoder.launch.py:
- Set
HOST_MACHINEto "amd64" or "jetson". - Update the
CameraEncoderobject with your camera's name and the Serial ID found in the previous step. 3. Launch the Nodes On the Host (Camera Side):
ros2 launch camera_streamer encoder.launch.pyOn the Target (Viewer Side):
ros2 launch camera_streamer decoder.launch.pyServices
- Toggle Camera (
/<camera_name>/toggle_camera): Starts or stops the video capture. - Set Encoder Config (
/<camera_name>/set_encoder_config): Dynamically updatesimage_width,image_height, andframe_rate. Parameters camera_cap_width/camera_cap_height: The raw resolution captured from the hardware.image_send_width/image_send_height: The resolution after resizing, sent over the network.jpeg_quality: Compression level (1-100) for thecompressedtransport.
camera_streamer: Contains the core encoder, decoder, and viewer nodes.custom_interfaces: Defines theSetEncoderConfigservice.utils: Helper scripts for hardware identification.