Skip to content

Commit

Permalink
ignore key error and botocore.errorfactory.InvalidParameterException:…
Browse files Browse the repository at this point in the history
… 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)
  • Loading branch information
mqcmd196 committed Mar 1, 2023
1 parent 095084f commit a217b79
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions jsk_perception/node_scripts/aws_auto_checkin_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.InvalidParameterException as e:
rospy.logdebug("No faces detected")
except Exception as e:
print(e)
rospy.logerr(e)

return None

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit a217b79

Please sign in to comment.