Setting the Region of Interest in ROS 2

With ZED SDK v3.8.x we have introduced an interesting feature for robotics applications: the “Region of Interest” to focus on for all SDK processing, discarding other parts.

When mounting a ZED on a robot it happens very often that parts of the robot itself are statically visible in the camera’s field of view. This fact affects the depth extraction and performance of the positional tracking algorithms because part of the image will be stable even if the camera is moving.

The region of interest can be used to ignore these non-useful parts of the frame in the ZED SDK pipeline thus improving the overall performance of the ZED SDK algorithms run by the ZED ROS 2 Wrapper.

How to use it #

To set the region of interest of the ZED SDK processing it is necessary to call the API function sl::Camera::setRegionOfInterest which requires as an input parameter an image mask of type sl::Mat which sets the valid pixel zones of the frames captured, all the pixels with 0 (zero) as value are ignored.

The ZED ROS 2 Wrapper automatically creates the required sl::Mat starting from a parameter describing a polygon that contains the region of the image to be used during the data processing.

The Region of Interest can be set when the node starts through a node parameter, or at runtime by calling a ROS 2 service.

Node parameter #

The node parameter used to set the region of interest is general.region_of_interest, the parameter is a string containing the list of the normalized coordinates of the polygon.

We use normalized coordinates so it is possible to change the resolution of the images without necessarily changing the definition of the parameter of the Region of Interest.

For example, to define a rhomboid-shaped Region of Interest, with the vertices in the central quarter of the frame, it is necessary to set the parameter region_of_interest in common.yaml like

region_of_interest: "[[0.5,0.25],[0.75,0.5],[0.5,0.75],[0.25,0.5]]"

To keep the Region of Interest equal to the full image the polygon must be empty:

region_of_interest: ""

or

region_of_interest: "[]"

ROS 2 service #

The custom service to set a new Region of Interest at runtime is defined in the zed-ros2-interfaces repository. The service name is setROI and the type is zed_interfaces::srv::SetROI.

The service has a parameter of type string defining the shape of the polygon of the Region of Interest defined in the same way as the node parameter general.region_of_interest.

To reset the Region of Interest to the full image you can call the service resetROI of type std_srvs::srv::Trigger.