我在哪里运行此AWS识别代码,是否还需要安装其他产品?我会得到什么结果? [英] Where do I run this AWS rekognition code and do I need to install anything else? What result will I get?

查看:94
本文介绍了我在哪里运行此AWS识别代码,是否还需要安装其他产品?我会得到什么结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

`
导入boto3

`
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()`

这是识别图像(OCR)的代码,但我不知道应将此代码粘贴到哪里运行.我是否可以在Jupyter笔记本电脑上运行此软件,是否需要安装其他东西?我可以在Anaconda Prompt中运行它吗?我都尝试过.在Jupyter中,我得到一个错误:| ParamValidationError:参数验证失败:Image.S3Object中的未知参数:"random_name",必须为以下之一:Bucket,Name,Version Image.S3Object中的未知参数:"b4.png",必须可以是以下之一:桶,名称,版本|而Anaconda提示有更多错误.我已经安装了AWS,并且好奇是否还有更多的要安装.如果有人帮助我,将不胜感激.

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.

推荐答案

调用AWS API的代码(例如client.detect_text())可以在Internet上的任何地方运行.您已经展示了一些可以在服务器,便携式计算机,EC2实例上或作为Lambda函数(需要一些清理)运行的Python代码.

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).

它唯一需要的另一件事是一组凭据,以便它可以连接到您的 AWS帐户.

The only additional thing it needs is a set of credentials so that it can connect to your AWS account.

  • 如果您在Amazon EC2实例上运行代码或作为lambda函数运行,只需为实例/函数分配适当的IAM角色,代码就会自动接收凭据.
  • 如果您是在自己的计算机上运行代码,请首先运行aws configure命令并提供您的IAM用户凭据.
  • If you are running the code on an Amazon EC2 instance or as a lambda function, simply assign the instance/function an appropriate IAM Role and the code will automatically receive credentials.
  • If you are running the code on your own computer, first run the aws configure command and provide your IAM User credentials.

另外,请注意detect_text()的格式为:

Also, please note that the format of detect_text() is:

response = client.detect_text(
    Image={
        'Bytes': b'bytes',
        'S3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    }
)

因此,您的代码行应为:

Therefore, your line of code should be:

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

此外,我不会说此功能是真正的OCR.而是在图片中找到文字的一部分,例如标牌上的文字.传统的OCR方法无法读取整页的文字.

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.

这篇关于我在哪里运行此AWS识别代码,是否还需要安装其他产品?我会得到什么结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