Robotics StackExchange | Archived questions

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

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/egovehicle/camera/rgb/front/imagecolor. 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):
    print('CAMERA')
    rospy.loginfo(data)
    time.sleep(2)
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 (data.data) like this:

def camera_callback(data):
    print('CAMERA')
    rospy.loginfo(data.data)
    time.sleep(2)
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?

Asked by ngoberville on 2020-01-08 17:03:19 UTC

Comments

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

Asked by davekroezen on 2020-01-09 05:40:58 UTC

Answers

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.

Asked by davekroezen on 2020-01-09 05:59:52 UTC

Comments