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

Convert from a sensor_msgs::CompressedImage message to IplImage

asked 2011-05-27 10:58:28 -0500

GeorgeAprilis gravatar image

I'm saving test videos in a JPEG compressed bag file. Then I try to use it as input to a subscriber that listens to the "/camera/image/compressed" topic and convert it to OpenCV's IplImage using the method presented here: http://www.ros.org/wiki/image_transpo... to use it then in my algorithm.

When save the images in raw format, posting them back in /camera/image topic things work fine, but the bag file is huge. There seems to be a problem with cv_bridge converting sensor_msgs::CompressedImage instead of sensor_msgs::Image...

Is there a way to solve this problem using cv_bridge? I couldn't figure it out reading the documentation, cv_bridge only refers to uncompressed image converting.

Thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2011-05-30 02:02:01 -0500

GeorgeAprilis gravatar image

Yes I am. I managed to solve my problem for now using the republish command of image_transport.

My code was pretty similar to the tutorial examples. My subscriber declaration:

_frameSubscriber = image_transport::ImageTransport(_nh).subscribe("/vision/image", 5, &WebVision::grabFrameFromMsg, this);

And implementation:

void WebVision::grabFrameFromMsg(const sensor_msgs::ImageConstPtr& msg)
{
    sensor_msgs::CvBridge bridge;

    frame = bridge.imgMsgToCv(msg, "bgr8");
    frameTimestamp = msg->header.stamp;

    /*rest of the code where I pass the IplImage* frame to my functions*/
}

So the notion was to save bag files from the camera input when testing, and then pass the "video" as input to the algorithms to test it while offline.

But CvBridge could only listen to raw image messages and I couldn't afford so much disk space to save long raw videos.

What I do now is to just run this:

$ rosrun image_transport republish compressed in:=/vision/image _image_transport:=compressed raw out:=/vision/image

and listen to the republished topic with raw images. It could be better if I could implement the conversion inside the code, but it solves my problem for now.

Thanks anyway for giving it a try. :)

edit flag offensive delete link more
0

answered 2011-05-29 21:49:02 -0500

KoenBuys gravatar image

Are you using image transport also for the subscriber? Could you post your code?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2011-05-27 10:58:28 -0500

Seen: 4,947 times

Last updated: May 30 '11