如何在不使用S3检测图像文本的情况下本地测试AWS的识别率

2024-04-26 21:50:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从图像中扫描文本,但如果不使用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

在这里找到一个Can I use Amazon Rekognition without an S3 bucket?并运行它与我需要的不同,因为它只检测标签。在


Tags: textclientidformatifs3bucket源代码
1条回答
网友
1楼 · 发布于 2024-04-26 21:50:55

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

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

因此,如果不使用s3bucket,则必须提供它的字节。在docs中没有提到第三种方法。输入结构如下所示:

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

而且,要获取非S3映像的字节流,可以从this answer复制实现:

^{pr2}$

相关问题 更多 >