37 from cv_bridge
import CvBridge, CvBridgeError
38 from sensor_msgs.msg
import Image, CompressedImage
41 '''A class to subscribe to a ROS camera''' 44 '''Initialize ros publisher, ros subscriber''' 48 self.
compressed =
True if "compressed" in topic
else False 58 topic, CompressedImage, self.
callback, queue_size=1)
61 '''Callback function of subscribed topic. 62 Here images get converted to cv2 format''' 66 self.bridge.imgmsg_to_cv2(ros_data,
"rgb8"),
69 np_arr = np.fromstring(ros_data.data, np.uint8)
70 image_np = cv2.imdecode(np_arr, 1)
72 self.
currentImage = cv2.cvtColor(image_np, cv2.COLOR_BGR2RGB)