我正在使用谷歌视觉API进行图像的文本检测,它以JSON格式给出响应。因此,此响应属于com.google.cloud.vision.v1.EntityAnnotation.From EntityAnnotation对象,我试图使用EntityAnnotation的getScore()获取值。但是,每次返回0时,我都期望某个浮点值而不是0。有人遇到过类似的问题吗? 要了解Google视觉文本检测API,您可以阅读以下https://cloud.google.com/vision/docs/ocr 感谢帮助。谢谢。
try (FileInputStream inputStream = new FileInputStream(filePath);
ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
final ByteString imageBytes = ByteString.readFrom(inputStream);
final Image image = Image.newBuilder().setContent(imageBytes).build();
final Feature feature = Feature.newBuilder().setType(TEXT_DETECTION).build();
final AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feature).setImage(image)
.build();
requests.add(request);
final BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
final List<AnnotateImageResponse> responseList = response.getResponsesList();
result = responseList.get(0).getTextAnnotationsList();
}
final EntityAnnotation annotation = result.get(0);
final Float confidence = annotation.getScore();