Search in sources :

Example 1 with ImageAnnotatorSettings

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();
}
Also used : AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) ImageAnnotatorClient(com.google.cloud.vision.v1.ImageAnnotatorClient) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) ArrayList(java.util.ArrayList) ImageAnnotatorSettings(com.google.cloud.vision.v1.ImageAnnotatorSettings) ImageSource(com.google.cloud.vision.v1.ImageSource) Image(com.google.cloud.vision.v1.Image) EntityAnnotation(com.google.cloud.vision.v1.EntityAnnotation) Feature(com.google.cloud.vision.v1.Feature) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Aggregations

AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)1 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)1 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)1 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)1 Feature (com.google.cloud.vision.v1.Feature)1 Image (com.google.cloud.vision.v1.Image)1 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)1 ImageAnnotatorSettings (com.google.cloud.vision.v1.ImageAnnotatorSettings)1 ImageSource (com.google.cloud.vision.v1.ImageSource)1 ArrayList (java.util.ArrayList)1