I'd leave you with a roadmap since you do not specify what type of language you are using, and if you have any other constraints.
You'd have to start by creating a custom service. There are a lot of tutorials online about creating your services, but the ROS 2 official documentation is the most useful to me. You'll find the tutorials for C++ and Python there.
If we choose to call the service MyCustomImage
, then the MyCustomImage.srv
file would look something like this:
---
sensor_msgs/Image response
The above block essentially translates the requirement
the request is empty and the response is an image
into ROS 2 terms.
From there on, you can continue to follow the creating a custom service tutorial for the implementation of the server and client nodes (these are language-specific, although the underlying concept translates to both of them).
The basic structure of your server node (the node which provides the image) would be "to read a particular device/file for an image, to convert the image to the sensor_msgs/Image format, and return the response". This is what would need to be defined in the service callback.
Similarly, the client node (the one that requests the server for an image), would call the MyCustomImage
service and receive the response. From there you choose what to do with your image data.
NOTE: You can simplify your life by using the cv_bridge
package to convert your OpenCV images to ROS 2 sensor_msgs/Image
messages, but this is out of the scope, as you have not specified if you are using OpenCV or not.