Skip to content

Commit da18160

Browse files
committed
Reverted Vision API classes.
1 parent 58a9670 commit da18160

File tree

7 files changed

+89
-89
lines changed

7 files changed

+89
-89
lines changed

vision/face-detection/src/main/java/com/google/cloud/vision/samples/facedetect/FaceDetectApp.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import com.google.api.client.json.jackson2.JacksonFactory;
2424
import com.google.api.services.vision.v1.Vision;
2525
import com.google.api.services.vision.v1.VisionScopes;
26-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageRequest;
27-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageResponse;
28-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesRequest;
29-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesResponse;
30-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation;
31-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Feature;
32-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Image;
33-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Vertex;
26+
import com.google.api.services.vision.v1.model.AnnotateImageRequest;
27+
import com.google.api.services.vision.v1.model.AnnotateImageResponse;
28+
import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest;
29+
import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse;
30+
import com.google.api.services.vision.v1.model.FaceAnnotation;
31+
import com.google.api.services.vision.v1.model.Feature;
32+
import com.google.api.services.vision.v1.model.Image;
33+
import com.google.api.services.vision.v1.model.Vertex;
3434
import com.google.common.collect.ImmutableList;
3535

3636
import java.awt.BasicStroke;
@@ -81,7 +81,7 @@ public static void main(String[] args) throws IOException, GeneralSecurityExcept
8181
}
8282

