test_scene_query.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # This script is designed to test the functionality of the scene query
00003 
00004 import rospy
00005 import cv2
00006 from sensor_msgs.msg import Image
00007 from cv_bridge import CvBridge, CvBridgeError
00008 from rail_object_detection_msgs.srv import SceneQuery, SceneQueryRequest, SceneQueryResponse
00009 
00010 COLORS = [(10,10,10), (100,10,10), (200,10,10), (10,100,10), (10,200,10),
00011 (10,10,100), (10,10,200), (100,100,100), (200,100,100), (100,200,100),
00012 (100,100,200)]
00013 
00014 def main():
00015         rospy.init_node('test_scene_query_node')
00016         bridge = CvBridge()
00017 
00018         service_proxy = rospy.ServiceProxy('/darknet_node/objects_in_scene', SceneQuery)
00019 
00020         rate = rospy.Rate(.4)
00021         while not rospy.is_shutdown():
00022                 resp = service_proxy()
00023 
00024                 try:
00025                         # Draw and display the image
00026                         resp_cv = bridge.imgmsg_to_cv2(resp.image, "bgr8")
00027                         for idx,obj in enumerate(resp.objects):
00028                                 cv2.rectangle(
00029                                         resp_cv,
00030                                         (obj.left_bot_x, obj.left_bot_y),
00031                                         (obj.right_top_x, obj.right_top_y),
00032                                         COLORS[idx%len(COLORS)],
00033                                         3
00034                                 )
00035                         cv2.imshow('image', resp_cv)
00036                         cv2.waitKey(100)
00037                         rospy.loginfo("objects: %s" % ",".join([x.label for x in resp.objects]))
00038                 except CvBridgeError:
00039                         pass
00040 
00041                 rate.sleep()
00042 
00043 if __name__ == '__main__':
00044         main()


rail_object_detector
Author(s):
autogenerated on Sat Jun 8 2019 20:26:31