From 9f0dd2c1ae8d8d43288142ca0b20ed505eca0e86 Mon Sep 17 00:00:00 2001 From: DPE bot Date: Mon, 6 Nov 2017 09:50:34 -0800 Subject: [PATCH 1/2] Auto-update dependencies. --- appengine-java8/gaeinfo/pom.xml | 2 +- appengine-java8/metadata/pom.xml | 2 +- appengine/sockets/pom.xml | 2 +- compute/signed-metadata/pom.xml | 2 +- flexible/gaeinfo/pom.xml | 2 +- vision/face-detection/pom.xml | 2 +- vision/label/pom.xml | 2 +- vision/landmark-detection/pom.xml | 2 +- vision/text/pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/appengine-java8/gaeinfo/pom.xml b/appengine-java8/gaeinfo/pom.xml index 3770b34ccaa..46e288b9894 100644 --- a/appengine-java8/gaeinfo/pom.xml +++ b/appengine-java8/gaeinfo/pom.xml @@ -65,7 +65,7 @@ Copyright 2017 Google Inc. org.thymeleaf thymeleaf - 3.0.8.RELEASE + 3.0.9.RELEASE diff --git a/appengine-java8/metadata/pom.xml b/appengine-java8/metadata/pom.xml index 8366ec7f281..28482ee3269 100644 --- a/appengine-java8/metadata/pom.xml +++ b/appengine-java8/metadata/pom.xml @@ -60,7 +60,7 @@ Copyright 2017 Google Inc. org.thymeleaf thymeleaf - 3.0.8.RELEASE + 3.0.9.RELEASE diff --git a/appengine/sockets/pom.xml b/appengine/sockets/pom.xml index ada36c8e6ee..8af84b28adc 100755 --- a/appengine/sockets/pom.xml +++ b/appengine/sockets/pom.xml @@ -59,7 +59,7 @@ org.jsoup jsoup - 1.10.3 + 1.11.1 diff --git a/compute/signed-metadata/pom.xml b/compute/signed-metadata/pom.xml index 74b85b68f31..c6a892f6a5c 100644 --- a/compute/signed-metadata/pom.xml +++ b/compute/signed-metadata/pom.xml @@ -30,7 +30,7 @@ com.auth0 java-jwt - 3.2.0 + 3.3.0 com.google.code.gson diff --git a/flexible/gaeinfo/pom.xml b/flexible/gaeinfo/pom.xml index 658ab343b0d..25882b5c2a8 100644 --- a/flexible/gaeinfo/pom.xml +++ b/flexible/gaeinfo/pom.xml @@ -65,7 +65,7 @@ Copyright 2017 Google Inc. org.thymeleaf thymeleaf - 3.0.8.RELEASE + 3.0.9.RELEASE diff --git a/vision/face-detection/pom.xml b/vision/face-detection/pom.xml index db0a58ae289..6e2fb706b0a 100644 --- a/vision/face-detection/pom.xml +++ b/vision/face-detection/pom.xml @@ -39,7 +39,7 @@ com.google.apis google-api-services-vision - v1-rev364-1.23.0 + v1-rev365-1.23.0 com.google.api-client diff --git a/vision/label/pom.xml b/vision/label/pom.xml index 3db05a3749b..0210ffd752d 100644 --- a/vision/label/pom.xml +++ b/vision/label/pom.xml @@ -38,7 +38,7 @@ com.google.apis google-api-services-vision - v1-rev364-1.23.0 + v1-rev365-1.23.0 com.google.api-client diff --git a/vision/landmark-detection/pom.xml b/vision/landmark-detection/pom.xml index 9f2fba85f9f..d6e766227d4 100644 --- a/vision/landmark-detection/pom.xml +++ b/vision/landmark-detection/pom.xml @@ -38,7 +38,7 @@ com.google.apis google-api-services-vision - v1-rev364-1.23.0 + v1-rev365-1.23.0 com.google.api-client diff --git a/vision/text/pom.xml b/vision/text/pom.xml index d91324e0838..16cda42973e 100644 --- a/vision/text/pom.xml +++ b/vision/text/pom.xml @@ -38,7 +38,7 @@ com.google.apis google-api-services-vision - v1-rev364-1.23.0 + v1-rev365-1.23.0 com.google.api-client From d5cc4b0fcdf77424ef01c02ce9db4d63f667a67c Mon Sep 17 00:00:00 2001 From: Kurtis Van Gent Date: Mon, 6 Nov 2017 10:29:50 -0800 Subject: [PATCH 2/2] Updated Cloud Vision API Client Library references. --- README.md | 3 ++ .../samples/facedetect/FaceDetectApp.java | 44 +++++++++---------- .../samples/facedetect/FaceDetectAppIT.java | 4 +- .../samples/facedetect/FaceDetectAppTest.java | 30 ++++++------- .../cloud/vision/samples/label/LabelApp.java | 34 +++++++------- .../vision/samples/label/LabelAppIT.java | 6 +-- .../vision/samples/label/LabelAppTest.java | 12 ++--- .../landmarkdetection/DetectLandmark.java | 38 ++++++++-------- .../landmarkdetection/DetectLandmarkIT.java | 4 +- .../cloud/vision/samples/text/ImageText.java | 20 ++++----- .../cloud/vision/samples/text/TextApp.java | 38 ++++++++-------- 11 files changed, 118 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index f0920bdd291..f3264bb9e7c 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ [![ghit.me](https://ghit.me/badge.svg?repo=GoogleCloudPlatform/java-docs-samples)](https://ghit.me/repo/GoogleCloudPlatform/java-docs-samples) [![Coverage Status](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples/branch/master/graph/badge.svg)](https://codecov.io/gh/GoogleCloudPlatform/java-docs-samples) + +While this library is still supported, we suggest trying the newer [Cloud Client Library](https://developers.google.com/api-client-library/java/apis/vision/v1) for Google Cloud Vision, especially for new projects. For more information, please see the notice on the [API Client Library Page](https://developers.google.com/api-client-library/java/apis/vision/v1). + This is a repository that contains java code snippets on [Cloud Platform Documentation](https://cloud.google.com/docs/). The repo is organized as follows: diff --git a/vision/face-detection/src/main/java/com/google/cloud/vision/samples/facedetect/FaceDetectApp.java b/vision/face-detection/src/main/java/com/google/cloud/vision/samples/facedetect/FaceDetectApp.java index 67d9999de53..aab3ebc1816 100644 --- a/vision/face-detection/src/main/java/com/google/cloud/vision/samples/facedetect/FaceDetectApp.java +++ b/vision/face-detection/src/main/java/com/google/cloud/vision/samples/facedetect/FaceDetectApp.java @@ -23,14 +23,14 @@ import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.vision.v1.Vision; import com.google.api.services.vision.v1.VisionScopes; -import com.google.api.services.vision.v1.model.AnnotateImageRequest; -import com.google.api.services.vision.v1.model.AnnotateImageResponse; -import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest; -import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse; -import com.google.api.services.vision.v1.model.FaceAnnotation; -import com.google.api.services.vision.v1.model.Feature; -import com.google.api.services.vision.v1.model.Image; -import com.google.api.services.vision.v1.model.Vertex; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageRequest; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageResponse; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesRequest; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesResponse; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Feature; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Image; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Vertex; import com.google.common.collect.ImmutableList; import java.awt.BasicStroke; @@ -81,7 +81,7 @@ public static void main(String[] args) throws IOException, GeneralSecurityExcept } FaceDetectApp app = new FaceDetectApp(getVisionService()); - List faces = app.detectFaces(inputPath, MAX_RESULTS); + List faces = app.detectFaces(inputPath, MAX_RESULTS); System.out.printf("Found %d face%s\n", faces.size(), faces.size() == 1 ? "" : "s"); System.out.printf("Writing to file %s\n", outputPath); app.writeWithFaces(inputPath, outputPath, faces); @@ -115,25 +115,25 @@ public FaceDetectApp(Vision vision) { /** * Gets up to {@code maxResults} faces for an image stored at {@code path}. */ - public List detectFaces(Path path, int maxResults) throws IOException { + public List detectFaces(Path path, int maxResults) throws IOException { byte[] data = Files.readAllBytes(path); - AnnotateImageRequest request = - new AnnotateImageRequest() - .setImage(new Image().encodeContent(data)) + GoogleCloudVisionV1AnnotateImageRequest request = + new GoogleCloudVisionV1AnnotateImageRequest() + .setImage(new GoogleCloudVisionV1Image().encodeContent(data)) .setFeatures(ImmutableList.of( - new Feature() + new GoogleCloudVisionV1Feature() .setType("FACE_DETECTION") .setMaxResults(maxResults))); Vision.Images.Annotate annotate = vision.images() - .annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request))); + .annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request))); // Due to a bug: requests to Vision API containing large images fail when GZipped. annotate.setDisableGZipContent(true); - BatchAnnotateImagesResponse batchResponse = annotate.execute(); + GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute(); assert batchResponse.getResponses().size() == 1; - AnnotateImageResponse response = batchResponse.getResponses().get(0); + GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(0); if (response.getFaceAnnotations() == null) { throw new IOException( response.getError() != null @@ -148,7 +148,7 @@ public List detectFaces(Path path, int maxResults) throws IOExce /** * Reads image {@code inputPath} and writes {@code outputPath} with {@code faces} outlined. */ - private static void writeWithFaces(Path inputPath, Path outputPath, List faces) + private static void writeWithFaces(Path inputPath, Path outputPath, List faces) throws IOException { BufferedImage img = ImageIO.read(inputPath.toFile()); annotateWithFaces(img, faces); @@ -158,8 +158,8 @@ private static void writeWithFaces(Path inputPath, Path outputPath, List faces) { - for (FaceAnnotation face : faces) { + public static void annotateWithFaces(BufferedImage img, List faces) { + for (GoogleCloudVisionV1FaceAnnotation face : faces) { annotateWithFace(img, face); } } @@ -167,10 +167,10 @@ public static void annotateWithFaces(BufferedImage img, List fac /** * Annotates an image {@code img} with a polygon defined by {@code face}. */ - private static void annotateWithFace(BufferedImage img, FaceAnnotation face) { + private static void annotateWithFace(BufferedImage img, GoogleCloudVisionV1FaceAnnotation face) { Graphics2D gfx = img.createGraphics(); Polygon poly = new Polygon(); - for (Vertex vertex : face.getFdBoundingPoly().getVertices()) { + for (GoogleCloudVisionV1Vertex vertex : face.getFdBoundingPoly().getVertices()) { poly.addPoint(vertex.getX(), vertex.getY()); } gfx.setStroke(new BasicStroke(5)); diff --git a/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppIT.java b/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppIT.java index fadc06abb63..3b79c226f80 100644 --- a/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppIT.java +++ b/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppIT.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; -import com.google.api.services.vision.v1.model.FaceAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation; import org.junit.Before; import org.junit.Test; @@ -45,7 +45,7 @@ public class FaceDetectAppIT { } @Test public void detectFaces_withFace_returnsAtLeastOneFace() throws Exception { - List faces = + List faces = appUnderTest.detectFaces(Paths.get("data/face.jpg"), MAX_RESULTS); assertThat(faces).named("face.jpg faces").isNotEmpty(); diff --git a/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java b/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java index 24642005273..bdf09524910 100644 --- a/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java +++ b/vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java @@ -18,9 +18,9 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.api.services.vision.v1.model.BoundingPoly; -import com.google.api.services.vision.v1.model.FaceAnnotation; -import com.google.api.services.vision.v1.model.Vertex; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BoundingPoly; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Vertex; import com.google.common.collect.ImmutableList; import org.junit.Test; @@ -36,21 +36,21 @@ public class FaceDetectAppTest { @Test public void annotateWithFaces_manyFaces_outlinesFaces() throws Exception { // Arrange - ImmutableList faces = + ImmutableList faces = ImmutableList.of( - new FaceAnnotation() + new GoogleCloudVisionV1FaceAnnotation() .setFdBoundingPoly( - new BoundingPoly().setVertices(ImmutableList.of( - new Vertex().setX(10).setY(5), - new Vertex().setX(20).setY(5), - new Vertex().setX(20).setY(25), - new Vertex().setX(10).setY(25)))), - new FaceAnnotation() + new GoogleCloudVisionV1BoundingPoly().setVertices(ImmutableList.of( + new GoogleCloudVisionV1Vertex().setX(10).setY(5), + new GoogleCloudVisionV1Vertex().setX(20).setY(5), + new GoogleCloudVisionV1Vertex().setX(20).setY(25), + new GoogleCloudVisionV1Vertex().setX(10).setY(25)))), + new GoogleCloudVisionV1FaceAnnotation() .setFdBoundingPoly( - new BoundingPoly().setVertices(ImmutableList.of( - new Vertex().setX(60).setY(50), - new Vertex().setX(70).setY(60), - new Vertex().setX(50).setY(60))))); + new GoogleCloudVisionV1BoundingPoly().setVertices(ImmutableList.of( + new GoogleCloudVisionV1Vertex().setX(60).setY(50), + new GoogleCloudVisionV1Vertex().setX(70).setY(60), + new GoogleCloudVisionV1Vertex().setX(50).setY(60))))); BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); // Act diff --git a/vision/label/src/main/java/com/google/cloud/vision/samples/label/LabelApp.java b/vision/label/src/main/java/com/google/cloud/vision/samples/label/LabelApp.java index fd4b62233e8..16983c4f592 100644 --- a/vision/label/src/main/java/com/google/cloud/vision/samples/label/LabelApp.java +++ b/vision/label/src/main/java/com/google/cloud/vision/samples/label/LabelApp.java @@ -23,13 +23,13 @@ import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.vision.v1.Vision; import com.google.api.services.vision.v1.VisionScopes; -import com.google.api.services.vision.v1.model.AnnotateImageRequest; -import com.google.api.services.vision.v1.model.AnnotateImageResponse; -import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest; -import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse; -import com.google.api.services.vision.v1.model.EntityAnnotation; -import com.google.api.services.vision.v1.model.Feature; -import com.google.api.services.vision.v1.model.Image; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageRequest; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageResponse; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesRequest; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesResponse; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Feature; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Image; import com.google.common.collect.ImmutableList; import java.io.IOException; @@ -74,9 +74,9 @@ public static void main(String[] args) throws IOException, GeneralSecurityExcept /** * Prints the labels received from the Vision API. */ - public static void printLabels(PrintStream out, Path imagePath, List labels) { + public static void printLabels(PrintStream out, Path imagePath, List labels) { out.printf("Labels for image %s:\n", imagePath); - for (EntityAnnotation label : labels) { + for (GoogleCloudVisionV1EntityAnnotation label : labels) { out.printf( "\t%s (score: %.3f)\n", label.getDescription(), @@ -114,28 +114,28 @@ public LabelApp(Vision vision) { /** * Gets up to {@code maxResults} labels for an image stored at {@code path}. */ - public List labelImage(Path path, int maxResults) throws IOException { + public List labelImage(Path path, int maxResults) throws IOException { // [START construct_request] byte[] data = Files.readAllBytes(path); - AnnotateImageRequest request = - new AnnotateImageRequest() - .setImage(new Image().encodeContent(data)) + GoogleCloudVisionV1AnnotateImageRequest request = + new GoogleCloudVisionV1AnnotateImageRequest() + .setImage(new GoogleCloudVisionV1Image().encodeContent(data)) .setFeatures(ImmutableList.of( - new Feature() + new GoogleCloudVisionV1Feature() .setType("LABEL_DETECTION") .setMaxResults(maxResults))); Vision.Images.Annotate annotate = vision.images() - .annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request))); + .annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request))); // Due to a bug: requests to Vision API containing large images fail when GZipped. annotate.setDisableGZipContent(true); // [END construct_request] // [START parse_response] - BatchAnnotateImagesResponse batchResponse = annotate.execute(); + GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute(); assert batchResponse.getResponses().size() == 1; - AnnotateImageResponse response = batchResponse.getResponses().get(0); + GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(0); if (response.getLabelAnnotations() == null) { throw new IOException( response.getError() != null diff --git a/vision/label/src/test/java/com/google/cloud/vision/samples/label/LabelAppIT.java b/vision/label/src/test/java/com/google/cloud/vision/samples/label/LabelAppIT.java index 17886c77432..18f0bcc5512 100644 --- a/vision/label/src/test/java/com/google/cloud/vision/samples/label/LabelAppIT.java +++ b/vision/label/src/test/java/com/google/cloud/vision/samples/label/LabelAppIT.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; -import com.google.api.services.vision.v1.model.EntityAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation; import com.google.common.collect.ImmutableSet; import org.junit.Before; @@ -46,11 +46,11 @@ public class LabelAppIT { } @Test public void labelImage_cat_returnsCatDescription() throws Exception { - List labels = + List labels = appUnderTest.labelImage(Paths.get("data/cat.jpg"), MAX_LABELS); ImmutableSet.Builder builder = ImmutableSet.builder(); - for (EntityAnnotation label : labels) { + for (GoogleCloudVisionV1EntityAnnotation label : labels) { builder.add(label.getDescription()); } ImmutableSet descriptions = builder.build(); diff --git a/vision/label/src/test/java/com/google/cloud/vision/samples/label/LabelAppTest.java b/vision/label/src/test/java/com/google/cloud/vision/samples/label/LabelAppTest.java index 6a238a3d248..afda34c5985 100644 --- a/vision/label/src/test/java/com/google/cloud/vision/samples/label/LabelAppTest.java +++ b/vision/label/src/test/java/com/google/cloud/vision/samples/label/LabelAppTest.java @@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.api.services.vision.v1.model.EntityAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation; import com.google.common.collect.ImmutableList; import org.junit.Test; @@ -42,7 +42,7 @@ public class LabelAppTest { // Act LabelApp.printLabels( - out, Paths.get("path/to/some/image.jpg"), ImmutableList.of()); + out, Paths.get("path/to/some/image.jpg"), ImmutableList.of()); // Assert assertThat(bout.toString()).contains("No labels found."); @@ -52,11 +52,11 @@ public class LabelAppTest { // Arrange ByteArrayOutputStream bout = new ByteArrayOutputStream(); PrintStream out = new PrintStream(bout); - ImmutableList labels = + ImmutableList labels = ImmutableList.of( - new EntityAnnotation().setDescription("dog").setScore(0.7564f), - new EntityAnnotation().setDescription("husky").setScore(0.67891f), - new EntityAnnotation().setDescription("poodle").setScore(0.1233f)); + new GoogleCloudVisionV1EntityAnnotation().setDescription("dog").setScore(0.7564f), + new GoogleCloudVisionV1EntityAnnotation().setDescription("husky").setScore(0.67891f), + new GoogleCloudVisionV1EntityAnnotation().setDescription("poodle").setScore(0.1233f)); // Act LabelApp.printLabels(out, Paths.get("path/to/some/image.jpg"), labels); diff --git a/vision/landmark-detection/src/main/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmark.java b/vision/landmark-detection/src/main/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmark.java index 8274ed88f92..8b5c7b98886 100644 --- a/vision/landmark-detection/src/main/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmark.java +++ b/vision/landmark-detection/src/main/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmark.java @@ -23,14 +23,14 @@ import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.vision.v1.Vision; import com.google.api.services.vision.v1.VisionScopes; -import com.google.api.services.vision.v1.model.AnnotateImageRequest; -import com.google.api.services.vision.v1.model.AnnotateImageResponse; -import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest; -import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse; -import com.google.api.services.vision.v1.model.EntityAnnotation; -import com.google.api.services.vision.v1.model.Feature; -import com.google.api.services.vision.v1.model.Image; -import com.google.api.services.vision.v1.model.ImageSource; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageRequest; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageResponse; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesRequest; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesResponse; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Feature; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Image; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1ImageSource; import com.google.common.collect.ImmutableList; import java.io.IOException; @@ -68,9 +68,9 @@ public static void main(String[] args) throws IOException, GeneralSecurityExcept } DetectLandmark app = new DetectLandmark(getVisionService()); - List landmarks = app.identifyLandmark(args[0], MAX_RESULTS); + List landmarks = app.identifyLandmark(args[0], MAX_RESULTS); System.out.printf("Found %d landmark%s\n", landmarks.size(), landmarks.size() == 1 ? "" : "s"); - for (EntityAnnotation annotation : landmarks) { + for (GoogleCloudVisionV1EntityAnnotation annotation : landmarks) { System.out.printf("\t%s\n", annotation.getDescription()); } } @@ -103,24 +103,24 @@ public DetectLandmark(Vision vision) { /** * Gets up to {@code maxResults} landmarks for an image stored at {@code uri}. */ - public List identifyLandmark(String uri, int maxResults) throws IOException { - AnnotateImageRequest request = - new AnnotateImageRequest() - .setImage(new Image().setSource( - new ImageSource().setGcsImageUri(uri))) + public List identifyLandmark(String uri, int maxResults) throws IOException { + GoogleCloudVisionV1AnnotateImageRequest request = + new GoogleCloudVisionV1AnnotateImageRequest() + .setImage(new GoogleCloudVisionV1Image().setSource( + new GoogleCloudVisionV1ImageSource().setGcsImageUri(uri))) .setFeatures(ImmutableList.of( - new Feature() + new GoogleCloudVisionV1Feature() .setType("LANDMARK_DETECTION") .setMaxResults(maxResults))); Vision.Images.Annotate annotate = vision.images() - .annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request))); + .annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request))); // Due to a bug: requests to Vision API containing large images fail when GZipped. annotate.setDisableGZipContent(true); - BatchAnnotateImagesResponse batchResponse = annotate.execute(); + GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute(); assert batchResponse.getResponses().size() == 1; - AnnotateImageResponse response = batchResponse.getResponses().get(0); + GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(0); if (response.getLandmarkAnnotations() == null) { throw new IOException( response.getError() != null diff --git a/vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java b/vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java index bb4c4e04f77..273156fedd2 100644 --- a/vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java +++ b/vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; -import com.google.api.services.vision.v1.model.EntityAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation; import org.junit.Before; import org.junit.Test; @@ -49,7 +49,7 @@ public class DetectLandmarkIT { } @Test public void identifyLandmark_withLandmark_returnsKnownLandmark() throws Exception { - List landmarks = appUnderTest.identifyLandmark(LANDMARK_URI, MAX_RESULTS); + List landmarks = appUnderTest.identifyLandmark(LANDMARK_URI, MAX_RESULTS); assertThat(landmarks).named("water.jpg landmarks").isNotEmpty(); assertThat(landmarks.get(0).getDescription()) diff --git a/vision/text/src/main/java/com/google/cloud/vision/samples/text/ImageText.java b/vision/text/src/main/java/com/google/cloud/vision/samples/text/ImageText.java index 4d695f9401f..afbe3c4f5b8 100644 --- a/vision/text/src/main/java/com/google/cloud/vision/samples/text/ImageText.java +++ b/vision/text/src/main/java/com/google/cloud/vision/samples/text/ImageText.java @@ -16,8 +16,8 @@ package com.google.cloud.vision.samples.text; -import com.google.api.services.vision.v1.model.EntityAnnotation; -import com.google.api.services.vision.v1.model.Status; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation; +import com.google.api.services.vision.v1.model.GoogleRpcStatus; import java.nio.file.Path; import java.util.List; @@ -29,8 +29,8 @@ */ public class ImageText { private Path pth; - private List ts; - private Status err; + private List ts; + private GoogleRpcStatus err; public static Builder builder() { return new Builder(); @@ -42,19 +42,19 @@ public Path path() { return this.pth; } - public List textAnnotations() { + public List textAnnotations() { return this.ts; } @Nullable - public Status error() { + public GoogleRpcStatus error() { return this.err; } public static class Builder { private Path pth; - private List ts; - private Status err; + private List ts; + private GoogleRpcStatus err; Builder() {} @@ -63,12 +63,12 @@ public Builder path(Path path) { return this; } - public Builder textAnnotations(List ts) { + public Builder textAnnotations(List ts) { this.ts = ts; return this; } - public Builder error(@Nullable Status err) { + public Builder error(@Nullable GoogleRpcStatus err) { this.err = err; return this; } diff --git a/vision/text/src/main/java/com/google/cloud/vision/samples/text/TextApp.java b/vision/text/src/main/java/com/google/cloud/vision/samples/text/TextApp.java index 951dacd00f6..7c29b113a8e 100644 --- a/vision/text/src/main/java/com/google/cloud/vision/samples/text/TextApp.java +++ b/vision/text/src/main/java/com/google/cloud/vision/samples/text/TextApp.java @@ -22,14 +22,14 @@ import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.services.vision.v1.Vision; import com.google.api.services.vision.v1.VisionScopes; -import com.google.api.services.vision.v1.model.AnnotateImageRequest; -import com.google.api.services.vision.v1.model.AnnotateImageResponse; -import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest; -import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse; -import com.google.api.services.vision.v1.model.EntityAnnotation; -import com.google.api.services.vision.v1.model.Feature; -import com.google.api.services.vision.v1.model.Image; -import com.google.api.services.vision.v1.model.Status; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageRequest; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageResponse; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesRequest; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesResponse; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Feature; +import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Image; +import com.google.api.services.vision.v1.model.GoogleRpcStatus; import com.google.common.base.MoreObjects; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableList; @@ -168,39 +168,39 @@ public void indexDirectory(Path inputPath) throws IOException { * Gets up to {@code maxResults} text annotations for images stored at {@code paths}. */ public ImmutableList detectText(List paths) { - ImmutableList.Builder requests = ImmutableList.builder(); + ImmutableList.Builder requests = ImmutableList.builder(); try { for (Path path : paths) { byte[] data; data = Files.readAllBytes(path); requests.add( - new AnnotateImageRequest() - .setImage(new Image().encodeContent(data)) + new GoogleCloudVisionV1AnnotateImageRequest() + .setImage(new GoogleCloudVisionV1Image().encodeContent(data)) .setFeatures(ImmutableList.of( - new Feature() + new GoogleCloudVisionV1Feature() .setType("TEXT_DETECTION") .setMaxResults(MAX_RESULTS)))); } Vision.Images.Annotate annotate = vision.images() - .annotate(new BatchAnnotateImagesRequest().setRequests(requests.build())); + .annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(requests.build())); // Due to a bug: requests to Vision API containing large images fail when GZipped. annotate.setDisableGZipContent(true); - BatchAnnotateImagesResponse batchResponse = annotate.execute(); + GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute(); assert batchResponse.getResponses().size() == paths.size(); ImmutableList.Builder output = ImmutableList.builder(); for (int i = 0; i < paths.size(); i++) { Path path = paths.get(i); - AnnotateImageResponse response = batchResponse.getResponses().get(i); + GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(i); output.add( ImageText.builder() .path(path) .textAnnotations( MoreObjects.firstNonNull( response.getTextAnnotations(), - ImmutableList.of())) + ImmutableList.of())) .error(response.getError()) .build()); } @@ -212,8 +212,8 @@ public ImmutableList detectText(List paths) { output.add( ImageText.builder() .path(path) - .textAnnotations(ImmutableList.of()) - .error(new Status().setMessage(ex.getMessage())) + .textAnnotations(ImmutableList.of()) + .error(new GoogleRpcStatus().setMessage(ex.getMessage())) .build()); } return output.build(); @@ -236,7 +236,7 @@ public boolean successfullyDetectedText(ImageText image) { */ public Word extractDescriptions(ImageText image) { String document = ""; - for (EntityAnnotation text : image.textAnnotations()) { + for (GoogleCloudVisionV1EntityAnnotation text : image.textAnnotations()) { document += text.getDescription(); } if (document.equals("")) {