8 import jsk_recognition_utils
9 from jsk_topic_tools
import ConnectionBasedTransport
10 import message_filters
12 from sensor_msgs.msg
import Image
13 import itertools, pkg_resources
14 from distutils.version
import StrictVersion
15 from threading
import Lock
19 color=(0, 255, 0), fg_color=(0, 0, 0), loc=
'ltb'):
20 font_face = cv2.FONT_HERSHEY_SIMPLEX
21 size, baseline = cv2.getTextSize(text, font_face, font_scale, thickness)
28 pt2 = (size[0], size[1] + baseline)
31 pt1 = (W - size[0], H - size[1] - baseline)
33 pt3 = (W - size[0], H - baseline)
37 cv2.rectangle(img, pt1, pt2, color=color, thickness=-1)
38 cv2.putText(img, text, pt3, font_face, font_scale, fg_color, thickness)
47 rospy.logerr(
'need to specify input_topics')
49 self.
_shape = rospy.get_param(
'~shape',
None)
51 if not (isinstance(self.
_shape, collections.Sequence)
and 53 rospy.logerr(
'~shape must be a list of 2 float values.')
56 rospy.logerr(
'Tile size must be larger than # of input topics')
61 self.
no_sync = rospy.get_param(
'~no_sync',
False)
64 StrictVersion(pkg_resources.get_distribution(
'message_filters').version) < StrictVersion(
'1.11.4')
and 66 rospy.logerr(
'hydro message_filters does not support approximate sync. Force to set ~approximate_sync=false')
68 self.
pub_img = self.advertise(
'~output', Image, queue_size=1)
77 queue_size = rospy.get_param(
'~queue_size', 10)
78 slop = rospy.get_param(
'~slop', 1)
81 self.sub_img_list.append(sub_img)
83 sync = message_filters.ApproximateTimeSynchronizer(
85 sync.registerCallback(self.
_apply)
89 sync.registerCallback(self.
_apply)
101 bridge = cv_bridge.CvBridge()
102 img = bridge.imgmsg_to_cv2(msg, desired_encoding=
'bgr8')
116 imgs, tile_shape=shape_xy)
121 imgs, tile_shape=shape_xy, result_img=self.
cache_img)
124 imgs, tile_shape=shape_xy)
126 bridge = cv_bridge.CvBridge()
127 imgmsg = bridge.cv2_to_imgmsg(out_bgr, encoding=
'bgr8')
128 self.pub_img.publish(imgmsg)
130 bridge = cv_bridge.CvBridge()
133 img = bridge.imgmsg_to_cv2(msg, desired_encoding=
'bgr8')
141 if __name__ ==
'__main__':
142 rospy.init_node(
'tile_image')
def simple_callback(self, target_topic)
def draw_text_box(img, text, font_scale=0.8, thickness=2, color=(0, 255, 0), fg_color=(0, 0, 0), loc='ltb')
def _append_images(self, imgs)
void callback(const sensor_msgs::Image::ConstPtr &rgb_image, const sensor_msgs::Image::ConstPtr &depth_image, const sensor_msgs::CameraInfo::ConstPtr &rgb_camera_info, const sensor_msgs::CameraInfo::ConstPtr &depth_camera_info)
def timer_callback(self, event)