Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 import roslib
00026 roslib.load_manifest('falkor_ardrone')
00027
00028 import sys
00029 import rospy
00030 import cv
00031 import cv2
00032 import math
00033
00034 from std_msgs.msg import String
00035 from sensor_msgs.msg import Image
00036 from geometry_msgs.msg import Point
00037 from cv_bridge import CvBridge, CvBridgeError
00038
00039 import numpy as np
00040 import tracker
00041
00042 class ardroneTracker:
00043
00044 def __init__(self, tracker):
00045 self.point_pub = rospy.Publisher("/ardrone_tracker/found_point", Point )
00046
00047 self.bridge = CvBridge()
00048 self.image_sub = rospy.Subscriber("/ardrone/front/image_raw",Image,self.callback)
00049 self.image_pub = rospy.Publisher( "/ardrone_tracker/image", Image )
00050
00051 self.tracker = tracker
00052
00053 def callback(self,data):
00054 try:
00055 cv_image = self.bridge.imgmsg_to_cv(data, "bgr8")
00056 except CvBridgeError, e:
00057 print e
00058
00059 numpy_image = np.asarray( cv_image )
00060 trackData = self.tracker.track( numpy_image )
00061 if trackData:
00062 x,y,z = trackData[0],trackData[1],trackData[2]
00063
00064 point = Point( x,y,z )
00065 self.point_pub.publish( point )
00066 else:
00067 self.point_pub.publish( Point( 0, 0, -1 ) )
00068
00069 try:
00070 vis = self.tracker.get_vis()
00071 image_message = self.bridge.cv_to_imgmsg(cv2.cv.fromarray( vis ), encoding="passthrough")
00072 self.image_pub.publish( image_message )
00073 except CvBridgeError, e:
00074 print e
00075
00076 def main():
00077 rospy.init_node( 'ardrone_tracker' )
00078
00079
00080
00081
00082 cascade_file = rospy.get_param( '~cascadefile', 'NULL' )
00083 if cascade_file == 'NULL':
00084 print "Must set cascadefile parameter!"
00085 exit
00086
00087 ardroneTracker( tracker.CascadeTracker( cascade_file ) )
00088 try:
00089 rospy.spin()
00090 except KeyboardInterrupt:
00091 print "Shutting down"
00092 cv.DestroyAllWindows()
00093
00094 if __name__ == '__main__':
00095
00096
00097 main()