Skip to content

Instantly share code, notes, and snippets.

@nkalra0123
Created January 11, 2020 16:28
Show Gist options
  • Save nkalra0123/d1ccbf5151dcb0e4813402ac663dd33c to your computer and use it in GitHub Desktop.
Save nkalra0123/d1ccbf5151dcb0e4813402ac663dd33c to your computer and use it in GitHub Desktop.
Perform LABEL_DETECTION on the uploaded image
private AnnotateImageResponse analyzeImage(String uri) {
// After the image was written to GCS, analyze it with the GCS URI.
// Note: It's also possible to analyze an image embedded in the
// request as a Base64 encoded payload.
List<AnnotateImageRequest> requests = new ArrayList<>();
ImageSource imgSrc = ImageSource.newBuilder()
.setGcsImageUri(uri).build();
Image img = Image.newBuilder().setSource(imgSrc).build();
Feature feature = Feature.newBuilder()
.setType(Feature.Type.LABEL_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest
.newBuilder()
.addFeatures(feature).setImage(img)
.build();
requests.add(request);
BatchAnnotateImagesResponse responses =
annotatorClient.batchAnnotateImages(requests);
// We send in one image, expecting just one response in batch
AnnotateImageResponse response = responses.getResponses(0);
System.out.println(response);
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment