Search in sources :

Example 1 with S3Object

use of com.amazonaws.services.textract.model.S3Object in project aws-doc-sdk-examples by awsdocs.

the class DocumentText method main.

public static void main(String[] arg) throws Exception {
    // The S3 bucket and document
    String document = "";
    String bucket = "";
    AmazonS3 s3client = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new EndpointConfiguration("https://s3.amazonaws.com", "us-east-1")).build();
    // Get the document from S3
    com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, document);
    S3ObjectInputStream inputStream = s3object.getObjectContent();
    BufferedImage image = ImageIO.read(inputStream);
    // Call DetectDocumentText
    EndpointConfiguration endpoint = new EndpointConfiguration("https://textract.us-east-1.amazonaws.com", "us-east-1");
    AmazonTextract client = AmazonTextractClientBuilder.standard().withEndpointConfiguration(endpoint).build();
    DetectDocumentTextRequest request = new DetectDocumentTextRequest().withDocument(new Document().withS3Object(new S3Object().withName(document).withBucket(bucket)));
    DetectDocumentTextResult result = client.detectDocumentText(request);
    // Create frame and panel.
    JFrame frame = new JFrame("RotateImage");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    DocumentText panel = new DocumentText(result, image);
    panel.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
    frame.setContentPane(panel);
    frame.pack();
    frame.setVisible(true);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) DetectDocumentTextRequest(com.amazonaws.services.textract.model.DetectDocumentTextRequest) Document(com.amazonaws.services.textract.model.Document) AmazonTextract(com.amazonaws.services.textract.AmazonTextract) BufferedImage(java.awt.image.BufferedImage) DetectDocumentTextResult(com.amazonaws.services.textract.model.DetectDocumentTextResult) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) S3Object(com.amazonaws.services.textract.model.S3Object)

Example 2 with S3Object

use of com.amazonaws.services.textract.model.S3Object in project aws-doc-sdk-examples by awsdocs.

the class AnalyzeDocument method main.

public static void main(String[] arg) throws Exception {
    // The S3 bucket and document
    String document = "";
    String bucket = "";
    AmazonS3 s3client = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new EndpointConfiguration("https://s3.amazonaws.com", "us-east-1")).build();
    // Get the document from S3
    com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, document);
    S3ObjectInputStream inputStream = s3object.getObjectContent();
    BufferedImage image = ImageIO.read(inputStream);
    // Call AnalyzeDocument
    EndpointConfiguration endpoint = new EndpointConfiguration("https://textract.us-east-1.amazonaws.com", "us-east-1");
    AmazonTextract client = AmazonTextractClientBuilder.standard().withEndpointConfiguration(endpoint).build();
    AnalyzeDocumentRequest request = new AnalyzeDocumentRequest().withFeatureTypes("TABLES", "FORMS").withDocument(new Document().withS3Object(new S3Object().withName(document).withBucket(bucket)));
    AnalyzeDocumentResult result = client.analyzeDocument(request);
    // Create frame and panel.
    JFrame frame = new JFrame("RotateImage");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    AnalyzeDocument panel = new AnalyzeDocument(result, image);
    panel.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
    frame.setContentPane(panel);
    frame.pack();
    frame.setVisible(true);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) Document(com.amazonaws.services.textract.model.Document) AmazonTextract(com.amazonaws.services.textract.AmazonTextract) BufferedImage(java.awt.image.BufferedImage) AnalyzeDocumentResult(com.amazonaws.services.textract.model.AnalyzeDocumentResult) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) S3Object(com.amazonaws.services.textract.model.S3Object) AnalyzeDocumentRequest(com.amazonaws.services.textract.model.AnalyzeDocumentRequest)

Aggregations

EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)2 AmazonTextract (com.amazonaws.services.textract.AmazonTextract)2 Document (com.amazonaws.services.textract.model.Document)2 S3Object (com.amazonaws.services.textract.model.S3Object)2 BufferedImage (java.awt.image.BufferedImage)2 AnalyzeDocumentRequest (com.amazonaws.services.textract.model.AnalyzeDocumentRequest)1 AnalyzeDocumentResult (com.amazonaws.services.textract.model.AnalyzeDocumentResult)1 DetectDocumentTextRequest (com.amazonaws.services.textract.model.DetectDocumentTextRequest)1 DetectDocumentTextResult (com.amazonaws.services.textract.model.DetectDocumentTextResult)1