publish_lena.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 import cv2
00005 import numpy as np
00006 from distutils.version import LooseVersion
00007 import scipy
00008 if LooseVersion(scipy.__version__) >= LooseVersion("0.17"):
00009     from scipy.misc import ascent
00010 else:
00011     from scipy.misc import lena
00012 
00013 import rospy
00014 from sensor_msgs.msg import Image
00015 import cv_bridge
00016 
00017 
00018 def main():
00019     pub = rospy.Publisher('image', Image, queue_size=1)
00020     # lena is no longer available since 0.17 due to license issue
00021     if LooseVersion(scipy.__version__) >= LooseVersion("0.17"):
00022         img = cv2.cvtColor(ascent().astype(np.uint8), cv2.COLOR_GRAY2BGR)
00023     else:
00024         img = cv2.cvtColor(lena().astype(np.uint8), cv2.COLOR_GRAY2BGR)
00025 
00026     bridge = cv_bridge.CvBridge()
00027     msg = bridge.cv2_to_imgmsg(img, encoding='bgr8')
00028     msg.header.frame_id = 'camera'
00029     # publish in 30 hz
00030     rate = rospy.Rate(30)
00031     while not rospy.is_shutdown():
00032         msg.header.stamp = rospy.get_rostime()
00033         pub.publish(msg)
00034         rate.sleep()
00035 
00036 
00037 if __name__ == '__main__':
00038     rospy.init_node('publish_lena')
00039     main()


image_view2
Author(s): Kei Okada
autogenerated on Fri Sep 8 2017 03:38:44