Skip to content

Commit

Permalink
[jsk_perception/node_scripts/tile_image.py] process and publish only …
Browse files Browse the repository at this point in the history
…when subscriber exists
  • Loading branch information
k-okada authored and knorth55 committed Dec 29, 2024
1 parent c518162 commit e1615fb
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions jsk_perception/node_scripts/tile_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,24 @@ def _append_images(self, imgs):
out_bgr = jsk_recognition_utils.get_tile_image(
imgs, tile_shape=shape_xy)
self.cache_img = out_bgr
bridge = cv_bridge.CvBridge()
imgmsg = bridge.cv2_to_imgmsg(out_bgr, encoding='bgr8')
self.pub_img.publish(imgmsg)

compressed_msg = CompressedImage()
compressed_msg.header = imgmsg.header
compressed_msg.format = imgmsg.encoding + '; jpeg compressed bgr8'
compressed_msg.data = np.array(
cv2.imencode('.jpg', out_bgr)[1]).tostring()
self.pub_compressed_img.publish(compressed_msg)
if self.pub_img.get_num_connections() > 0:
bridge = cv_bridge.CvBridge()
imgmsg = bridge.cv2_to_imgmsg(out_bgr, encoding='bgr8')
self.pub_img.publish(imgmsg)

if self.pub_compressed_img.get_num_connections() > 0:
compressed_msg = CompressedImage()
compressed_msg.header = imgmsg.header
compressed_msg.format = imgmsg.encoding + '; jpeg compressed bgr8'
compressed_msg.data = np.array(
cv2.imencode('.jpg', out_bgr)[1]).tostring()
self.pub_compressed_img.publish(compressed_msg)

def _apply(self, *msgs):
if self.pub_img.get_num_connections() == 0 and
self.pub_compressed_img.get_num_connections() == 0:
return

bridge = cv_bridge.CvBridge()
imgs = []
for msg, topic in zip(msgs, self.input_topics):
Expand Down

0 comments on commit e1615fb

Please sign in to comment.