Open awesomebytes opened 7 years ago
I've run into this, too. Appears to be a rosbag issue, not a ros_numpy
issue. Also plays havoc with pickle
. I found that I could work around this by inserting the correct __class__
when loading from a rosbag. Lame, but it works for my need:
for msg in msgs:
if msg.topic == odom_topic:
msg.message.__class__ = nav_msgs.msg._Odometry.Odometry
odom_msgs.append(msg.message)
if msg.topic == scan_topic:
msg.message.__class__ = sensor_msgs.msg._PointCloud2.PointCloud2
scan_msgs.append(msg.message)
Based on the answer by rarmstrong22.
For anyone searching for a quick working solution. In case you are sure it is a ROS Image message but it still throws this error.
This worked for me:
import ros_numpy
import sensor_msgs
def get_img_from_ros_image_msg(msg):
""" Returns image as a numpy array.
Note: can be used with any topic of message type 'sensor_msgs/Image'
"""
msg.__class__ = sensor_msgs.msg.Image
return ros_numpy.numpify(msg)
img_array = get_img_from_ros_image_msg(msg)
If reading messages from a rosbag one gets an error like:
That's because
From a rosbag the messages don't seem to have the proper type (I guess it has something to do with the way messages are stored).