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

Revision history [back]

When I've worked with compressed image topics, I've never had to deal with the compressed data directly I've left that to the image_transport package. You can use the following code to setup a subscriber, this will work with the compressed topic if it is available, or with an uncompressed one if that's all that's available.

image_transport::ImageTransport it(n);
itSub = it.subscribe("topic_name", 1, imageCallbackFn, image_transport::TransportHints("compressed"));

Then your imageCallbackFn will be the same as a regular image callback because the decompression is being handled for you:

// Image callback
void imageCallbackFn(const sensor_msgs::ImageConstPtr& msg)
{
  cv_bridge::CvImagePtr cvImg = cv_bridge::toCvCopy(msg, "bgr8");
  cv::Mat myOpenCVImg = cvImg->image;
}

Hope this helps you get this working.