Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish compressed tile image #2857

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions jsk_perception/node_scripts/tile_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import jsk_recognition_utils
from jsk_topic_tools import ConnectionBasedTransport
import message_filters
import numpy as np
import rospy
from sensor_msgs.msg import CompressedImage
from sensor_msgs.msg import Image
import itertools, pkg_resources
from distutils.version import StrictVersion
Expand Down Expand Up @@ -66,6 +68,7 @@ def __init__(self):
rospy.logerr('hydro message_filters does not support approximate sync. Force to set ~approximate_sync=false')
self.approximate_sync = False
self.pub_img = self.advertise('~output', Image, queue_size=1)
self.pub_compressed_img = self.advertise('~output/compressed', CompressedImage, queue_size=1)

def subscribe(self):
self.sub_img_list = []
Expand All @@ -87,14 +90,17 @@ def subscribe(self):
sync = message_filters.TimeSynchronizer(
self.sub_img_list, queue_size=queue_size)
sync.registerCallback(self._apply)

def unsubscribe(self):
for sub in self.sub_img_list:
sub.sub.unregister()

def timer_callback(self, event):
with self.lock:
imgs = [self.input_imgs[topic] for topic in self.input_topics
if topic in self.input_imgs]
self._append_images(imgs)

def simple_callback(self, target_topic):
def callback(msg):
with self.lock:
Expand All @@ -105,6 +111,7 @@ def callback(msg):
draw_text_box(img, rospy.resolve_name(target_topic),
font_scale=self.font_scale)
return callback

def _append_images(self, imgs):
if not imgs:
return
Expand All @@ -126,6 +133,14 @@ def _append_images(self, imgs):
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)

def _apply(self, *msgs):
bridge = cv_bridge.CvBridge()
imgs = []
Expand Down
Loading