@Generated(value="by GAPIC") @BetaApi public class ImageAnnotatorClient extends Object implements AutoCloseable
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
}
Note: close() needs to be called on the imageAnnotatorClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of ImageAnnotatorSettings to create(). For example:
ImageAnnotatorSettings imageAnnotatorSettings =
ImageAnnotatorSettings.defaultBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ImageAnnotatorClient imageAnnotatorClient =
ImageAnnotatorClient.create(imageAnnotatorSettings);
Modifier | Constructor and Description |
---|---|
protected |
ImageAnnotatorClient(ImageAnnotatorSettings settings)
Constructs an instance of ImageAnnotatorClient, using the given settings.
|
Modifier and Type | Method and Description |
---|---|
com.google.cloud.vision.v1.BatchAnnotateImagesResponse |
batchAnnotateImages(List<com.google.cloud.vision.v1.AnnotateImageRequest> requests)
Run image detection and annotation for a batch of images.
|
com.google.api.gax.grpc.UnaryCallable<com.google.cloud.vision.v1.BatchAnnotateImagesRequest,com.google.cloud.vision.v1.BatchAnnotateImagesResponse> |
batchAnnotateImagesCallable()
Run image detection and annotation for a batch of images.
|
void |
close()
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
cancelled.
|
static ImageAnnotatorClient |
create()
Constructs an instance of ImageAnnotatorClient with default settings.
|
static ImageAnnotatorClient |
create(ImageAnnotatorSettings settings)
Constructs an instance of ImageAnnotatorClient, using the given settings.
|
ImageAnnotatorSettings |
getSettings() |
protected ImageAnnotatorClient(ImageAnnotatorSettings settings) throws IOException
IOException
public static final ImageAnnotatorClient create() throws IOException
IOException
public static final ImageAnnotatorClient create(ImageAnnotatorSettings settings) throws IOException
IOException
public final ImageAnnotatorSettings getSettings()
public final com.google.cloud.vision.v1.BatchAnnotateImagesResponse batchAnnotateImages(List<com.google.cloud.vision.v1.AnnotateImageRequest> requests)
Sample code:
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();
BatchAnnotateImagesResponse response = imageAnnotatorClient.batchAnnotateImages(requests);
}
requests
- Individual image annotation requests for this batch.com.google.api.gax.grpc.ApiException
- if the remote call failspublic final com.google.api.gax.grpc.UnaryCallable<com.google.cloud.vision.v1.BatchAnnotateImagesRequest,com.google.cloud.vision.v1.BatchAnnotateImagesResponse> batchAnnotateImagesCallable()
Sample code:
try (ImageAnnotatorClient imageAnnotatorClient = ImageAnnotatorClient.create()) {
List<AnnotateImageRequest> requests = new ArrayList<>();
BatchAnnotateImagesRequest request = BatchAnnotateImagesRequest.newBuilder()
.addAllRequests(requests)
.build();
ApiFuture<BatchAnnotateImagesResponse> future = imageAnnotatorClient.batchAnnotateImagesCallable().futureCall(request);
// Do something
BatchAnnotateImagesResponse response = future.get();
}
public final void close() throws Exception
close
in interface AutoCloseable
Exception
Copyright © 2017 Google. All rights reserved.