0
$\begingroup$

Rosanswers logo

Folks,

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?


Originally posted by Pototo on ROS Answers with karma: 803 on 2016-10-26

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

http://wiki.ros.org/image_transport/Tutorials/ExaminingImagePublisherSubscriber 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?


Originally posted by lucasw with karma: 8729 on 2016-10-27

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$
0
$\begingroup$

Rosanswers logo

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 https://answers.ros.org/question/230476/how-to-subscribe-to-sensor_msgscompressedimage-without-the-raw-image/


Originally posted by apichlkostner with karma: 11 on 2018-09-08

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Da on 2020-11-21:
I am trying to do this via c++ instead of external ros node. It works well! Thank you for your answer!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.