Amazon Textract Textract를 사용하여 비동기 텍스트 감지 시작AWSSDK - Amazon Textract

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon Textract Textract를 사용하여 비동기 텍스트 감지 시작AWSSDK

다음 코드 예제에서는 Amazon Textract Textract를 사용하여 문서에서 비동기 텍스트 탐지를 시작하는 방법을 보여줍니다.

Python
SDK for Python(Boto3)

문서의 텍스트를 감지하는 비동기 작업을 시작합니다.

class TextractWrapper: """Encapsulates Textract functions.""" def __init__(self, textract_client, s3_resource, sqs_resource): """ :param textract_client: A Boto3 Textract client. :param s3_resource: A Boto3 Amazon S3 resource. :param sqs_resource: A Boto3 Amazon SQS resource. """ self.textract_client = textract_client self.s3_resource = s3_resource self.sqs_resource = sqs_resource def start_detection_job( self, bucket_name, document_file_name, sns_topic_arn, sns_role_arn): """ Starts an asynchronous job to detect text elements in an image stored in an Amazon S3 bucket. Textract publishes a notification to the specified Amazon SNS topic when the job completes. The image must be in PNG, JPG, or PDF format. :param bucket_name: The name of the Amazon S3 bucket that contains the image. :param document_file_name: The name of the document image stored in Amazon S3. :param sns_topic_arn: The Amazon Resource Name (ARN) of an Amazon SNS topic where the job completion notification is published. :param sns_role_arn: The ARN of an AWS Identity and Access Management (IAM) role that can be assumed by Textract and grants permission to publish to the Amazon SNS topic. :return: The ID of the job. """ try: response = self.textract_client.start_document_text_detection( DocumentLocation={ 'S3Object': {'Bucket': bucket_name, 'Name': document_file_name}}, NotificationChannel={ 'SNSTopicArn': sns_topic_arn, 'RoleArn': sns_role_arn}) job_id = response['JobId'] logger.info( "Started text detection job %s on %s.", job_id, document_file_name) except ClientError: logger.exception("Couldn't detect text in %s.", document_file_name) raise else: return job_id
  • GitHub에서 지침과 추가 코드를 확인해 보세요.

  • API 자세한 내용은 단원을 참조하십시오.StartDocumentTextDetection에서AWSPython용 API 참조 SDK (Boto3).

의 전체 목록은 단원을 참조하십시오.AWSSDK 개발자 가이드 및 코드 예제는 다음을 참조하십시오.와 함께 Amazon Textract 추출을 사용하여AWSSDK. 이 항목에는 시작에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.