コード例 #1
0
 def _apply(self, feature_msg, label_msg):
     bridge = cv_bridge.CvBridge()
     label = bridge.imgmsg_to_cv2(label_msg)
     desc = np.array(feature_msg.descriptors)
     desc = desc.reshape((-1, feature_msg.descriptor_dim))
     pos = np.array(feature_msg.positions)
     pos = pos.reshape((-1, 2))
     if label.sum() == 0:
         jsk_logdebug('Skip image with only background label')
         return
     decomposed = decompose_descriptors_with_label(descriptors=desc,
                                                   positions=pos,
                                                   label_img=label,
                                                   skip_zero_label=True)
     X = np.array(decomposed.values())
     if X.size == 0:
         return
     X = self.bof.transform(X)
     normalize(X, copy=False)
     self._pub.publish(
         VectorArray(
             header=feature_msg.header,
             vector_dim=X.shape[1],
             data=X.reshape(-1),
         ))
コード例 #2
0
 def _apply(self, msg):
     bridge = cv_bridge.CvBridge()
     mask = bridge.imgmsg_to_cv2(msg, desired_encoding='mono8')
     if mask.size == 0:
         jsk_logdebug('Skipping empty image')
         return
     label = np.zeros(mask.shape, dtype=np.int32)
     label[mask == 0] = 0
     label[mask == 255] = 1
     label_msg = bridge.cv2_to_imgmsg(label, encoding='32SC1')
     label_msg.header = msg.header
     self._pub.publish(label_msg)
コード例 #3
0
 def subscribe(self):
     self._sub_feature = message_filters.Subscriber('~input', Feature0D)
     self._sub_label = message_filters.Subscriber('~input/label', Image)
     use_async = rospy.get_param('~approximate_sync', False)
     if use_async:
         sync = message_filters.ApproximateTimeSynchronizer(
             [self._sub_feature, self._sub_label], queue_size=10, slop=0.1)
     else:
         sync = message_filters.TimeSynchronizer(
             [self._sub_feature, self._sub_feature], queue_size=10)
     jsk_logdebug('~approximate_sync: {}'.format(use_async))
     sync.registerCallback(self._apply)
コード例 #4
0
 def subscribe(self):
     self._sub_feature = message_filters.Subscriber('~input', Feature0D)
     self._sub_label = message_filters.Subscriber('~input/label', Image)
     use_async = rospy.get_param('~approximate_sync', False)
     if use_async:
         sync = message_filters.ApproximateTimeSynchronizer(
             [self._sub_feature, self._sub_label], queue_size=10, slop=0.1)
     else:
         sync = message_filters.TimeSynchronizer(
             [self._sub_feature, self._sub_feature], queue_size=10)
     jsk_logdebug('~approximate_sync: {}'.format(use_async))
     sync.registerCallback(self._apply)
コード例 #5
0
 def _apply(self, feature_msg, label_msg):
     bridge = cv_bridge.CvBridge()
     label = bridge.imgmsg_to_cv2(label_msg)
     desc = np.array(feature_msg.descriptors)
     desc = desc.reshape((-1, feature_msg.descriptor_dim))
     pos = np.array(feature_msg.positions)
     pos = pos.reshape((-1, 2))
     if label.sum() == 0:
         jsk_logdebug('Skip image with only background label')
         return
     decomposed = decompose_descriptors_with_label(
         descriptors=desc, positions=pos, label_img=label,
         skip_zero_label=True)
     X = self.bof.transform(np.array(decomposed.values()))
     normalize(X, copy=False)
     self._pub.publish(
         VectorArray(
             header=feature_msg.header,
             vector_dim=X.shape[1],
             data=X.reshape(-1),
         ))