static_image_publisher.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import cv2
4 try:
5  from scipy.misc import face
6  img = face()[:, :, ::-1]
7 except ImportError:
8  import numpy as np
9  from scipy.misc import lena
10  img = cv2.cvtColor(lena().astype(np.uint8), cv2.COLOR_GRAY2BGR)
11 
12 import cv_bridge
13 import rospy
14 from sensor_msgs.msg import Image
15 
16 
17 def timer_cb(event):
18  imgmsg.header.stamp = rospy.Time.now()
19  pub_img.publish(imgmsg)
20 
21 
22 if __name__ == '__main__':
23  rospy.init_node('static_image_publisher')
24 
25  pub_img = rospy.Publisher('~output', Image, queue_size=1)
26 
27  bridge = cv_bridge.CvBridge()
28  imgmsg = bridge.cv2_to_imgmsg(img, encoding='bgr8')
29 
30  rospy.Timer(rospy.Duration(0.1), timer_cb)
31  rospy.spin()


jsk_topic_tools
Author(s): Kei Okada , Yusuke Furuta
autogenerated on Tue Feb 6 2018 03:45:19