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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 import sys
00036 import time
00037 import math
00038 import rospy
00039 import numpy
00040 import cv2
00041
00042 import sensor_msgs.msg
00043 from cv_bridge import CvBridge
00044
00045
00046
00047 class Source:
00048
00049 def __init__(self):
00050 self.pub = rospy.Publisher("/opencv_tests/images", sensor_msgs.msg.Image)
00051 self.pub_compressed = rospy.Publisher("/opencv_tests/images/compressed", sensor_msgs.msg.CompressedImage)
00052
00053 def spin(self):
00054 time.sleep(1.0)
00055 started = time.time()
00056 counter = 0
00057 cvim = numpy.zeros((480, 640, 1), numpy.uint8)
00058 ball_xv = 10
00059 ball_yv = 10
00060 ball_x = 100
00061 ball_y = 100
00062
00063 cvb = CvBridge()
00064
00065 while not rospy.core.is_shutdown():
00066
00067 cvim.fill(0)
00068 cv2.circle(cvim, (ball_x, ball_y), 10, 255, -1)
00069
00070 ball_x += ball_xv
00071 ball_y += ball_yv
00072 if ball_x in [10, 630]:
00073 ball_xv = -ball_xv
00074 if ball_y in [10, 470]:
00075 ball_yv = -ball_yv
00076
00077 self.pub.publish(cvb.cv2_to_imgmsg(cvim))
00078 self.pub_compressed.publish(cvb.cv2_to_compressed_imgmsg(cvim))
00079 time.sleep(0.03)
00080
00081
00082 def main(args):
00083 s = Source()
00084 rospy.init_node('Source')
00085 try:
00086 s.spin()
00087 rospy.spin()
00088 outcome = 'test completed'
00089 except KeyboardInterrupt:
00090 print "shutting down"
00091 outcome = 'keyboard interrupt'
00092 rospy.core.signal_shutdown(outcome)
00093
00094 if __name__ == '__main__':
00095 main(sys.argv)