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

sensor_msgs/Image data value is a string?

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

robzz gravatar image

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

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

produces

header: 
  seq: 35232
  stamp: 
    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(img.data), type(img.data[0])

produces

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

When I try to display the data with "print img.data" 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 img.data 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
1

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

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

Question Tools

Stats

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

Seen: 6,279 times

Last updated: Apr 02 '13