Search in sources :

Example 1 with DetectDocumentTextRequest

use of com.amazonaws.services.textract.model.DetectDocumentTextRequest 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)

Aggregations

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