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

sensor_msgs/Image encoding conversion

asked 2013-06-19 03:31:06 -0500

Mikee gravatar image

Hi, I'm trying to publish the ros image message encoded as "rgba8" from the original image, which has encoding "bgr8".

What would be a proper way to do that?

I'm thinking of doing it in the following steps:

  1. convert ros image to cvImage
  2. split the channels
  3. merge the image according to "rgba" encoding (assuming a = 255)
  4. convert new cvImage to ros image

This seems a bit tedious... any suggestions??


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-06-19 06:16:32 -0500

makokal gravatar image

Have a look cv_bridge, the tutorial are plenty here, select the appropriate ROS distro while at it.

edit flag offensive delete link more

answered 2013-06-21 04:29:35 -0500

Mikee gravatar image

Thanks for pointing that out!

I tried to get the most out of that tutorial to do the conversion, and I just figured out the following:

  1. convert the ros image (bgr8) to cvImage in cv_bridge by specifying the wanted encoding (rgba8).

  2. convert this cvImage to ros msg, and publish.

When I run this script, it seems to consume quite a bit of cpu. I assume that during the first conversion, it needs lots of operations.

I just wonder if there would be a more efficient way of doing it?

edit flag offensive delete link more


i also have to publish a cvMat image in ROS...can you please tell me how can i convert the cvMat to ROS msg image?

rosqueries gravatar image rosqueries  ( 2013-09-05 06:16:22 -0500 )edit

Were you able to get any other conversions to work? I'm trying the same thing with RGB8 > Mono16, with no luck: encoding specified as mono16, but image has incompatible type 8UC3

Edit: My stream was only coming in as RGB8. This was the default in opencv, changing that fixed it.

TimboInSpace gravatar image TimboInSpace  ( 2014-11-16 23:41:52 -0500 )edit

Question Tools

1 follower


Asked: 2013-06-19 03:31:06 -0500

Seen: 15,975 times

Last updated: Jun 21 '13