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

How to use sensor_msgs.msg.Image data to train a NN

asked 2020-01-08 16:03:19 -0500

ngoberville gravatar image

updated 2020-01-09 05:08:30 -0500

gvdhoorn gravatar image

I'm trying to do some RL for driving a vehicle using the CARLA simulator. I'm using the carla-ros-bridge that's made available by the CARLA team. In order to get camera image data, I need to read the data from the topic /carla/ego_vehicle/camera/rgb/front/image_color. I'm able to subscribe to this topic and see the data when I display the class, but I am unable to extract the data from the class. By using this code:

def camera_callback(data):
rospy.Subscriber('carla/ego_vehicle/camera/rgb/front/image_color', Image, camera_callback)

I am able to see the image data as a list of numbers, but once I try to extract the data ( like this:

def camera_callback(data):
rospy.Subscriber('carla/ego_vehicle/camera/rgb/front/image_color', Image, camera_callback)

It spits out what looks like it's reading a binary file and I'm unable to view the list of numbers. How can I extract the data and view the list so I can use the data?

edit retag flag offensive close merge delete


For readability could you use the formatting settings to properly format the code?

davekroezen gravatar image davekroezen  ( 2020-01-09 04:40:58 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-01-09 04:59:52 -0500

davekroezen gravatar image

If you look at the definition of sensor_msgs/Image.msg you can see that the data type of the 'data' field is uint8[]. Python2 interpreters uint8[] as a string, so to use it as a list you have to convert it to a list or other data type that you want to use. To do the conversion you could for example use cv_bridge or do the conversion yourself.

If you print the whole class as in your first example, it actually uses the __repr__ and __str__ functions of the class to produce the readable output summarising the content of the class. This converts the uint8[] data to the readable list you see.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-01-08 16:03:19 -0500

Seen: 577 times

Last updated: Jan 09 '20