8 from jsk_topic_tools
import ConnectionBasedTransport
10 from sensor_msgs.msg
import Image
16 super(SplitForeBackground, self).
__init__()
18 '~output/fg_mask', Image, queue_size=10)
20 '~output/bg_mask', Image, queue_size=10)
23 self.
sub = rospy.Subscriber(
'~input', Image, self.
_apply)
30 supported_encodings = {
'16UC1',
'32FC1'}
31 if depth_msg.encoding
not in supported_encodings:
32 rospy.logwarn(
'Unsupported depth image encoding: {0}' 33 .format(depth_msg.encoding))
35 bridge = cv_bridge.CvBridge()
36 depth = bridge.imgmsg_to_cv2(depth_msg)
38 if depth_msg.encoding ==
'32FC1':
40 nan_mask = np.isnan(depth)
43 depth = depth.astype(np.uint8)
44 fg_mask, bg_mask = split_fore_background(depth)
45 if nan_mask
is not None:
49 fg_mask = (fg_mask * 255).astype(np.uint8)
50 fg_mask_msg = bridge.cv2_to_imgmsg(fg_mask, encoding=
'mono8')
51 fg_mask_msg.header = depth_msg.header
52 self.fg_mask_pub_.publish(fg_mask_msg)
54 bg_mask = (bg_mask * 255).astype(np.uint8)
55 bg_mask_msg = bridge.cv2_to_imgmsg(bg_mask, encoding=
'mono8')
56 bg_mask_msg.header = depth_msg.header
57 self.bg_mask_pub_.publish(bg_mask_msg)
60 if __name__ ==
'__main__':
61 rospy.init_node(
'split_fore_background')
def _apply(self, depth_msg)