A camera streaming system for ROS 2
Tested using ROS 2 Humble, Ubuntu 22.04, amd64 laptop.
Tested using ROS 2 Humble, Jetson Linux DP 6.0, Jetson AGX Orin.
- Install ROS 2 Compressed Image Transport:
sudo apt install ros-humble-compressed-image-transport
- Make sure Compressed Image Transport is listed:
ros2 run image_transport list_transports
- OpenCV 4.x
- libsystemd-dev:
sudo apt install libsystemd-dev
- Find the serial ID for the USB camera devices using the
find_devpath.bash
file within theutils/
folder. - Set the proper host machine architecture using
HOST_MACHINE
withinencoder.launch.py
. - Add
CameraEncoder
objects to theencoder.launch.py
file, and give each a camera name and serial ID. - Add
CameraDecoder
objects to thedecoder.launch.py
file, and specify the camera name. - Build the package using
colcon build
- Run
ros2 launch camera_streamer encoder.launch.py
to start the encoder. - Run
ros2 launch camera_streamer decoder.launch.py
to start the decoder.
- Topic:
<camera_name>/out
, Type:Image
, QoS:SensorData
; Video feed output.
- Service:
<camera_name>/toggle_camera
, Type:std_srvs/SetBool
; Toggle the camera feed on or off. (Will also release the USB device). - Service:
<camera_name>/set_encoder_config
, Type:SetEncoderConfig
; Set encoder parameters such as resolution and frame rate.
- To use the built-in camera viewer, enable
ENABLE_WINDOW_VIEW
withindecoder.launch.py
. - JPEG image compression can be set using the
JPEG_COMPRESSION
variable withinencoder.launch.py
. - Set cameras to auto enable on encoder startup using
AUTO_ENABLE_CAMERAS
withinencoder.launch.py
. - Test encoder services using
ros2 launch camera_streamer config_test.launch.py
. Make sure the camera name is specified.
- Seem to only be able to use two cameras per physical USB controller. May need to update GStreamer API configuration to allocate less memory to the device?
- Other ROS 2 image transports can potentially be used. Would need to change
IMAGE_TRANSPORT
withindecoder.launch.py
to the name withinros2 run image_transport list_transports
list, and then add the proper ROS 2 parameters for the transport intoencoder.launch.py
:
// Example from encoder.launch.py for compressed image transport:
{self.camera_name + '.transport.format': 'jpeg'},
{self.camera_name + '.transport.jpeg_quality': self.jpeg_quality}