-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DetectFaces and Recognise skills.
- Loading branch information
Showing
3 changed files
with
59 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
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,25 @@ | ||
import rospy | ||
import smach | ||
|
||
from lasr_vision_msgs.srv import DetectFaces as DetectFacesSrv | ||
from sensor_msgs.msg import Image | ||
|
||
|
||
class DetectFaces(smach.State): | ||
|
||
def __init__(self, image_topic: str = "/xtion/rgb/image_raw"): | ||
smach.State.__init__( | ||
self, outcomes=["succeeded", "failed"], output_keys=["detections"] | ||
) | ||
self._image_topic = image_topic | ||
self._detect_faces = rospy.ServiceProxy("/detect_faces", DetectFacesSrv) | ||
|
||
def execute(self, userdata): | ||
img_msg = rospy.wait_for_message(self._image_topic, Image) | ||
try: | ||
result = self._detect_faces(img_msg) | ||
userdata.detections = result | ||
return "succeeded" | ||
except rospy.ServiceException as e: | ||
rospy.logwarn(f"Unable to perform inference. ({str(e)})") | ||
return "failed" |
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,32 @@ | ||
import rospy | ||
import smach | ||
|
||
from lasr_vision_msgs.srv import Recognise as RecogniseSrv | ||
from sensor_msgs.msg import Image | ||
|
||
|
||
class Recognise(smach.State): | ||
|
||
def __init__( | ||
self, | ||
dataset: str, | ||
confidence: float = 0.5, | ||
image_topic: str = "/xtion/rgb/image_raw", | ||
): | ||
smach.State.__init__( | ||
self, outcomes=["succeeded", "failed"], output_keys=["detections"] | ||
) | ||
self._dataset = dataset | ||
self._confidence = confidence | ||
self._image_topic = image_topic | ||
self._recognise = rospy.ServiceProxy("/recognise", RecogniseSrv) | ||
|
||
def execute(self, userdata): | ||
img_msg = rospy.wait_for_message(self._image_topic, Image) | ||
try: | ||
result = self._recognise(img_msg, self._dataset, self._confidence) | ||
userdata.detections = result | ||
return "succeeded" | ||
except rospy.ServiceException as e: | ||
rospy.logwarn(f"Unable to perform inference. ({str(e)})") | ||
return "failed" |