기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
Amazon Textract를 사용한 자격 증명 설명서 분석
자격 증명 문서를 분석하려면 AnalyzeID API 작업을 사용하고 문서 파일을 입력으로 전달합니다.는 분석된 텍스트가 포함된 JSON 구조를 AnalyzeID 반환합니다. 자세한 내용은 자격 증명 문서 분석 단원을 참조하십시오.
입력 문서를 이미지 바이트 배열(base64 인코딩 이미지 바이트) 또는 Amazon S3 객체로 제공할 수 있습니다. 이 절차에서는 이미지 파일을 S3 버킷에 업로드하고 파일 이름을 지정합니다.
자격 증명 문서를 분석하려면(API)
아직 설정하지 않았다면 다음과 같이 하세요.
사용자에게
AmazonTextractFullAccess및AmazonS3ReadOnlyAccess권한을 부여합니다. 자세한 내용은 1단계: AWS 계정 설정 및 사용자 만들기 단원을 참조하십시오.AWS CLI 및 AWS SDKs를 설치하고 구성합니다. 자세한 내용은 2단계: AWS CLI 및 AWS SDKs 설정 단원을 참조하십시오.
-
문서가 포함된 이미지를 S3 버킷에 업로드합니다.
이에 관한 지침은 Amazon Simple Storage Service 사용 설명서에서 Amazon S3에 객체 업로드를 참조하세요.
다음 예제를 사용하여
AnalyzeID작업을 호출합니다.- AWS CLI
-
다음 예제에서는 S3 버킷에서 입력 파일을 가져와서 해당 버킷에서
AnalyzeID작업을 실행합니다. 다음 코드에서의 값을 S3 버킷의Bucket이름으로 바꾸고의 값을 버킷의 파일Name이름으로 바꿉니다.profile-name를 역할을 수임할 수 있는 프로파일의 이름으로 바꾸고를 코드를 실행하려는 리전region으로 바꿉니다.aws textract analyze-id \ --document-pages '{"S3Object":{"Bucket":"bucket","Name":"name"}}' \ --profileprofile-name\ --regionregion입력에 다른 Amazon S3 객체를 추가하여 운전면허증의 앞뒤로 API를 호출할 수도 있습니다.
aws textract analyze-id \ --document-pages '[{"S3Object":{"Bucket":"bucket","Name":"name front"}}, {"S3Object":{"Bucket":"bucket","Name":"name back"}}]' \ --profileprofile-name\ --regionregionWindows 디바이스에서 CLI에 액세스하는 경우 작은따옴표 대신 큰따옴표를 사용하고 내부 큰따옴표를 백슬래시(\)로 이스케이프하여 발생할 수 있는 구문 분석기 오류를 해결합니다. 예를 들어 다음을 참조하세요.
aws textract analyze-id --document-pages "[{\"S3Object\":{\"Bucket\":\"bucket\",\"Name\":\"name\"}}]" --regionregion - Python
-
다음 예제에서는 S3 버킷에서 입력 파일을 가져와서 해당 버킷에서
AnalyzeID작업을 실행하여 감지된 키-값 페어를 반환합니다. 다음 코드에서의 값을 S3 버킷의bucket_name이름으로 바꾸고의 값을 버킷의 파일file_name이름으로 바꿉니다.profile-name를 역할을 수임할 수 있는 프로파일의 이름으로 바꾸고를 코드를 실행하려는 리전region으로 바꿉니다.import boto3 def analyze_id(client, bucket_name, file_name): # Analyze document # process using S3 object response = client.analyze_id( DocumentPages=[{'S3Object': {'Bucket': bucket_name, 'Name': file_name}}]) for doc_fields in response['IdentityDocuments']: for id_field in doc_fields['IdentityDocumentFields']: for key, val in id_field.items(): if "Type" in str(key): print("Type: " + str(val['Text'])) for key, val in id_field.items(): if "ValueDetection" in str(key): print("Value Detection: " + str(val['Text'])) print() def main(): session = boto3.Session(profile_name='profile-name') client = session.client('textract', region_name='region') bucket_name = "bucket" file_name = "file" analyze_id(client, bucket_name, file_name) if __name__ == "__main__": main() - Java
-
다음 예제에서는 S3 버킷에서 입력 파일을 가져와서 해당 버킷에서
AnalyzeID작업을 실행하여 감지된 데이터를 반환합니다. 함수 메인에서s3bucket및의 값을 2단계에서 사용한 Amazon S3 버킷 및 문서 이미지의sourceDoc이름으로 바꿉니다.credentialsProvider의 값을 개발자 프로필 이름으로 바꿉니다./* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ package com.amazonaws.samples; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.regions.Regions; import com.amazonaws.services.textract.AmazonTextractClient; import com.amazonaws.services.textract.AmazonTextractClientBuilder; import com.amazonaws.services.textract.model.*; import java.util.ArrayList; import java.util.List; public class AppTest1 { public static void main(String[] args) { final String USAGE = "\n" + "Usage:\n" + " <s3bucket><sourceDoc> \n\n" + "Where:\n" + " s3bucket - the Amazon S3 bucket where the document is located. \n" + " sourceDoc - the name of the document. \n"; if (args.length != 1) { System.out.println(USAGE); System.exit(1); } // set provider credentials AWSCredentialsProvider credentialsProvider = new ProfileCredentialsProvider("default"); String s3bucket = "bucket-name"; //args[0]; String sourceDoc = "sourcedoc-name"; //args[1]; AmazonTextractClient textractClient = (AmazonTextractClient) AmazonTextractClientBuilder.standard().withCredentials(credentialsProvider) .withRegion(Regions.US_EAST_1) .build(); getDocDetails(textractClient, s3bucket, sourceDoc); } public static void getDocDetails(AmazonTextractClient textractClient, String s3bucket, String sourceDoc ) { try { S3Object s3 = new S3Object(); s3.setBucket(s3bucket); s3.setName(sourceDoc); com.amazonaws.services.textract.model.Document myDoc = new com.amazonaws.services.textract.model.Document(); myDoc.setS3Object(s3); List<Document> list1 = new ArrayList(); list1.add(myDoc); AnalyzeIDRequest idRequest = new AnalyzeIDRequest(); idRequest.setDocumentPages(list1); AnalyzeIDResult result = textractClient.analyzeID(idRequest); List<IdentityDocument> docs = result.getIdentityDocuments(); for (IdentityDocument doc: docs) { List<IdentityDocumentField>idFields = doc.getIdentityDocumentFields(); for (IdentityDocumentField field: idFields) { System.out.println("Field type is "+ field.getType().getText()); System.out.println("Field value is "+ field.getValueDetection().getText()); } } } catch (Exception e) { e.printStackTrace(); } } } - Java V2
-
다음 예제에서는 S3 버킷에서 입력 파일을 가져와서 해당 버킷에서
AnalyzeID작업을 실행하여 감지된 데이터를 반환합니다. 함수 메인에서s3bucket및의 값을 2단계에서 사용한 S3 버킷 및 문서 이미지의sourceDoc이름으로 바꿉니다.profile-name를 생성하는 줄의TextractClient를 개발자 프로필의 이름으로 바꿉니다.import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.core.SdkBytes; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.textract.TextractClient; import software.amazon.awssdk.services.textract.model.*; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; // snippet-end:[textract.java2._analyze_doc.import] import java.util.Optional; import org.json.JSONObject; /** * Before running this Java V2 code example, set up your development environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DetectCelebrityVideo { public static void main(String[] args) { final String usage = "\n" + "Usage:\n" + " <bucketName> <docName> \n\n" + "Where:\n" + " bucketName - The name of the Amazon S3 bucket that contains the document. \n\n" + " docName - The document name (must be an image, i.e., book.png). \n"; if (args.length != 2) { System.out.println(usage); System.exit(1); } String bucketName = args[0]; String docName = args[1]; Region region = Region.US_WEST_2; TextractClient textractClient = TextractClient.builder() .region(region) .credentialsProvider(ProfileCredentialsProvider.create("default")) .build(); analyzeID(textractClient, bucketName, docName); textractClient.close(); } // snippet-start:[textract.java2._analyze_doc.main] public static void analyzeID(TextractClient textractClient, String bucketName, String docName) { try { S3Object s3Object = S3Object.builder() .bucket(bucketName) .name(docName) .build(); // Create a Document object and reference the s3Object instance Document myDoc = Document.builder() .s3Object(s3Object) .build(); AnalyzeIdRequest analyzeIdRequest = AnalyzeIdRequest.builder() .documentPages(myDoc).build(); AnalyzeIdResponse analyzeId = textractClient.analyzeID(analyzeIdRequest); // System.out.println(analyzeExpense.toString()); List<IdentityDocument> Docs = analyzeId.identityDocuments(); for (IdentityDocument doc: Docs) { System.out.println(doc); } } catch (TextractException e) { System.err.println(e.getMessage()); System.exit(1); } } // snippet-end:[textract.java2._analyze_doc.main] }
-
그러면
AnalyzeID작업에 대한 JSON 출력이 제공됩니다.