8383
FaceDetectApp app = new FaceDetectApp(getVisionService());
84-
List<GoogleCloudVisionV1FaceAnnotation> faces = app.detectFaces(inputPath, MAX_RESULTS);
84+
List<FaceAnnotation> faces = app.detectFaces(inputPath, MAX_RESULTS);
8585
System.out.printf("Found %d face%s\n", faces.size(), faces.size() == 1 ? "" : "s");
8686
System.out.printf("Writing to file %s\n", outputPath);
8787
app.writeWithFaces(inputPath, outputPath, faces);
@@ -115,25 +115,25 @@ public FaceDetectApp(Vision vision) {
115115
/**
116116
* Gets up to {@code maxResults} faces for an image stored at {@code path}.
117117
*/
118-
public List<GoogleCloudVisionV1FaceAnnotation> detectFaces(Path path, int maxResults) throws IOException {
118+
public List<FaceAnnotation> detectFaces(Path path, int maxResults) throws IOException {
119119
byte[] data = Files.readAllBytes(path);
120120

121-
GoogleCloudVisionV1AnnotateImageRequest request =
122-
new GoogleCloudVisionV1AnnotateImageRequest()
123-
.setImage(new GoogleCloudVisionV1Image().encodeContent(data))
121+
AnnotateImageRequest request =
122+
new AnnotateImageRequest()
123+
.setImage(new Image().encodeContent(data))
124124
.setFeatures(ImmutableList.of(
125-
new GoogleCloudVisionV1Feature()
125+
new Feature()
126126
.setType("FACE_DETECTION")
127127
.setMaxResults(maxResults)));
128128
Vision.Images.Annotate annotate =
129129
vision.images()
130-
.annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
130+
.annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
131131
// Due to a bug: requests to Vision API containing large images fail when GZipped.
132132
annotate.setDisableGZipContent(true);
133133

134-
GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute();
134+
BatchAnnotateImagesResponse batchResponse = annotate.execute();
135135
assert batchResponse.getResponses().size() == 1;
136-
GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(0);
136+
AnnotateImageResponse response = batchResponse.getResponses().get(0);
137137
if (response.getFaceAnnotations() == null) {
138138
throw new IOException(
139139
response.getError() != null
@@ -148,7 +148,7 @@ public List<GoogleCloudVisionV1FaceAnnotation> detectFaces(Path path, int maxRes
148148
/**
149149
* Reads image {@code inputPath} and writes {@code outputPath} with {@code faces} outlined.
150150
*/
151-
private static void writeWithFaces(Path inputPath, Path outputPath, List<GoogleCloudVisionV1FaceAnnotation> faces)
151+
private static void writeWithFaces(Path inputPath, Path outputPath, List<FaceAnnotation> faces)
152152
throws IOException {
153153
BufferedImage img = ImageIO.read(inputPath.toFile());
154154
annotateWithFaces(img, faces);
@@ -158,19 +158,19 @@ private static void writeWithFaces(Path inputPath, Path outputPath, List<GoogleC
158158
/**
159159
* Annotates an image {@code img} with a polygon around each face in {@code faces}.
160160
*/
161-
public static void annotateWithFaces(BufferedImage img, List<GoogleCloudVisionV1FaceAnnotation> faces) {
162-
for (GoogleCloudVisionV1FaceAnnotation face : faces) {
161+
public static void annotateWithFaces(BufferedImage img, List<FaceAnnotation> faces) {
162+
for (FaceAnnotation face : faces) {
163163
annotateWithFace(img, face);
164164
}
165165
}
166166

167167
/**
168168
* Annotates an image {@code img} with a polygon defined by {@code face}.
169169
*/
170-
private static void annotateWithFace(BufferedImage img, GoogleCloudVisionV1FaceAnnotation face) {
170+
private static void annotateWithFace(BufferedImage img, FaceAnnotation face) {
171171
Graphics2D gfx = img.createGraphics();
172172
Polygon poly = new Polygon();
173-
for (GoogleCloudVisionV1Vertex vertex : face.getFdBoundingPoly().getVertices()) {
173+
for (Vertex vertex : face.getFdBoundingPoly().getVertices()) {
174174
poly.addPoint(vertex.getX(), vertex.getY());
175175
}
176176
gfx.setStroke(new BasicStroke(5));

vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static com.google.common.truth.Truth.assertThat;
2020
import static org.junit.Assert.fail;
2121

22-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation;
22+
import com.google.api.services.vision.v1.model.FaceAnnotation;
2323

2424
import org.junit.Before;
2525
import org.junit.Test;
@@ -45,7 +45,7 @@ public class FaceDetectAppIT {
4545
}
4646

4747
@Test public void detectFaces_withFace_returnsAtLeastOneFace() throws Exception {
48-
List<GoogleCloudVisionV1FaceAnnotation> faces =
48+
List<FaceAnnotation> faces =
4949
appUnderTest.detectFaces(Paths.get("data/face.jpg"), MAX_RESULTS);
5050

5151
assertThat(faces).named("face.jpg faces").isNotEmpty();

vision/face-detection/src/test/java/com/google/cloud/vision/samples/facedetect/FaceDetectAppTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BoundingPoly;
22-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1FaceAnnotation;
23-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Vertex;
21+
import com.google.api.services.vision.v1.model.BoundingPoly;
22+
import com.google.api.services.vision.v1.model.FaceAnnotation;
23+
import com.google.api.services.vision.v1.model.Vertex;
2424
import com.google.common.collect.ImmutableList;
2525

2626
import org.junit.Test;
@@ -36,21 +36,21 @@
3636
public class FaceDetectAppTest {
3737
@Test public void annotateWithFaces_manyFaces_outlinesFaces() throws Exception {
3838
// Arrange
39-
ImmutableList<GoogleCloudVisionV1FaceAnnotation> faces =
39+
ImmutableList<FaceAnnotation> faces =
4040
ImmutableList.of(
41-
new GoogleCloudVisionV1FaceAnnotation()
41+
new FaceAnnotation()
4242
.setFdBoundingPoly(
43-
new GoogleCloudVisionV1BoundingPoly().setVertices(ImmutableList.of(
44-
new GoogleCloudVisionV1Vertex().setX(10).setY(5),
45-
new GoogleCloudVisionV1Vertex().setX(20).setY(5),
46-
new GoogleCloudVisionV1Vertex().setX(20).setY(25),
47-
new GoogleCloudVisionV1Vertex().setX(10).setY(25)))),
48-
new GoogleCloudVisionV1FaceAnnotation()
43+
new BoundingPoly().setVertices(ImmutableList.of(
44+
new Vertex().setX(10).setY(5),
45+
new Vertex().setX(20).setY(5),
46+
new Vertex().setX(20).setY(25),
47+
new Vertex().setX(10).setY(25)))),
48+
new FaceAnnotation()
4949
.setFdBoundingPoly(
50-
new GoogleCloudVisionV1BoundingPoly().setVertices(ImmutableList.of(
51-
new GoogleCloudVisionV1Vertex().setX(60).setY(50),
52-
new GoogleCloudVisionV1Vertex().setX(70).setY(60),
53-
new GoogleCloudVisionV1Vertex().setX(50).setY(60)))));
50+
new BoundingPoly().setVertices(ImmutableList.of(
51+
new Vertex().setX(60).setY(50),
52+
new Vertex().setX(70).setY(60),
53+
new Vertex().setX(50).setY(60)))));
5454
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
5555

5656
// Act

vision/landmark-detection/src/main/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmark.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import com.google.api.client.json.jackson2.JacksonFactory;
2424
import com.google.api.services.vision.v1.Vision;
2525
import com.google.api.services.vision.v1.VisionScopes;
26-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageRequest;
27-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1AnnotateImageResponse;
28-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesRequest;
29-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1BatchAnnotateImagesResponse;
30-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation;
31-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Feature;
32-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1Image;
33-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1ImageSource;
26+
import com.google.api.services.vision.v1.model.AnnotateImageRequest;
27+
import com.google.api.services.vision.v1.model.AnnotateImageResponse;
28+
import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest;
29+
import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse;
30+
import com.google.api.services.vision.v1.model.EntityAnnotation;
31+
import com.google.api.services.vision.v1.model.Feature;
32+
import com.google.api.services.vision.v1.model.Image;
33+
import com.google.api.services.vision.v1.model.ImageSource;
3434
import com.google.common.collect.ImmutableList;
3535

3636
import java.io.IOException;
@@ -68,9 +68,9 @@ public static void main(String[] args) throws IOException, GeneralSecurityExcept
6868
}
6969

7070
DetectLandmark app = new DetectLandmark(getVisionService());
71-
List<GoogleCloudVisionV1EntityAnnotation> landmarks = app.identifyLandmark(args[0], MAX_RESULTS);
71+
List<EntityAnnotation> landmarks = app.identifyLandmark(args[0], MAX_RESULTS);
7272
System.out.printf("Found %d landmark%s\n", landmarks.size(), landmarks.size() == 1 ? "" : "s");
73-
for (GoogleCloudVisionV1EntityAnnotation annotation : landmarks) {
73+
for (EntityAnnotation annotation : landmarks) {
7474
System.out.printf("\t%s\n", annotation.getDescription());
7575
}
7676
}
@@ -103,24 +103,24 @@ public DetectLandmark(Vision vision) {
103103
/**
104104
* Gets up to {@code maxResults} landmarks for an image stored at {@code uri}.
105105
*/
106-
public List<GoogleCloudVisionV1EntityAnnotation> identifyLandmark(String uri, int maxResults) throws IOException {
107-
GoogleCloudVisionV1AnnotateImageRequest request =
108-
new GoogleCloudVisionV1AnnotateImageRequest()
109-
.setImage(new GoogleCloudVisionV1Image().setSource(
110-
new GoogleCloudVisionV1ImageSource().setGcsImageUri(uri)))
106+
public List<EntityAnnotation> identifyLandmark(String uri, int maxResults) throws IOException {
107+
AnnotateImageRequest request =
108+
new AnnotateImageRequest()
109+
.setImage(new Image().setSource(
110+
new ImageSource().setGcsImageUri(uri)))
111111
.setFeatures(ImmutableList.of(
112-
new GoogleCloudVisionV1Feature()
112+
new Feature()
113113
.setType("LANDMARK_DETECTION")
114114
.setMaxResults(maxResults)));
115115
Vision.Images.Annotate annotate =
116116
vision.images()
117-
.annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
117+
.annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
118118
// Due to a bug: requests to Vision API containing large images fail when GZipped.
119119
annotate.setDisableGZipContent(true);
120120

121-
GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute();
121+
BatchAnnotateImagesResponse batchResponse = annotate.execute();
122122
assert batchResponse.getResponses().size() == 1;
123-
GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(0);
123+
AnnotateImageResponse response = batchResponse.getResponses().get(0);
124124
if (response.getLandmarkAnnotations() == null) {
125125
throw new IOException(
126126
response.getError() != null

vision/landmark-detection/src/test/java/com/google/cloud/vision/samples/landmarkdetection/DetectLandmarkIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static com.google.common.truth.Truth.assertThat;
2020
import static org.junit.Assert.fail;
2121

22-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation;
22+
import com.google.api.services.vision.v1.model.EntityAnnotation;
2323

2424
import org.junit.Before;
2525
import org.junit.Test;
@@ -49,7 +49,7 @@ public class DetectLandmarkIT {
4949
}
5050

5151
@Test public void identifyLandmark_withLandmark_returnsKnownLandmark() throws Exception {
52-
List<GoogleCloudVisionV1EntityAnnotation> landmarks = appUnderTest.identifyLandmark(LANDMARK_URI, MAX_RESULTS);
52+
List<EntityAnnotation> landmarks = appUnderTest.identifyLandmark(LANDMARK_URI, MAX_RESULTS);
5353

5454
assertThat(landmarks).named("water.jpg landmarks").isNotEmpty();
5555
assertThat(landmarks.get(0).getDescription())

vision/text/src/main/java/com/google/cloud/vision/samples/text/ImageText.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.google.cloud.vision.samples.text;
1818

19-
import com.google.api.services.vision.v1.model.GoogleCloudVisionV1EntityAnnotation;
20-
import com.google.api.services.vision.v1.model.GoogleRpcStatus;
19+
import com.google.api.services.vision.v1.model.EntityAnnotation;
20+
import com.google.api.services.vision.v1.model.Status;
2121

2222
import java.nio.file.Path;
2323
import java.util.List;
@@ -29,8 +29,8 @@
2929
*/
3030
public class ImageText {
3131
private Path pth;
32-
private List<GoogleCloudVisionV1EntityAnnotation> ts;
33-
private GoogleRpcStatus err;
32+
private List<EntityAnnotation> ts;
33+
private Status err;
3434

3535
public static Builder builder() {
3636
return new Builder();
@@ -42,19 +42,19 @@ public Path path() {
4242
return this.pth;
4343
}
4444

45-
public List<GoogleCloudVisionV1EntityAnnotation> textAnnotations() {
45+
public List<EntityAnnotation> textAnnotations() {
4646
return this.ts;
4747
}
4848

4949
@Nullable
50-
public GoogleRpcStatus error() {
50+
public Status error() {
5151
return this.err;
5252
}
5353

5454
public static class Builder {
5555
private Path pth;
56-
private List<GoogleCloudVisionV1EntityAnnotation> ts;
57-
private GoogleRpcStatus err;
56+
private List<EntityAnnotation> ts;
57+
private Status err;
5858

5959
Builder() {}
6060

@@ -63,12 +63,12 @@ public Builder path(Path path) {
6363
return this;
6464
}
6565

66-
public Builder textAnnotations(List<GoogleCloudVisionV1EntityAnnotation> ts) {
66+
public Builder textAnnotations(List<EntityAnnotation> ts) {
6767
this.ts = ts;
6868
return this;
6969
}
7070

71-
public Builder error(@Nullable GoogleRpcStatus err) {
71+
public Builder error(@Nullable Status err) {
7272
this.err = err;
7373
return this;
7474
}

0 commit comments

Comments
 (0)