extract_top_polygon_likelihood.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 from jsk_topic_tools import ConnectionBasedTransport
5 from jsk_recognition_msgs.msg import PolygonArray, ModelCoefficientsArray
6 from pcl_msgs.msg import ModelCoefficients
7 from geometry_msgs.msg import PolygonStamped
8 import message_filters
9 from dynamic_reconfigure.server import Server
10 from jsk_pcl_ros.cfg import ExtractTopPolygonLikelihoodConfig
11 
12 class ExtractTopPolygonLikelihood(ConnectionBasedTransport):
13  def __init__(self):
14  super(ExtractTopPolygonLikelihood, self).__init__()
15  self._srv = Server(ExtractTopPolygonLikelihoodConfig, self.config_callback)
16  self._pub = self.advertise("~output", PolygonArray, queue_size=1)
17  self._pub_coef = self.advertise("~output/coefficients", ModelCoefficientsArray, queue_size=1)
18  def config_callback(self, config, level):
19  self._min_likelihood = config.min_likelihood
20  return config
21  def subscribe(self):
22  self._sub = message_filters.Subscriber("~input", PolygonArray)
23  self._sub_coef = message_filters.Subscriber("~input/coefficients", ModelCoefficientsArray)
25  self._sync.registerCallback(self.callback)
26  def unsubscribe(self):
27  self._sub.sub.unregister()
28  self._sub_coef.sub.unregister()
29  def callback(self, msg, msg_coef):
30  if len(msg.polygons) > 0:
31  #self._pub.publish(msg.histograms[0])
32  max_index = max(xrange(len(msg.polygons)), key=lambda i: msg.likelihood[i])
33  res = PolygonArray()
34  res.header = msg.header
35  res.polygons = [msg.polygons[max_index]]
36  res.likelihood = [msg.likelihood[max_index]]
37  if msg.likelihood[max_index] < self._min_likelihood:
38  rospy.loginfo("Ignore result because of too small likelihood: {0} < {1}".format(
39  msg.likelihood[max_index],
40  self._min_likelihood))
41  return
42  self._pub.publish(res)
43  res_coef = ModelCoefficientsArray()
44  res_coef.header = msg.header
45  res_coef.coefficients = [msg_coef.coefficients[max_index]]
46  self._pub_coef.publish(res_coef)
47 
48 
49 if __name__ == "__main__":
50  rospy.init_node("extract_top_polygon_likelihood")
52  rospy.spin()
53 
54 
double max(const OneDataStat &d)
wrapper function for max method for boost::function


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:46