ros_to_cv.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import roslib
00004 roslib.load_manifest('pi_head_tracking_tutorial')
00005 import sys
00006 import rospy
00007 import cv
00008 from std_msgs.msg import String
00009 from sensor_msgs.msg import Image
00010 from cv_bridge import CvBridge, CvBridgeError
00011 
00012 class vision_node:
00013 
00014     def __init__(self):
00015         rospy.init_node('vision_node')
00016 
00017         self.cv_window_name = "OpenCV Image"
00018 
00019         cv.NamedWindow(self.cv_window_name, 1)
00020         self.bridge = CvBridge()
00021         self.image_sub = rospy.Subscriber("/camera/rgb/image_color", Image, self.callback)
00022 
00023     def callback(self, data):
00024         try:
00025           cv_image = self.bridge.imgmsg_to_cv(data, "bgr8")
00026         except CvBridgeError, e:
00027           print e
00028    
00029         cv.ShowImage(self.cv_window_name, cv_image)
00030         cv.WaitKey(3)
00031 
00032 def main(args):
00033       vn = vision_node()
00034       try:
00035         rospy.spin()
00036       except KeyboardInterrupt:
00037         print "Shutting down vison node."
00038         cv.DestroyAllWindows()
00039 
00040 if __name__ == '__main__':
00041     main(sys.argv)


pi_head_tracking_tutorial
Author(s): Patrick Goebel
autogenerated on Mon Oct 6 2014 03:27:15