@@ -130,18 +130,24 @@ def _append_images(self, imgs):
130
130
out_bgr = jsk_recognition_utils .get_tile_image (
131
131
imgs , tile_shape = shape_xy )
132
132
self .cache_img = out_bgr
133
- bridge = cv_bridge .CvBridge ()
134
- imgmsg = bridge .cv2_to_imgmsg (out_bgr , encoding = 'bgr8' )
135
- self .pub_img .publish (imgmsg )
136
-
137
- compressed_msg = CompressedImage ()
138
- compressed_msg .header = imgmsg .header
139
- compressed_msg .format = imgmsg .encoding + '; jpeg compressed bgr8'
140
- compressed_msg .data = np .array (
141
- cv2 .imencode ('.jpg' , out_bgr )[1 ]).tostring ()
142
- self .pub_compressed_img .publish (compressed_msg )
133
+ if self .pub_img .get_num_connections () > 0 :
134
+ bridge = cv_bridge .CvBridge ()
135
+ imgmsg = bridge .cv2_to_imgmsg (out_bgr , encoding = 'bgr8' )
136
+ self .pub_img .publish (imgmsg )
137
+
138
+ if self .pub_compressed_img .get_num_connections () > 0 :
139
+ compressed_msg = CompressedImage ()
140
+ compressed_msg .header = imgmsg .header
141
+ compressed_msg .format = imgmsg .encoding + '; jpeg compressed bgr8'
142
+ compressed_msg .data = np .array (
143
+ cv2 .imencode ('.jpg' , out_bgr )[1 ]).tostring ()
144
+ self .pub_compressed_img .publish (compressed_msg )
143
145
144
146
def _apply (self , * msgs ):
147
+ if self .pub_img .get_num_connections () == 0 and
148
+ self .pub_compressed_img .get_num_connections () == 0 :
149
+ return
150
+
145
151
bridge = cv_bridge .CvBridge ()
146
152
imgs = []
147
153
for msg , topic in zip (msgs , self .input_topics ):
0 commit comments