6 from collections.abc
import Sequence
as collections_Sequence
8 from collections
import Sequence
as collections_Sequence
12 import jsk_recognition_utils
13 from jsk_topic_tools
import ConnectionBasedTransport
14 import message_filters
17 from sensor_msgs.msg
import CompressedImage
18 from sensor_msgs.msg
import Image
19 import itertools, pkg_resources
20 from distutils.version
import StrictVersion
21 from threading
import Lock
25 color=(0, 255, 0), fg_color=(0, 0, 0), loc=
'ltb'):
26 font_face = cv2.FONT_HERSHEY_SIMPLEX
27 size, baseline = cv2.getTextSize(text, font_face, font_scale, thickness)
34 pt2 = (size[0], size[1] + baseline)
37 pt1 = (W - size[0], H - size[1] - baseline)
39 pt3 = (W - size[0], H - baseline)
43 cv2.rectangle(img, pt1, pt2, color=color, thickness=-1)
44 cv2.putText(img, text, pt3, font_face, font_scale, fg_color, thickness)
53 rospy.logerr(
'need to specify input_topics')
55 self.
_shape = rospy.get_param(
'~shape',
None)
57 if not (isinstance(self.
_shape, collections_Sequence)
and
59 rospy.logerr(
'~shape must be a list of 2 float values.')
62 rospy.logerr(
'Tile size must be larger than # of input topics')
67 self.
no_sync = rospy.get_param(
'~no_sync',
False)
70 StrictVersion(pkg_resources.get_distribution(
'message_filters').version) < StrictVersion(
'1.11.4')
and
72 rospy.logerr(
'hydro message_filters does not support approximate sync. Force to set ~approximate_sync=false')
74 self.
pub_img = self.advertise(
'~output', Image, queue_size=1)
84 queue_size = rospy.get_param(
'~queue_size', 10)
85 slop = rospy.get_param(
'~slop', 1)
90 sync = message_filters.ApproximateTimeSynchronizer(
92 sync.registerCallback(self.
_apply)
96 sync.registerCallback(self.
_apply)
111 bridge = cv_bridge.CvBridge()
112 img = bridge.imgmsg_to_cv2(msg, desired_encoding=
'bgr8')
127 imgs, tile_shape=shape_xy)
132 imgs, tile_shape=shape_xy, result_img=self.
cache_img)
135 imgs, tile_shape=shape_xy)
139 stamp = rospy.Time.now()
140 if self.
pub_img.get_num_connections() > 0:
141 bridge = cv_bridge.CvBridge()
142 imgmsg = bridge.cv2_to_imgmsg(out_bgr, encoding=encoding)
143 imgmsg.header.stamp = stamp
147 compressed_msg = CompressedImage()
148 compressed_msg.header.stamp = stamp
149 compressed_msg.format = encoding +
'; jpeg compressed ' + encoding
150 compressed_msg.data = np.array(
151 cv2.imencode(
'.jpg', out_bgr)[1]).tostring()
155 if (self.
pub_img.get_num_connections() == 0
159 bridge = cv_bridge.CvBridge()
162 img = bridge.imgmsg_to_cv2(msg, desired_encoding=
'bgr8')
170 if __name__ ==
'__main__':
171 rospy.init_node(
'tile_image')