【问题标题】:Cloud Vision API Android- text annotationCloud Vision API Android-文本注释
【发布时间】:2017-08-03 16:21:22
【问题描述】:

我正在尝试实现 Cloud Vision API (TEXT_DETECTION),我想从图像中获取所有文本及其顶点位置。这是一个例子:

我想获得 4 个“对象”。一、二、三和四的顶点位置。

这是我的代码的响应部分:

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

然后我可以得到这样的信息:

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

然而它看起来真的很复杂。如何获取这些数据?

PS。这是我的完整代码:

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();

【问题讨论】:

    标签: android google-cloud-vision


    【解决方案1】:

    我想通了。我没有使用TextAnnotation,而是使用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());
                        }
                    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-07
      • 2019-02-05
      • 2019-06-13
      • 2017-10-20
      • 2019-04-08
      • 2017-07-07
      • 1970-01-01
      • 2020-03-20
      相关资源
      最近更新 更多