ros-perception / image_transport_tutorials

ROS 2 tutorials for image_transport.
Apache License 2.0
50 stars 11 forks source link

bandwidth is the same #10

Closed AreteQin closed 7 months ago

AreteQin commented 8 months ago

Hi

Thank you so much for your tutorial.

I used the following commands to run the publisher and subscriber:

ros2 run image_transport_tutorials publisher_from_video 0
ros2 run image_transport_tutorials my_subscriber
ros2 run image_transport_tutorials my_subscriber --ros-args --remap __name:=compressed_listener -p _image_transport:=compressed

I can successfully get the video. However, there is no difference in bandwidth. The bandwidth is always around 25 MB/s.

Is there anything else I should do to get the compressed video? Or there is anything wrong I did/

Thanks in advance for any help!

ahcorde commented 7 months ago

The command that you are using looks wrong

you need to remap the topic name not the name of the node.

ros2 run image_transport_tutorials my_subscriber --ros-args -p image_transport:=compressed -r /image/compressed:=/camera/image/compressed

or try image_view

ros2 run image_view image_view --ros-args -p image_transport:=compressed -r /image/compressed:=/camera/image/compressed
AreteQin commented 7 months ago

Hi Thanks for your reply. I tried your command. But the bandwidth is still the same. Screenshot from 2024-01-27 12-27-43

As you can see the first and second periods are the same.

mikeferguson commented 7 months ago

The tutorial doesn't actually support the "image_transport" parameter - since we never define a TransportHints - see https://github.com/ros-perception/image_transport_tutorials/pull/13 for a change that actually does this.

The easiest way to confirm the transport is correct is to do a "node info" and see what topic is subscribed - with the changes in my PR, you get the compressed topic, instead of the regular "camera/image" topic (which is uncompressed):

ros2 node info /compressed_listener
/compressed_listener
  Subscribers:
    /camera/image/compressed: sensor_msgs/msg/CompressedImage
    /parameter_events: rcl_interfaces/msg/ParameterEvent
  Publishers:
    /parameter_events: rcl_interfaces/msg/ParameterEvent
    /rosout: rcl_interfaces/msg/Log
  Service Servers:
    /compressed_listener/describe_parameters: rcl_interfaces/srv/DescribeParameters
    /compressed_listener/get_parameter_types: rcl_interfaces/srv/GetParameterTypes
    /compressed_listener/get_parameters: rcl_interfaces/srv/GetParameters
    /compressed_listener/get_type_description: type_description_interfaces/srv/GetTypeDescription
    /compressed_listener/list_parameters: rcl_interfaces/srv/ListParameters
    /compressed_listener/set_parameters: rcl_interfaces/srv/SetParameters
    /compressed_listener/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically
  Service Clients:

  Action Servers:

  Action Clients:

You can also confirm bandwidth difference using the "topic bw" command, so the topics themselves are correct, the issue is that without TransportHints, we aren't subscribing to the correct topic:

fergs@ubuntu22:~/rolling$ ros2 topic bw /camera/image
Subscribed to [/camera/image]
2.71 MB/s from 5 messages
    Message size mean: 0.51 MB min: 0.51 MB max: 0.51 MB

fergs@ubuntu22:~/rolling$ ros2 topic bw /camera/image/compressed
Subscribed to [/camera/image/compressed]
566.70 KB/s from 5 messages
    Message size mean: 110.13 KB min: 110.13 KB max: 110.13 KB
AreteQin commented 7 months ago

Hi

Thanks for your explaination. Do you mean that I do not need to set image_transport parameter?

I tried "topic bw" and I got the following:

ros2 topic bw /camera/image/compressed
2024-02-02 18:54:51.167 [SUBSCRIBER Error] Deserialization of data failed -> Function deserialize_change
Subscribed to [/camera/image/compressed]
1.00 MB/s from 5 messages
    Message size mean: 0.18 MB min: 0.17 MB max: 0.18 MB
943.19 KB/s from 10 messages
    Message size mean: 177.54 KB min: 174.36 KB max: 179.00 KB
926.65 KB/s from 15 messages
    Message size mean: 178.06 KB min: 174.36 KB max: 179.48 KB
916.28 KB/s from 20 messages
    Message size mean: 177.87 KB min: 172.72 KB max: 179.48 KB

ros2 topic bw /camera/image
2024-02-02 18:54:37.104 [SUBSCRIBER Error] Deserialization of data failed -> Function deserialize_change
Subscribed to [/camera/image]
26.48 MB/s from 4 messages
    Message size mean: 2.76 MB min: 2.76 MB max: 2.76 MB
11.70 MB/s from 6 messages
    Message size mean: 2.76 MB min: 2.76 MB max: 2.76 MB
11.44 MB/s from 10 messages
    Message size mean: 2.76 MB min: 2.76 MB max: 2.76 MB
9.71 MB/s from 12 messages
    Message size mean: 2.76 MB min: 2.76 MB max: 2.76 MB
9.39 MB/s from 15 messages
    Message size mean: 2.76 MB min: 2.76 MB max: 2.76 MB

I believe that it means my publisher is working well. I also checked using "ros2 run rqt_image_view rqt_image_view", and I can successfully get original and compressed images.

Then I tried the following comand to subscribe the video:

ros2 run image_transport_tutorials my_subscriber

And I can get the original images.

But if I use this command

ros2 run image_transport_tutorials my_subscriber --ros-args -r /camera/image:=/camera/image/compressed

I cannot receive any image.

mikeferguson commented 7 months ago

Remapping /camera/image to the compressed topic isn't going to work (the encoding is different) - the image_transport parameter is the right thing to do - but we need to merge #13 and then things will work (as the code exists right now, it doesn't actually support compressed transport to be selected).

AreteQin commented 7 months ago

Thank you!