0

I am trying to implement Cloud Vision API (TEXT_DETECTION) and I want to get all texts and it's vertices positions from image. Here is an example:

enter image description here

I want to get 4 "objects". One, Two, Three and Four with vertices positions.

Here is the response part of my code:

final TextAnnotation text = batchResponse.getResponses()
                            .get(0).getFullTextAnnotation();

I can then get such information as:

 text.getPages().get(0).getBlocks().get(0).getParagraphs().get(0).getWords().get(0).getSymbols().get(0)

However it seems really complex. How to get these data?

PS. Here is my full code:

Feature desiredFeature = new Feature();

            desiredFeature.setType("TEXT_DETECTION");


                AnnotateImageRequest request = new AnnotateImageRequest();
                request.setImage(inputImage);
                request.setFeatures(Arrays.asList(desiredFeature));


                BatchAnnotateImagesRequest batchRequest =
                        new BatchAnnotateImagesRequest();

                batchRequest.setRequests(Arrays.asList(request));

                BatchAnnotateImagesResponse batchResponse =
                        vision.images().annotate(batchRequest).execute();

                final TextAnnotation text = batchResponse.getResponses()
                        .get(0).getFullTextAnnotation();

1 Answers1

0

I figured it out. Instead of using TextAnnotation i used AnnotateImageResponse

 List<AnnotateImageResponse> responses = batchResponse.getResponses();

                for (AnnotateImageResponse res : responses) {

                    // For full list of available annotations, see http://g.co/cloud/vision/docs
                    for (EntityAnnotation annotation : res.getTextAnnotations()) {
                        out.printf("Text: %s\n", annotation.getDescription());
                        out.printf("Position : %s\n", annotation.getBoundingPoly());
                    }
                }