-
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.
(color_extractor) Create a node listener and call service (#228)
* Create a node listener and call service * Edit node name * Make class for service client * Add executable script * Add service argument and start subscriber after client * Add rospy argument filter
- Loading branch information
1 parent
ecc0a87
commit d91bc5a
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
#!/usr/bin/env python | ||
import argparse | ||
|
||
import rospy | ||
|
||
from sensor_msgs.msg import Image | ||
|
||
from image_recognition_msgs.srv import Recognize | ||
|
||
class ExtractColorClient: | ||
def __init__(self, image_topic, color_service): | ||
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) | ||
rospy.loginfo(colors) | ||
|
||
if __name__ == '__main__': | ||
|
||
myargs = rospy.myargv() | ||
parser = argparse.ArgumentParser(description='Get dominant colors from image') | ||
parser.add_argument('--topic', required=False, default='/image', type=str, help='Topic') | ||
parser.add_argument('--service', required=False, default='extract_color', type=str, help='Service') | ||
args = parser.parse_args(myargs[1:]) | ||
|
||
rospy.init_node('color_extractor_stream') | ||
|
||
extract_color_client = ExtractColorClient(args.topic, args.service) | ||
|
||
rospy.spin() |