Skip to content

Commit

Permalink
Add service argument and start subscriber after client
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoDCC committed May 4, 2024
1 parent 83510f1 commit 347a39d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions image_recognition_color_extractor/scripts/get_colors_stream
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ from sensor_msgs.msg import Image

from image_recognition_msgs.srv import Recognize

class ExtractColorClient(object):
class ExtractColorClient:
def __init__(self, image_topic, color_service):
self.image_sub = rospy.Subscriber(image_topic, Image, self.color_callback)
self.color_proxy = rospy.ServiceProxy(color_service, Recognize)
self.color_proxy.wait_for_service(timeout=20)

# Subscriber will start immediately
self.image_sub = rospy.Subscriber(image_topic, Image, self.color_callback)

def color_callback(self, msg):
# Simply print out values in our custom message.
colors = self.color_proxy(msg)
Expand All @@ -22,10 +24,11 @@ if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Get dominant colors from image')
parser.add_argument('--topic', default='/image', type=str, help='Topic')
parser.add_argument('--service', default='extract_color', type=str, help='Service')
args = parser.parse_args()

rospy.init_node('color_extractor_stream')

extract_color_client = ExtractColorClient(args.topic, 'extract_color')
extract_color_client = ExtractColorClient(args.topic, args.service)

rospy.spin()

0 comments on commit 347a39d

Please sign in to comment.