AWS Textract支持阿拉伯文本的OCR识别。在请求中设置相应的语言代码即可。
以下是Python代码示例:
import boto3
client = boto3.client('textract')
response = client.detect_document_text(
Document={
'S3Object': {
'Bucket': 'mybucket',
'Name': 'myimage.png'
}
},
# 设置语言代码为ar
LanguageCode='ar'
)
lines = []
for item in response["Blocks"]:
if item["BlockType"] == "LINE":
lines.append(item["Text"])
text = "\n".join(lines)
print(text)
注意:如果图像中包含多种语言的文本,请在detect_document_text请求中进行适当的设置,以确保正确识别和提取所有文本。