Hi, all. I am very new to Pythonista and somewhat new to Python. So, apologies if this is a basic question. But, Googling and searching this forum has not helped.
I'm trying to take a photo on my iPhone via Pythonista and pass it to the AWS Rekognition API for image analysis. (I'm using the AWS Python SDK.) Taking the photo works fine. But, when I try to pass the photo to the AWS Rekognition API, I get error messages saying that I am passing an image when str, bytes, or an os.PathLike object are required.
I have tried searching for Python code to convert the image file to bytes, but I am never successful. I still get image object errors. And, attempts to covert an image to a bytearray generated error messages that an image object isn't iterable.
Can anyone give me pointers on how to convert a photo taken by Pythonista to bytes? Or, is there a better solution here that I'm not considering?
Here are four different code snippets I have tried when submitting to AWS:
with open(img, 'rb') as image:
response = client.detect_faces(
Image={
'Bytes': image.read(),
},
Attributes=[
'ALL',
]
)
with open(img, 'rb') as image:
response = client.detect_faces(
Image={
'Bytes': image,
},
Attributes=[
'ALL',
]
)
response = client.detect_faces(
Image={
'Bytes': image.read(),
},
Attributes=[
'ALL',
]
)
response = client.detect_faces(
Image={
'Bytes': image,
},
Attributes=[
'ALL',
]
)
My attempts to convert images to bytes have been so fruitless that I don't really have useful code to share.
Thanks for any help!
Marc :-)