From 095084ffc2f32cc948a43864138d0e329049a748 Mon Sep 17 00:00:00 2001 From: Yoshiki Obinata Date: Wed, 1 Mar 2023 17:39:17 +0900 Subject: [PATCH 1/2] [AWS] logdebug when detect face --- jsk_perception/node_scripts/aws_auto_checkin_app.py | 4 ++-- jsk_perception/node_scripts/aws_detect_faces.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jsk_perception/node_scripts/aws_auto_checkin_app.py b/jsk_perception/node_scripts/aws_auto_checkin_app.py index 463743350f..2f9373f823 100755 --- a/jsk_perception/node_scripts/aws_auto_checkin_app.py +++ b/jsk_perception/node_scripts/aws_auto_checkin_app.py @@ -192,8 +192,8 @@ def callback(self, image, roi): face_id = self.dynamodb_table.get_item( Key={'RekognitionId': ret['FaceMatches'][0]['Face']['FaceId']})['Item']['Name'] - rospy.loginfo("FaceId: {}\n Similarity: {}".format(face_id, \ - ret['FaceMatches'][0]['Similarity'])) + rospy.logdebug("FaceId: {}\n Similarity: {}".format(face_id, \ + ret['FaceMatches'][0]['Similarity'])) faces.faces.append(Face(face=Rect(cx - w // 2, cy - h // 2, w, h), label=face_id, confidence=ret['FaceMatches'][0]['Similarity'] / 100.0)) diff --git a/jsk_perception/node_scripts/aws_detect_faces.py b/jsk_perception/node_scripts/aws_detect_faces.py index 7e2412bbc3..35f50448cb 100755 --- a/jsk_perception/node_scripts/aws_detect_faces.py +++ b/jsk_perception/node_scripts/aws_detect_faces.py @@ -157,7 +157,7 @@ def reconfigure_callback(self, config, level): return config def process_attributes(self, text, img, bbox): - rospy.loginfo(" {}".format(text)) + rospy.logdebug(" {}".format(text)) if self.use_window: cv2.putText(img, text, (bbox.x + bbox.height // 2 + 8, bbox.y - bbox.width // 2 + self.offset), cv2.FONT_HERSHEY_PLAIN, @@ -207,7 +207,7 @@ def image_callback(self, image): landmarks_msgs.poses = [] # See https://docs.aws.amazon.com/rekognition/latest/dg/API_DetectFaces.html for detail - rospy.loginfo("Found {} faces".format(len(faces['FaceDetails']))) + rospy.logdebug("Found {} faces".format(len(faces['FaceDetails']))) for face in faces['FaceDetails']: # Bounding box of the face @@ -365,7 +365,7 @@ def image_callback(self, image): self.landmarks_pub.publish(landmarks_msgs) # debug info - rospy.loginfo("processing time {}".format((rospy.Time.now() - start_time).to_sec())) + rospy.logdebug("processing time {}".format((rospy.Time.now() - start_time).to_sec())) if __name__ == '__main__': From 775bc30c58a03e755fe87ac381a2c8d5fddf01f8 Mon Sep 17 00:00:00 2001 From: Yoshiki Obinata Date: Wed, 1 Mar 2023 18:28:31 +0900 Subject: [PATCH 2/2] ignore key error and botocore.errorfactory.InvalidParameterException: An error occurred (InvalidParameterException) when calling the SearchFacesByImage operation: There are no faces in the image. Should be at least 1. (ref: https://stackoverflow.com/questions/41863595/boto3-invalidparameterexception) --- .../node_scripts/aws_auto_checkin_app.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/jsk_perception/node_scripts/aws_auto_checkin_app.py b/jsk_perception/node_scripts/aws_auto_checkin_app.py index 2f9373f823..d282c7e6a6 100755 --- a/jsk_perception/node_scripts/aws_auto_checkin_app.py +++ b/jsk_perception/node_scripts/aws_auto_checkin_app.py @@ -152,8 +152,10 @@ def findface(self, face_image): CollectionId=self.COLLECTION_ID, Image={'Bytes': encoded_face_image.tobytes()}, FaceMatchThreshold=self.FACE_SIMILARITY_THRESHOLD, MaxFaces=self.MAX_FACES) return res + except self.rekognition.exceptions.InvalidParameterException as e: + rospy.logdebug("No faces detected") except Exception as e: - print(e) + rospy.logerr(e) return None @@ -189,14 +191,16 @@ def callback(self, image, roi): ret = self.findface(img[image_roi_slice]) if ret != None: if ret['FaceMatches'] != []: - face_id = self.dynamodb_table.get_item( - Key={'RekognitionId': + try: + face_id = self.dynamodb_table.get_item( + Key={'RekognitionId': ret['FaceMatches'][0]['Face']['FaceId']})['Item']['Name'] - rospy.logdebug("FaceId: {}\n Similarity: {}".format(face_id, \ - ret['FaceMatches'][0]['Similarity'])) - faces.faces.append(Face(face=Rect(cx - w // 2, cy - h // 2, w, h), - label=face_id, - confidence=ret['FaceMatches'][0]['Similarity'] / 100.0)) + rospy.logdebug("FaceId: {}\n Similarity: {}".format(face_id, \ + ret['FaceMatches'][0]['Similarity'])) + faces.faces.append(Face(face=Rect(cx - w // 2, cy - h // 2, w, h), + label=face_id, + confidence=ret['FaceMatches'][0]['Similarity'] / 100.0)) + except KeyError: return if self.use_window: # copy colored face rectangle to img_gray img_gray[image_roi_slice] = img[image_roi_slice]