是的,AWS Rekognition可以检测图像中的表格,并且可以将其导入到DynamoDB表中。以下是一个使用AWS SDK for Python(Boto3)的示例代码:
import boto3
def detect_table(image_path):
# 创建Rekognition客户端
rekognition_client = boto3.client('rekognition')
with open(image_path, 'rb') as image_file:
# 读取图像文件的字节流
image_bytes = image_file.read()
# 调用DetectText API检测图像中的文本和表格
response = rekognition_client.detect_text(Image={'Bytes': image_bytes})
# 遍历检测结果
for text_detection in response['TextDetections']:
# 如果检测到表格
if text_detection['Type'] == 'TABLE':
# 获取表格中的文本和位置信息
table_text = text_detection['DetectedText']
table_box = text_detection['Geometry']['BoundingBox']
print('Table detected:', table_text)
# 将表格信息导入到DynamoDB表
dynamodb_client = boto3.client('dynamodb')
dynamodb_client.put_item(
TableName='your-dynamodb-table-name',
Item={
'table_text': {'S': table_text},
'table_box': {'S': str(table_box)}
}
)
# 调用函数进行检测和导入
detect_table('your-image.jpg')
请确保你已经安装了AWS SDK for Python(Boto3)并且配置了正确的访问密钥和区域。在代码中,你需要将your-dynamodb-table-name
替换为真实的DynamoDB表名,并且将your-image.jpg
替换为你要检测的图像路径。