I am a new learner who just start to expose the Python and AWS for academic purposes, currently I am working with the AWS rekognition and I will compare and check through the result with image filename that I enter, the person info that store in database is successfully recognize and return the info and the details, however the else statement is unable to execute and without displaying any error message, it only directly jump to ans = input("Do you want do again? (y/n)") while statement only. Anyone know what is happening or which part trigger this situation occur, please help me, appreciate those help thank you.
Another question is any way to automatically recognize the extension filename (such as png, jpeg and other) instead of I need to enter the full name?
import boto3
import io
from PIL import Image
import datetime
from datetime import timedelta
# ct stores current time
ct = datetime.datetime.now()
rekognition = boto3.client("rekognition", region_name="ap-southeast-1")
dynamodb = boto3.client("dynamodb", region_name="ap-southeast-1")
# upload result
dynamodb1 = boto3.resource("dynamodb", region_name="ap-southeast-1")
dynamoTable = dynamodb1.Table("employee-working-status")
while True:
x = input("Please enter the image name: ")
image = Image.open(x)
# print(image)
stream = io.BytesIO()
image.save(stream, format="JPEG")
image_binary = stream.getvalue()
response = rekognition.search_faces_by_image(
CollectionId="family_collection", Image={"Bytes": image_binary}
)
for match in response["FaceMatches"]:
print("Face id " + match["Face"]["FaceId"])
print("\n")
print("Similarity Percentage is " + str(match["Face"]["Confidence"]))
print("\n")
face = dynamodb.get_item(
TableName="family_collection",
Key={"RekognitionId": {"S": match["Face"]["FaceId"]}},
)
faceId = Key = match["Face"]["FaceId"]
fullName = face["Item"]["FullName"]["S"]
clockIn = str(ct)
clockOut = str(ct + timedelta(hours=8))
if "Item" in face:
print("Welcome to work", face["Item"]["FullName"]["S"], "")
print("\nClocking Time: " + clockIn)
print("\nClocking Out: " + clockOut)
print(
"\n" "The face identified is:",
face["Item"]["FullName"]["S"],
# print(faceId, fullName, clockIn, clockOut),
dynamoTable.put_item(
Item={
"rekognitionId": faceId,
"tsSortKey": clockIn,
"FullName": fullName,
"ClockingInTime": clockIn,
"ClockingOutTime": clockOut,
}
),
),
else:
print("no match found in person lookup")
ans = input("Do you want do again? (y/n)")
# Terminate the script if the input value is 'n'
if ans.lower() == "n":
break