-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathsubscriber.py
executable file
·36 lines (30 loc) · 1.07 KB
/
subscriber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env python
# Import ROS.
import rospy
# Importing BoundingBoxes message from package darknet_ros_msgs.
from darknet_ros_msgs.msg import BoundingBoxes
def detection_cb(msg):
# Callback function of the subscriber.
# Assigning bounding_boxes of the message to bbox variable.
bbox = msg.bounding_boxes
for i in range(len(bbox)):
# Printing the detected object with its probability in percentage.
rospy.loginfo("{}% certain {} detected.".format(
float(bbox[i].probability * 100), bbox[i].Class))
def main():
# Initializing ROS node.
rospy.init_node("Detection_sub")
# Creating a subscriber for the topic "/darknet_ros/bounding_boxes".
rospy.Subscriber(name="/darknet_ros/bounding_boxes",
data_class=BoundingBoxes,
callback=detection_cb,
queue_size=1)
# Driver code.
if __name__ == '__main__':
try:
main()
# Used to keep the node running.
rospy.spin()
except KeyboardInterrupt:
rospy.loginfo("Closing")
exit()