6 from jsk_topic_tools
import ConnectionBasedTransport
7 from jsk_recognition_msgs.msg
import RectArray, Rect
8 from sensor_msgs.msg
import Image
9 import dynamic_reconfigure.server
10 from jsk_perception.cfg
import SelectiveSearchConfig
16 super(SelectiveSearch, self).
__init__()
17 dynamic_reconfigure.server.Server(
19 self.
pub_ = self.advertise(
'~output', RectArray, queue_size=10)
20 self.
debug_pub_ = self.advertise(
'~debug', Image, queue_size=1)
23 self.
sub_ = rospy.Subscriber(
'~input', Image, self.
_apply, queue_size=1)
26 self.sub_.unregister()
32 bridge = cv_bridge.CvBridge()
33 img_bgr = bridge.imgmsg_to_cv2(img_msg, desired_encoding=
'bgr8')
34 img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
36 dlib.find_candidate_object_locations(img_rgb, rects,
38 ros_rect_array = RectArray()
39 ros_rect_array.header = img_msg.header
41 if (d.right() - d.left()) * (d.bottom() - d.top()) > self.
max_size:
43 cv2.rectangle(img_bgr, (d.left(), d.top()), (d.right(), d.bottom()), (255, 0, 0), 3)
44 ros_rect_array.rects.append(Rect(x=d.left(), y=d.top(), width=d.right() - d.left(), height=d.bottom() - d.top()))
45 imgmsg = bridge.cv2_to_imgmsg(img_bgr, encoding=
'bgr8')
46 self.debug_pub_.publish(imgmsg)
47 self.pub_.publish(ros_rect_array)
50 if __name__ ==
'__main__':
51 rospy.init_node(
'selective_search')
def _cb_dyn_reconfig(self, config, level)
def _apply(self, img_msg)