6 from scipy.misc
import face
7 img = face()[:, :, ::-1]
9 from scipy.misc
import lena
10 img = cv2.cvtColor(lena().astype(np.uint8), cv2.COLOR_GRAY2BGR)
14 from sensor_msgs.msg
import Image, CompressedImage
15 from sensor_msgs.msg
import CameraInfo
19 imgmsg.header.stamp = rospy.Time.now()
20 info_msg.header.stamp = imgmsg.header.stamp
21 if pub_img.get_num_connections() > 0:
22 pub_img.publish(imgmsg)
23 if pub_img_compressed.get_num_connections() > 0:
24 pub_img_compressed.publish(compmsg)
25 pub_info.publish(info_msg)
28 if __name__ ==
'__main__':
29 rospy.init_node(
'static_virtual_camera')
32 transport_hint = rospy.get_param(
'~image_transport',
'raw')
33 rospy.loginfo(
"Using transport {}".
format(transport_hint))
35 pub_img = rospy.Publisher(
'~image_color', Image, queue_size=1)
36 pub_img_compressed = rospy.Publisher(
'~image_color/compressed', CompressedImage, queue_size=1)
37 pub_info = rospy.Publisher(
'~camera_info', CameraInfo, queue_size=1)
39 bridge = cv_bridge.CvBridge()
40 imgmsg = bridge.cv2_to_imgmsg(img, encoding=
'bgr8')
41 imgmsg.header.frame_id =
'static_virtual_camera' 42 compmsg = CompressedImage()
43 compmsg.header = imgmsg.header
44 compmsg.format =
"jpeg" 45 compmsg.data = np.array(cv2.imencode(
'.jpg', cv2.cvtColor(img, cv2.COLOR_BGR2RGB))[1]).tostring()
47 info_msg = CameraInfo()
48 info_msg.header.frame_id = imgmsg.header.frame_id
49 height, width = img.shape[:2]
50 info_msg.height = height
51 info_msg.width = width
53 rospy.Timer(rospy.Duration(0.1), timer_cb)