Search in sources :

Example 1 with TextDetection

use of software.amazon.awssdk.services.rekognition.model.TextDetection in project aws-doc-sdk-examples by awsdocs.

the class DetectText method detectTextLabels.

// snippet-start:[rekognition.java2.detect_text.main]
public static void detectTextLabels(RekognitionClient rekClient, String sourceImage) {
    try {
        InputStream sourceStream = new FileInputStream(sourceImage);
        SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
        // Create an Image object for the source image
        Image souImage = Image.builder().bytes(sourceBytes).build();
        DetectTextRequest textRequest = DetectTextRequest.builder().image(souImage).build();
        DetectTextResponse textResponse = rekClient.detectText(textRequest);
        List<TextDetection> textCollection = textResponse.textDetections();
        System.out.println("Detected lines and words");
        for (TextDetection text : textCollection) {
            System.out.println("Detected: " + text.detectedText());
            System.out.println("Confidence: " + text.confidence().toString());
            System.out.println("Id : " + text.id());
            System.out.println("Parent Id: " + text.parentId());
            System.out.println("Type: " + text.type());
            System.out.println();
        }
    } catch (RekognitionException | FileNotFoundException e) {
        System.out.println(e.getMessage());
        System.exit(1);
    }
}
Also used : TextDetection(software.amazon.awssdk.services.rekognition.model.TextDetection) SdkBytes(software.amazon.awssdk.core.SdkBytes) DetectTextRequest(software.amazon.awssdk.services.rekognition.model.DetectTextRequest) RekognitionException(software.amazon.awssdk.services.rekognition.model.RekognitionException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DetectTextResponse(software.amazon.awssdk.services.rekognition.model.DetectTextResponse) FileNotFoundException(java.io.FileNotFoundException) Image(software.amazon.awssdk.services.rekognition.model.Image) FileInputStream(java.io.FileInputStream)

Aggregations

FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 DetectTextRequest (software.amazon.awssdk.services.rekognition.model.DetectTextRequest)1 DetectTextResponse (software.amazon.awssdk.services.rekognition.model.DetectTextResponse)1 Image (software.amazon.awssdk.services.rekognition.model.Image)1 RekognitionException (software.amazon.awssdk.services.rekognition.model.RekognitionException)1 TextDetection (software.amazon.awssdk.services.rekognition.model.TextDetection)1