AWS Textract支持扫描驾照和护照。需要注意的是,扫描的结果将以文本形式返回,不包含图像或照片。
以下是使用AWS CLI在Python中调用AWS Textract扫描护照的示例代码:
import boto3
import io
from PIL import Image
# Replace bucket, document, and region with your values
bucket = 'my-bucket'
document = 'passport.jpg'
region = 'us-east-1'
# Get the document from S3
s3 = boto3.resource('s3', region_name=region)
object = s3.Object(bucket, document)
image = object.get()['Body'].read()
# Analyze the document
client = boto3.client('textract', region_name=region)
response = client.analyze_document(Document={'Bytes': image}, FeatureTypes=['FORMS'])
# Print the fields
for field in response['Blocks']:
if field['BlockType'] == 'KEY_VALUE_SET':
if 'KEY' in field.keys() and field['KEY']['Text'] == 'Place of Issue':
print('Place of Issue:', field['VALUE']['Text'])
以上代码将解析包含护照扫描的S3对象,并从扫描结果中提取包含“Place of Issue”值的字段。