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

Revision history [back]

click to hide/show revision 1
initial version

This will do what you want, assuming you have an RGB image. If not, you can check the data.encoding and add some extra logic.

import numpy as np
import rospy 
from sensor_msgs.msg import Image
from rospy.numpy_msg import numpy_msg

def vis_callback( data ):
  im = np.frombuffer(data.data, dtype=np.uint8).reshape(data.height, data.width, -1)
  doSomething(im)

rospy.init_node('bla', anonymous=True)
sub_vis = rospy.Subscriber('navbot/camera/image', numpy_msg(Image), vis_callback)

rospy.spin()