static_virtual_camera.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 from sensor_msgs.msg import CameraInfo
16 
17 
18 def timer_cb(event):
19  imgmsg.header.stamp = rospy.Time.now()
20  info_msg.header.stamp = imgmsg.header.stamp
21  pub_img.publish(imgmsg)
22  pub_info.publish(info_msg)
23 
24 
25 if __name__ == '__main__':
26  rospy.init_node('static_virtual_camera')
27 
28  pub_img = rospy.Publisher('~image_color', Image, queue_size=1)
29  pub_info = rospy.Publisher('~camera_info', CameraInfo, queue_size=1)
30 
31  bridge = cv_bridge.CvBridge()
32  imgmsg = bridge.cv2_to_imgmsg(img, encoding='bgr8')
33  imgmsg.header.frame_id = 'static_virtual_camera'
34 
35  info_msg = CameraInfo()
36  info_msg.header.frame_id = imgmsg.header.frame_id
37  height, width = img.shape[:2]
38  info_msg.height = height
39  info_msg.width = width
40 
41  rospy.Timer(rospy.Duration(0.1), timer_cb)
42  rospy.spin()


jsk_recognition_utils
Author(s):
autogenerated on Fri Dec 6 2019 04:02:51