Last active
December 17, 2017 02:32
-
-
Save srli/d6cba55d9cc172a4c242544c017d5b04 to your computer and use it in GitHub Desktop.
Simple implmentation of a ros node in python
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
#!/usr/bin/python | |
import rospy | |
from std_msgs.msg import String | |
from sensor_msgs.msg import Image | |
import cv2 | |
import numpy as np | |
class FaceFinder: | |
def __init__(self): | |
rospy.init_node("face_finder_node", anonymous=True) | |
self.bridge = CvBridge() | |
self.image_sub = rospy.Subscriber("IMAGE_TOPIC_HERE", Image, self.image_callback) | |
self.frame = None # Initialize image frame to None | |
def image_callback(self, data): | |
try: | |
self.frame = self.bridge.imgmsg_to_cv2(data, "bgr8") | |
except CvBridgeError as e: | |
print(e) | |
def find_smile(self): | |
if self.frame == None: | |
return | |
#### Face/smile finding code here | |
def run(self): | |
# Set detector rate to 10hz | |
r = rospy.Rate(10) | |
while not rospy.is_shutdown(): | |
self.find_smile() # Run smile detector code once | |
r.sleep() # Sleep until time is up for next cycle to hit 10hz | |
if __name__ == "__main__": | |
face_finder = FaceFinder() | |
face_finder.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment