ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

sensor_msgs/Image data value is a string?

asked 2013-04-02 18:34:20 -0500

robzz gravatar image

updated 2014-01-28 17:16:00 -0500

ngrennan gravatar image

I've written a node in python to read a binary image (of type sensor_msgs/Image) being published on a topic. I got confused when trying to access the data in the callback.

print img


  seq: 35232
    secs: 0
    nsecs: 0
  frame_id: ''
height: 40
width: 127
encoding: 8UC3
is_bigendian: 0
step: 381
data: [0, 0, 0, 0, ...]

I shortened the data array with an ellipsis.

What's weird are the types of the data.

print type(, type([0])


<type 'str'> <type 'str'>

When I try to display the data with "print" I get a bunch of junk characters. When I try to index into the first element, I get an empty string.

This confuses me because the description of the topic type Image specifies that the field is an array of bytes. Why am I seeing a string here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-04-02 19:03:33 -0500

According to the msg documentation, rospy automatically interprets byte arrays (uint8[]) as strings.

See this cv_bridge tutorial for an example of how to convert image data from a ROS message (byte array) to a "real" IplImage for further processing.

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


Asked: 2013-04-02 18:34:20 -0500

Seen: 5,672 times

Last updated: Apr 02 '13