image_16uc1_to_32fc1.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 
7 import numpy as np
8 
9 import cv_bridge
10 from jsk_topic_tools import ConnectionBasedTransport
11 import rospy
12 from sensor_msgs.msg import Image
13 
14 
15 class Image16UC1To32FC1(ConnectionBasedTransport):
16 
17  def __init__(self):
18  super(self.__class__, self).__init__()
19  self.pub = self.advertise('~output', Image, queue_size=1)
20 
21  def subscribe(self):
22  self.sub = rospy.Subscriber('~input', Image, self.transport)
23 
24  def unsubscribe(self):
25  self.sub.unregister()
26 
27  def transport(self, msg):
28  if msg.height * msg.width == 0:
29  return
30  bridge = cv_bridge.CvBridge()
31  img_16uc1 = bridge.imgmsg_to_cv2(msg, desired_encoding='16UC1')
32  img_32fc1 = (img_16uc1.astype(np.float64) / (2**16)).astype(np.float32)
33  out_msg = bridge.cv2_to_imgmsg(img_32fc1, '32FC1')
34  out_msg.header = msg.header
35  self.pub.publish(out_msg)
36 
37 
38 if __name__ == '__main__':
39  rospy.init_node('image_16uc1_to_32fc1')
41  rospy.spin()


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