`
import boto3
if __name__ == "__main__":
bucket='random_name'
photo='b4.png'
client=boto3.client('rekognition')
response=client.detect_text(Image={'S3Object':
{'random_name':bucket,'b4.png':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()`
This is the code recognizing images(OCR) yet I do not know where I should paste this code to run. Do I run this in Jupyter notebooks and would I need to install extra things? Do I run it in the Anaconda Prompt? I've tried both. In Jupyter, I get an error: |ParamValidationError: Parameter validation failed: Unknown parameter in Image.S3Object: "random_name", must be one of: Bucket, Name, Version Unknown parameter in Image.S3Object: "b4.png", must be one of: Bucket, Name, Version| and Anaconda prompt has much more errors. I've installed AWS already and curious whether there is more to install. It would be greatly appreciated if anyone helped me.
Code that calls an AWS API (such as
client.detect_text()
) can be run from anywhere on the Internet. You have shown some Python code that can be run on a server, on a laptop, an EC2 instance or as a Lambda function (with a bit of a cleanup).The only additional thing it needs is a set of credentials so that it can connect to your AWS account.
aws configure
command and provide your IAM User credentials.Also, please note that the format of
detect_text()
is:Therefore, your line of code should be:
Also, I wouldn't say that this function is true OCR. Rather, it finds bits of text in a picture, such as words on a sign. It would not be suitable for reading a page full of text, which is done by traditional OCR methods.