use of com.google.cloud.vision.v1.ImageAnnotatorSettings in project java-vision by googleapis.
the class SetEndpoint method setEndpoint.
// Change your endpoint
public static void setEndpoint() throws IOException {
// [START vision_set_endpoint]
ImageAnnotatorSettings settings = ImageAnnotatorSettings.newBuilder().setEndpoint("eu-vision.googleapis.com:443").build();
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
ImageAnnotatorClient client = ImageAnnotatorClient.create(settings);
// [END vision_set_endpoint]
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri("gs://cloud-samples-data/vision/text/screen.jpg").build();
Image image = Image.newBuilder().setSource(imgSource).build();
Feature feature = Feature.newBuilder().setType(Feature.Type.TEXT_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feature).setImage(image).build();
List<AnnotateImageRequest> requests = new ArrayList<>();
requests.add(request);
BatchAnnotateImagesResponse batchResponse = client.batchAnnotateImages(requests);
for (AnnotateImageResponse response : batchResponse.getResponsesList()) {
for (EntityAnnotation annotation : response.getTextAnnotationsList()) {
System.out.format("Text: %s%n", annotation.getDescription());
System.out.println("Position:");
System.out.format("%s%n", annotation.getBoundingPoly());
}
}
client.close();
}
Aggregations