-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a node listener and call service
- Loading branch information
1 parent
ee8607b
commit 0f770ff
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
image_recognition_color_extractor/scripts/get_colors_stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
|
||
import rospy | ||
|
||
from sensor_msgs.msg import Image | ||
|
||
from image_recognition_msgs.srv import Recognize | ||
|
||
def extract_color_client(img_msg): | ||
|
||
rospy.wait_for_service('extract_color') | ||
try: | ||
extract_color = rospy.ServiceProxy('extract_color', Recognize) | ||
return extract_color(img_msg) | ||
except rospy.ServiceException as e: | ||
print("Service call failed: %s"%e) | ||
|
||
# Create a callback function for the subscriber. | ||
def callback(msg): | ||
|
||
# Simply print out values in our custom message. | ||
colors = extract_color_client(msg) | ||
rospy.loginfo(colors) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
rospy.init_node('pose_estimation_image_subscriber') | ||
|
||
parser = argparse.ArgumentParser(description='Get dominant colors from image') | ||
parser.add_argument('--topic', default='/image', type=str, help='Topic') | ||
args = parser.parse_args() | ||
sub = rospy.Subscriber(args.topic, Image, callback) | ||
rospy.loginfo('Node has been started') | ||
|
||
rospy.spin() |