@@ -5,18 +5,33 @@ from __future__ import print_function
5
5
import argparse
6
6
7
7
import cv2
8
- from image_recognition_color_extractor import ColorExtractor
9
8
10
- # Assign description to the help doc
11
- parser = argparse .ArgumentParser (description = 'Get dominant colors from image' )
12
- parser .add_argument ('image' , type = argparse .FileType ('r' ), nargs = '+' , help = 'Image' )
13
- parser .add_argument ('--total-colors' , default = 3 , type = int , help = 'Total colors' )
14
- parser .add_argument ('--dominant-range' , default = 10 , type = int , help = 'Dominant range' )
9
+ import rospy
15
10
16
- args = parser .parse_args ()
11
+ from image_recognition_msgs .srv import Recognize
12
+
13
+ from cv_bridge import CvBridge
14
+
15
+ def extract_color_client (img_msg ):
16
+
17
+ rospy .wait_for_service ('extract_color' )
18
+ try :
19
+ extract_color = rospy .ServiceProxy ('extract_color' , Recognize )
20
+ return extract_color (img_msg )
21
+ except rospy .ServiceException as e :
22
+ print ("Service call failed: %s" % e )
23
+
24
+
25
+ if __name__ == "__main__" :
26
+
27
+ # Assign description to the help doc
28
+ parser = argparse .ArgumentParser (description = 'Get dominant colors from image' )
29
+ parser .add_argument ('image' , type = argparse .FileType ('r' ), nargs = '+' , help = 'Image' )
30
+ args = parser .parse_args ()
31
+ bridge = CvBridge ()
32
+
33
+ for image in args .image :
34
+ print (image .name )
35
+ colors = extract_color_client (bridge .cv2_to_imgmsg (cv2 .imread (image .name )))
36
+ print (colors )
17
37
18
- color_extractor = ColorExtractor (args .total_colors , args .dominant_range )
19
- for image in args .image :
20
- print (image .name )
21
- colors = color_extractor .recognize (cv2 .imread (image .name ))
22
- print ('Colors:' , colors )
0 commit comments