0
$\begingroup$

Rosanswers logo

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??

Thanks!!


Originally posted by Mikee on ROS Answers with karma: 41 on 2013-06-19

Post score: 2

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Have a look cv_bridge, the tutorial are plenty here http://www.ros.org/wiki/cv_bridge/Tutorials/UsingCvBridgeToConvertBetweenROSImagesAndOpenCVImages, select the appropriate ROS distro while at it.


Originally posted by makokal with karma: 1295 on 2013-06-19

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$
0
$\begingroup$

Rosanswers logo

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?


Originally posted by Mikee with karma: 41 on 2013-06-21

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by rosqueries on 2013-09-05:
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?

Comment by TimboInSpace on 2014-11-17:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.