Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Analisi della documentazione sull'identità con Amazon Textract
Per analizzare i documenti di identità, si utilizza l'operazione API AnalyzeID e si passa un file di documento come input. AnalyzeIDrestituisce una struttura JSON che contiene il testo analizzato. Per ulteriori informazioni, consulta Analisi dei documenti di identità.
Puoi fornire un documento di input come array di byte di immagine (byte di immagine con codifica Base64) o come oggetto Amazon S3. In questa procedura, carichi un file di immagine nel bucket S3 e specifichi il nome del file.
Per analizzare un documento di identità (API)
Se non lo hai già fatto:
Assegna a un utente le
AmazonS3ReadOnlyAccessautorizzazioniAmazonTextractFullAccesse. Per ulteriori informazioni, consulta Fase 1: impostazione di un account AWS e creazione di un utente.Installa e configura gli SDK AWS CLI e gli AWS SDK. Per ulteriori informazioni, consulta Passaggio 2: configura il AWS CLI and AWS SDK.
-
Carica un'immagine che contiene un documento nel tuo bucket S3.
Per le istruzioni, consulta Caricamento di oggetti in Amazon S3 nella Guida per l'utente di Amazon Simple Storage Service.
Utilizzare i seguenti esempi per richiamare l'operazione
AnalyzeID.- AWS CLI
-
L'esempio seguente prende un file di input da un bucket S3 ed esegue l'
AnalyzeIDoperazione su di esso. Nel codice seguente, sostituite il valore diBucketcon il nome del bucket S3 e il valore diNamecon il nome del file nel bucket. Sostituisciloprofile-namecon il nome di un profilo che può assumere il ruolo eregioncon la regione in cui desideri eseguire il codice.aws textract analyze-id \ --document-pages '{"S3Object":{"Bucket":"bucket","Name":"name"}}' \ --profileprofile-name\ --regionregionPuoi anche chiamare l'API con la parte anteriore e posteriore della patente di guida aggiungendo un altro oggetto Amazon S3 all'input.
aws textract analyze-id \ --document-pages '[{"S3Object":{"Bucket":"bucket","Name":"name front"}}, {"S3Object":{"Bucket":"bucket","Name":"name back"}}]' \ --profileprofile-name\ --regionregionSe accedi alla CLI su un dispositivo Windows, utilizza le virgolette doppie anziché le virgolette singole ed evita le virgolette doppie interne con una barra rovesciata (\) per correggere eventuali errori del parser che potresti riscontrare. Per un esempio, consulta quanto segue:
aws textract analyze-id --document-pages "[{\"S3Object\":{\"Bucket\":\"bucket\",\"Name\":\"name\"}}]" --regionregion - Python
-
L'esempio seguente prende un file di input da un bucket S3 ed esegue l'
AnalyzeIDoperazione su di esso, restituendo le coppie chiave-valore rilevate. Nel codice seguente, sostituite il valore dibucket_namecon il nome del bucket S3 e il valore difile_namecon il nome del file nel bucket. Sostituisciloprofile-namecon il nome di un profilo che può assumere il ruolo eregioncon la regione in cui desideri eseguire il codice.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
-
L'esempio seguente prende un file di input da un bucket S3 ed esegue l'
AnalyzeIDoperazione su di esso, restituendo i dati rilevati. Nella funzione main, sostituisci i valori dis3bucketesourceDoccon i nomi del bucket Amazon S3 e dell'immagine del documento utilizzati nel passaggio 2. Sostituisci il valore dicredentialsProvidercon il nome del tuo profilo di sviluppatore./* 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
-
L'esempio seguente prende un file di input da un bucket S3 ed esegue l'
AnalyzeIDoperazione su di esso, restituendo i dati rilevati. Nella funzione main, sostituite i valori dis3bucketesourceDoccon i nomi del bucket S3 e dell'immagine del documento utilizzati nel passaggio 2.Sostituisci
profile-namenella riga che crea ilTextractClientcon il nome del tuo profilo di sviluppatore.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] }
-
Questo ti fornirà l'output JSON per l'
AnalyzeIDoperazione.