ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Publishing CV2 image message in ROS2 rclpy

asked 2019-05-19 16:05:40 -0600

John Doenut gravatar image

I have an image matrix in python3 CV2, which is actually just a numpy ndarray message in the shape of (width, height, rgb channels) that I want to publish as a message. In ROS1, there are standard message such as Image, compressed image and even variable arrays that can accomplish this. There are some example like ros2/demo git that shows cam2img but this is for cpp rclcpp. This seems like the simplest example but I cannot find any example, documentation on sending images in ROS2 python3 rclpy environment. I was actually able to turn the entire array into string and send it but this is nasty and the parsing done are unnecessary. How can I send three dimensional ndarray in rclpy in a "clean" fashion?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2019-05-20 11:12:29 -0600

Dirk Thomas gravatar image

As of the upcoming Dashing release the field in the Python messages will use numpy.ndarray to store image arrays of numeric values. That should avoid the conversion between your data and strings (as it was necessary in Crystal and earlier).

The draft of the Dashing release page mentions this change:

edit flag offensive delete link more

answered 2020-07-08 09:00:52 -0600

CodeFlow gravatar image

Might be worth pointing out that there is a package called cv_bridge, which did the job for me.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-05-19 16:05:40 -0600

Seen: 1,799 times

Last updated: May 20 '19