2017-08-03 3 views
0

Ich versuche Cloud Vision API (TEXT_DETECTION) zu implementieren und ich möchte alle Texte und ihre Scheitelpunkte aus dem Bild bekommen. Hier ein Beispiel:Cloud Vision API Android- Text Annotation

enter image description here

Ich möchte 4 "Objekte" erhalten. Eins, Zwei, Drei und Vier mit Eckenpositionen. Hier

ist die Antwort ein Teil meiner Code:

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

dann kann ich diese Informationen erhalten, wie:

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

aber es ist wirklich komplex erscheint. Wie bekomme ich diese Daten?

PS. Hier ist mein voller 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(); 

Antwort

0

Ich fand es heraus. Anstatt TextAnnotation zu verwenden, benutzte ich 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()); 
        } 
       } 
Verwandte Themen