Created
January 11, 2020 16:28
-
-
Save nkalra0123/d1ccbf5151dcb0e4813402ac663dd33c to your computer and use it in GitHub Desktop.
Perform LABEL_DETECTION on the uploaded image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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