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

'JPEG compression requires 8-bit, 1/3-channel images' error since Fuerte

asked 2012-11-06 03:58:57 -0500

Benoit Larochelle gravatar image

I developed an application based on the old RVIZ (wxWidgets) and I have a tool that takes an OgreImage (from a video feed) and publishes on a different topic as a screenshot. I use a standard image_transport publisher.

In Diamondback, the listener could choose between raw, compressed, and theora. In Fuerte, only raw works.

On the publisher side, I get the following error with compressed: Compressed Image Transport - JPEG compression requires 8-bit, 1/3-channel images (input format is: rgba8)

I'm wondering if some format support was removed in Fuerte, since this used to work. Here is my code:

void PhotoTool::publishImageToROS(const Ogre::Image& ogreImage, const std::string& referenceFrame)
                sensor_msgs::Image rosImage;

                static int seq = 0;

                rosImage.header.seq = seq++;
                rosImage.header.frame_id = referenceFrame;
                rosImage.header.stamp = ros::Time::now();
                rosImage.height = ogreImage.getHeight();
                rosImage.width = ogreImage.getWidth();
                rosImage.encoding = "rgba8";
                rosImage.is_bigendian = false;
                rosImage.step = ogreImage.getRowSpan();
                size_t size = rosImage.step * rosImage.height;

                // Copies the data from the Ogre Image to the ROS Image
                memcpy((char*) (&[0]), ogreImage.getData(), size);

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-02-08 06:48:33 -0500

jkammerl gravatar image
edit flag offensive delete link more


Sorry that it took me so long to test it, but the problem is fixed now! :-)

Benoit Larochelle gravatar image Benoit Larochelle  ( 2013-04-04 04:02:00 -0500 )edit

answered 2012-11-06 04:33:36 -0500

updated 2012-11-06 06:09:30 -0500

I'm a little surprised that ever worked. JPEG doesn't support alpha, which is what that error message is telling you. An easy fix would be to remove the 'a' channel from your image. There may be a clever way to do it without deserializing the data, but the easiest thing would be to use opencv to split the image channels, then merge back the r, g and b channels (leaving out a).

EDIT - mixChannels will do it: Something like this should work (taken from the example, not tested):

// Mat rgba = input image
Mat rgb( rgba.rows, rgba.cols, CV_8UC3 );

Mat out[] = { rgb };
int from_to[] = { 0,0, 1,1, 2,2 };
mixChannels( &rgba, 1, out, 1, from_to, 3 );
edit flag offensive delete link more


Well, I was surprised too. :-) I have never used opencv... could you direct me to documentation or an example? Alternatively, is there a way to get what's on the Ogre Texture without an alpha channel?

Benoit Larochelle gravatar image Benoit Larochelle  ( 2012-11-06 05:08:20 -0500 )edit

Edited my answer with an example. If there's a way for ogre to directly output an image without alpha, that's probably the way to go.

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2012-11-06 06:10:17 -0500 )edit

Question Tools

1 follower


Asked: 2012-11-06 03:58:57 -0500

Seen: 615 times

Last updated: Feb 08 '13