use of com.google.api.services.vision.v1.model.ImageSource in project java-docs-samples by GoogleCloudPlatform.
the class DetectLandmark method identifyLandmark.
/**
* Gets up to {@code maxResults} landmarks for an image stored at {@code uri}.
*/
public List<EntityAnnotation> identifyLandmark(String uri, int maxResults) throws IOException {
AnnotateImageRequest request = new AnnotateImageRequest().setImage(new Image().setSource(new ImageSource().setGcsImageUri(uri))).setFeatures(ImmutableList.of(new Feature().setType("LANDMARK_DETECTION").setMaxResults(maxResults)));
Vision.Images.Annotate annotate = vision.images().annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
// Due to a bug: requests to Vision API containing large images fail when GZipped.
annotate.setDisableGZipContent(true);
BatchAnnotateImagesResponse batchResponse = annotate.execute();
assert batchResponse.getResponses().size() == 1;
AnnotateImageResponse response = batchResponse.getResponses().get(0);
if (response.getLandmarkAnnotations() == null) {
throw new IOException(response.getError() != null ? response.getError().getMessage() : "Unknown error getting image annotations");
}
return response.getLandmarkAnnotations();
}
Aggregations