Skip to content

Commit

Permalink
Fixed some more Vision classes back.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisvg committed Nov 15, 2017
1 parent f644a07 commit 008a5cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.google.cloud.videointelligence.v1beta2.LabelSegment;
import com.google.cloud.videointelligence.v1beta2.VideoAnnotationResults;
import com.google.cloud.videointelligence.v1beta2.VideoIntelligenceServiceClient;
import com.google.longrunning.Operation;
import java.util.List;

public class QuickstartSample {
Expand All @@ -48,7 +47,7 @@ public static void main(String[] args) throws Exception {
.addFeatures(Feature.LABEL_DETECTION)
.build();

OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress, Operation> operation =
OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> operation =
client.annotateVideoAsync(request);

System.out.println("Waiting for operation to complete...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.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.common.collect.ImmutableList;

import java.io.IOException;
Expand Down Expand Up @@ -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<GoogleCloudVisionV1EntityAnnotation> labels) {
public static void printLabels(PrintStream out, Path imagePath, List<EntityAnnotation> labels) {
out.printf("Labels for image %s:\n", imagePath);
for (GoogleCloudVisionV1EntityAnnotation label : labels) {
for (EntityAnnotation label : labels) {
out.printf(
"\t%s (score: %.3f)\n",
label.getDescription(),
Expand Down Expand Up @@ -114,28 +114,28 @@ public LabelApp(Vision vision) {
/**
* Gets up to {@code maxResults} labels for an image stored at {@code path}.
*/
public List<GoogleCloudVisionV1EntityAnnotation> labelImage(Path path, int maxResults) throws IOException {
public List<EntityAnnotation> labelImage(Path path, int maxResults) throws IOException {
// [START construct_request]
byte[] data = Files.readAllBytes(path);

GoogleCloudVisionV1AnnotateImageRequest request =
new GoogleCloudVisionV1AnnotateImageRequest()
.setImage(new GoogleCloudVisionV1Image().encodeContent(data))
AnnotateImageRequest request =
new AnnotateImageRequest()
.setImage(new Image().encodeContent(data))
.setFeatures(ImmutableList.of(
new GoogleCloudVisionV1Feature()
new Feature()
.setType("LABEL_DETECTION")
.setMaxResults(maxResults)));
Vision.Images.Annotate annotate =
vision.images()
.annotate(new GoogleCloudVisionV1BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
.annotate(new BatchAnnotateImagesRequest().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]
GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate.execute();
BatchAnnotateImagesResponse batchResponse = annotate.execute();
assert batchResponse.getResponses().size() == 1;
GoogleCloudVisionV1AnnotateImageResponse response = batchResponse.getResponses().get(0);
AnnotateImageResponse response = batchResponse.getResponses().get(0);
if (response.getLabelAnnotations() == null) {
throw new IOException(
response.getError() != null
Expand Down

0 comments on commit 008a5cd

Please sign in to comment.