File tree 1 file changed +37
-0
lines changed 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ import argparse
3
+
4
+ import rospy
5
+
6
+ from sensor_msgs .msg import Image
7
+
8
+ from image_recognition_msgs .srv import Recognize
9
+
10
+ def extract_color_client (img_msg ):
11
+
12
+ rospy .wait_for_service ('extract_color' )
13
+ try :
14
+ extract_color = rospy .ServiceProxy ('extract_color' , Recognize )
15
+ return extract_color (img_msg )
16
+ except rospy .ServiceException as e :
17
+ print ("Service call failed: %s" % e )
18
+
19
+ # Create a callback function for the subscriber.
20
+ def callback (msg ):
21
+
22
+ # Simply print out values in our custom message.
23
+ colors = extract_color_client (msg )
24
+ rospy .loginfo (colors )
25
+
26
+
27
+ if __name__ == '__main__' :
28
+
29
+ rospy .init_node ('pose_estimation_image_subscriber' )
30
+
31
+ parser = argparse .ArgumentParser (description = 'Get dominant colors from image' )
32
+ parser .add_argument ('--topic' , default = '/image' , type = str , help = 'Topic' )
33
+ args = parser .parse_args ()
34
+ sub = rospy .Subscriber (args .topic , Image , callback )
35
+ rospy .loginfo ('Node has been started' )
36
+
37
+ rospy .spin ()
You can’t perform that action at this time.
0 commit comments