0
votes

I am attempting to run multiple images through the AWS system using python code, just a basic for loop. When I run the code I am getting an error. I am able to run one image but once I attempt to run multiple images I again get an error code.

import boto3

if __name__ == "__main__":

bucket='fastlane'
photo=','.join(('test.png',
'test2.png',
'test3.png',
'test4.png',
'test5.png',
'test6.png',
'test7.png',
'test8.png',
'test9.png',
'test10.png',
'test11.png',
'test12.png',
'test13.png',
'test14.png',
'test15.png',
'test16.png',
'test17.png',
'test18.png'))




client=boto3.client('rekognition')


response=client.detect_text(Image={'S3Object': 
{'Bucket':bucket,'Name':photo}})


textDetections=response['TextDetections']
print (response)
print ('Matching faces')
for text in textDetections:
        print ('Detected text:' + text['DetectedText'])
        print ('Confidence: ' + "{:.2f}".format(text['Confidence']) + "%")
        print ('Id: {}'.format(text['Id']))
        if 'ParentId' in text:
            print ('Parent Id: {}'.format(text['ParentId']))
        print ('Type:' + text['Type'])
        print

Error code: Traceback (most recent call last): File "main.py", line 37, in response=client.detect_text(Image={'S3Object':{'Bucket':bucket,'Name':photo}}) File "/home/Zeus/farcry/AWS/env/lib/python3.5/site-packages/botocore/client.py", line 320, in _api_call return self._make_api_call(operation_name, kwargs) File "/home/Zeus/farcry/AWS/env/lib/python3.5/site-packages/botocore/client.py", line 624, in _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.InvalidS3ObjectException: An error occurred (InvalidS3ObjectException) when calling the DetectText operation: Unable to get object metadata from S3. Check object key, region and/or access permissions.

1

1 Answers

0
votes

You join all the names into one big string and pass this as the name of the object which won't work unless your s3 object is called test1.png,test2.png, etc.

From the docs:

Name (string) -- S3 object key name

You will have to call detect_text for each photo.

What you can do is the following:

import boto3

if __name__ == "__main__":

    bucket='fastlane'
    client=boto3.client('rekognition')
    photos= ['test.png',
    'test2.png',
    'test3.png',
    'test4.png',
    'test5.png',
    'test6.png',
    'test7.png',
    'test8.png',
    'test9.png',
    'test10.png',
    'test11.png',
    'test12.png',
    'test13.png',
    'test14.png',
    'test15.png',
    'test16.png',
    'test17.png',
    'test18.png']

    for photo in photos:
        response=client.detect_text(Image={'S3Object':
        {'Bucket':bucket,'Name':photo}})

        textDetections=response['TextDetections']
        print (response)
        print ('Matching faces')
        for text in textDetections:
                print ('Detected text:' + text['DetectedText'])
                print ('Confidence: ' + "{:.2f}".format(text['Confidence']) + "%")
                print ('Id: {}'.format(text['Id']))
                if 'ParentId' in text:
                    print ('Parent Id: {}'.format(text['ParentId']))
                print ('Type:' + text['Type'])