38 from std_msgs.msg
import Header, Int8MultiArray, MultiArrayDimension
39 from cnn_bridge.msg
import Netmask
43 '''A class to publish commands to ROS''' 45 def __init__(self, width, height, topic_name="mask"):
46 '''Initialize ros publisher, ros subscriber''' 48 rospy.get_name() +
'/' + topic_name, Netmask, queue_size=1)
50 self.
mask = Int8MultiArray()
51 self.mask.layout.dim.append(MultiArrayDimension())
52 self.mask.layout.dim.append(MultiArrayDimension())
53 self.mask.layout.dim[0].label =
"height" 54 self.mask.layout.dim[1].label =
"width" 55 self.mask.layout.dim[0].size = height
56 self.mask.layout.dim[1].size = width
57 self.mask.layout.dim[0].stride = height * width
58 self.mask.layout.dim[1].stride = width
59 self.mask.layout.data_offset = 0
62 """Set up a ROS camera 64 data (str) The data to send to ROS [throttle, steer] 67 rosgraph.Master(
'/rostopic').getPid()
69 raise ROSTopicIOException(
"Unable to communicate with master!")
71 start_time = timeit.default_timer()
73 mask_data = np.array(data)
75 np_arr_time = timeit.default_timer() - start_time
77 mask_data = np.array(data).flatten()
78 flatten_time = timeit.default_timer() - start_time - np_arr_time
80 mask_data = np.pad(mask_data, (self.mask.layout.data_offset, 0),
'constant')
81 pad_time = timeit.default_timer() - start_time- np_arr_time - flatten_time
83 self.mask.data = mask_data.tolist()
84 list_time = timeit.default_timer() - start_time - np_arr_time - flatten_time - pad_time
89 h.stamp = rospy.Time.now()
93 msg.image_identifier = meta_header
96 self.mask_pub.publish(msg)
def __init__(self, width, height, topic_name="mask")
def send_mask(self, data, meta_header)