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

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

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

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;
                rosImage.data.resize(size);

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

                publisher.publish(rosImage);
            }
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

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

jkammerl gravatar image
edit flag offensive delete link more

Comments

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 -0600 )edit
2

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

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

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

Comments

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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 656 times

Last updated: Feb 08 '13