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

How To Write C++ CompressedImage Subscriber?

asked 2016-10-26 16:18:26 -0600

Pototo gravatar image


I can't find explicit tutorials on how to WRITE a subscriber for compressed images on roscpp. I see the one in python, as well as the image_transport tutorials, etc., but nothing concrete about how to do it in C++. I always get errors when I try to import CompressedImage.h and add "/compressed" to my image topics and replace my ImageConstPtr for CompressedImageConstPtr.

Any sample C++ code you know of?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2016-10-27 10:20:45 -0600

lucasw gravatar image

updated 2016-10-27 10:33:37 -0600 says setting the image_transport parameter to compressed will cause the compressed image to be subscribed to. (If there are multiple image subscribers in the same node, I would guess they all would either be using the same transport, only having multiple ImageTransport objects with multiple node handles on different namespaces would allow finer grained control)

If you were running the my_subscriber tutorial code and the image to subscribe to was /usb_cam/image_raw instead of /camera/image, you would do this:

rosrun image_transport_tutorial my_subscriber camera/image/compressed:=/usb_cam/image_raw/compressed _image_transport:=compressed

The image is uncompressed for you before it hits your callback, did you want to get the compressed data raw instead?

rqt_image_view looks like it is directly subscribing to the compressed image, I wonder if it is doing something different?

edit flag offensive delete link more

answered 2018-09-08 04:27:47 -0600

Instead of setting the parameter ~image_transport:=compressed it's also possible to set the value hardcoded with a TransportHints object:

ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::TransportHints hints("compressed");
it.subscribe(base_topic, queue_size, callback, ros::VoidPtr(), hints);

Another solution is to implement the subscriber without image_transport and subscribe to the compressed image directly, as shown in

edit flag offensive delete link more


I am trying to do this via c++ instead of external ros node. It works well! Thank you for your answer!

Da gravatar image Da  ( 2020-11-21 11:06:43 -0600 )edit

Question Tools

1 follower


Asked: 2016-10-26 16:18:26 -0600

Seen: 3,038 times

Last updated: Oct 27 '16