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(list(range(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 
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood._sync
_sync
Definition: extract_top_polygon_likelihood.py:24
msg
msg
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood._srv
_srv
Definition: extract_top_polygon_likelihood.py:15
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood._sub_coef
_sub_coef
Definition: extract_top_polygon_likelihood.py:23
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood._sub
_sub
Definition: extract_top_polygon_likelihood.py:22
message_filters::Subscriber
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood._pub
_pub
Definition: extract_top_polygon_likelihood.py:16
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood.subscribe
def subscribe(self)
Definition: extract_top_polygon_likelihood.py:21
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood.unsubscribe
def unsubscribe(self)
Definition: extract_top_polygon_likelihood.py:26
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood._min_likelihood
_min_likelihood
Definition: extract_top_polygon_likelihood.py:19
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood.config_callback
def config_callback(self, config, level)
Definition: extract_top_polygon_likelihood.py:18
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood
Definition: extract_top_polygon_likelihood.py:12
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood.callback
def callback(self, msg, msg_coef)
Definition: extract_top_polygon_likelihood.py:29
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood.__init__
def __init__(self)
Definition: extract_top_polygon_likelihood.py:13
extract_top_polygon_likelihood.ExtractTopPolygonLikelihood._pub_coef
_pub_coef
Definition: extract_top_polygon_likelihood.py:17
message_filters::TimeSynchronizer


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Tue Jan 7 2025 04:05:44