繁体   English   中英

如何在不使用S3从图像中检测文本的情况下在本地测试来自AWS的Rekognition

[英]How to test Rekognition from AWS locally without using S3 in detecting texts from images

我正在尝试从图像中扫描文本,但是如果不使用S3存储桶,就找不到源代码。 这是我找到的唯一源代码,但它使用了S3。 我正在为此项目使用python。

https://docs.aws.amazon.com/rekognition/latest/dg/text-detecting-text-procedure.html

import boto3

if __name__ == "__main__":

bucket='bucket'
photo='text.png'

client=boto3.client('rekognition')


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

textDetections=response['TextDetections']
print ('Detected text')
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

在这里找到一个我可以在没有S3存储桶的情况下使用Amazon Rekognition吗? 并运行它与我需要的东西不同,因为它仅检测标签。

Rekognition API中的DetectText方法(对于boto为detect_text )可以采用以下参数之一:

  • 对Amazon S3存储桶中图像的引用
  • base64编码的图像字节

因此,如果您不使用S3存储桶,则必须提供其bytes 文档中没有提到第三种方法。 输入结构如下所示:

{
  "Image": { 
    "Bytes": blob,
    "S3Object": { 
      "Bucket": "string",
       "Name": "string",
       "Version": "string"
     }
  }
}

并且,获取非S3图像的字节流; 您可以从以下答案中复制实现:

client = boto3.client('rekognition')

image_path='images/4.jpeg'
image = Image.open(image_path)

stream = io.BytesIO()
image.save(stream,format="JPEG")
image_binary = stream.getvalue()

response = client.detect_text(Image={'Bytes':image_binary})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM