Ask Your Question
0

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

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

ngoberville gravatar image

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

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):
    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?

edit retag flag offensive close merge delete

Comments

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

davekroezen gravatar imagedavekroezen ( 2020-01-09 04:40:58 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 29 times

Last updated: Jan 09