publish_lena.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 import cv2
5 import numpy as np
6 from distutils.version import LooseVersion
7 import scipy
8 if LooseVersion(scipy.__version__) >= LooseVersion("0.17"):
9  from scipy.misc import ascent
10 else:
11  from scipy.misc import lena
12 
13 import rospy
14 from sensor_msgs.msg import Image
15 import cv_bridge
16 
17 
18 def main():
19  pub = rospy.Publisher('image', Image, queue_size=1)
20  # lena is no longer available since 0.17 due to license issue
21  if LooseVersion(scipy.__version__) >= LooseVersion("0.17"):
22  img = cv2.cvtColor(ascent().astype(np.uint8), cv2.COLOR_GRAY2BGR)
23  else:
24  img = cv2.cvtColor(lena().astype(np.uint8), cv2.COLOR_GRAY2BGR)
25 
26  bridge = cv_bridge.CvBridge()
27  msg = bridge.cv2_to_imgmsg(img, encoding='bgr8')
28  msg.header.frame_id = 'camera'
29  # publish in 30 hz
30  rate = rospy.Rate(30)
31  while not rospy.is_shutdown():
32  msg.header.stamp = rospy.get_rostime()
33  pub.publish(msg)
34  rate.sleep()
35 
36 
37 if __name__ == '__main__':
38  rospy.init_node('publish_lena')
39  main()


image_view2
Author(s): Kei Okada
autogenerated on Tue Feb 6 2018 03:45:03