我正在尝试实施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();
答案 0 :(得分:0)
我明白了。而不是使用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());
}
}