17
17
package com .example .vision ;
18
18
19
19
// [START vision_async_batch_annotate_images_beta]
20
- import com .google .api .core . ApiFuture ;
20
+ import com .google .api .gax . longrunning . OperationFuture ;
21
21
import com .google .api .gax .paging .Page ;
22
22
import com .google .cloud .storage .Blob ;
23
23
import com .google .cloud .storage .Bucket ;
26
26
import com .google .cloud .storage .StorageOptions ;
27
27
import com .google .cloud .vision .v1p4beta1 .AnnotateImageRequest ;
28
28
import com .google .cloud .vision .v1p4beta1 .AsyncBatchAnnotateImagesRequest ;
29
- import com .google .cloud .vision .v1p4beta1 .BatchAnnotateImagesResponse . Builder ;
29
+ import com .google .cloud .vision .v1p4beta1 .AsyncBatchAnnotateImagesResponse ;
30
30
import com .google .cloud .vision .v1p4beta1 .BatchAnnotateImagesResponse ;
31
+ import com .google .cloud .vision .v1p4beta1 .BatchAnnotateImagesResponse .Builder ;
31
32
import com .google .cloud .vision .v1p4beta1 .Feature ;
32
33
import com .google .cloud .vision .v1p4beta1 .Feature .Type ;
33
34
import com .google .cloud .vision .v1p4beta1 .GcsDestination ;
34
35
import com .google .cloud .vision .v1p4beta1 .Image ;
35
36
import com .google .cloud .vision .v1p4beta1 .ImageAnnotatorClient ;
36
37
import com .google .cloud .vision .v1p4beta1 .ImageSource ;
38
+ import com .google .cloud .vision .v1p4beta1 .OperationMetadata ;
37
39
import com .google .cloud .vision .v1p4beta1 .OutputConfig ;
38
-
39
- import com .google .longrunning .Operation ;
40
40
import com .google .protobuf .util .JsonFormat ;
41
41
import java .util .ArrayList ;
42
42
import java .util .List ;
@@ -51,7 +51,6 @@ public static void asyncBatchAnnotateImagesGcs(String gcsSourcePath, String gcsD
51
51
throws Exception {
52
52
// String gcsSourcePath = "gs://YOUR_BUCKET_ID/path_to_your_data";
53
53
// String gcsDestinationPath = "gs://YOUR_BUCKET_ID/path_to_store_annotation";
54
-
55
54
try (ImageAnnotatorClient client = ImageAnnotatorClient .create ()) {
56
55
List <AnnotateImageRequest > requests = new ArrayList <>();
57
56
@@ -87,13 +86,14 @@ public static void asyncBatchAnnotateImagesGcs(String gcsSourcePath, String gcsD
87
86
.setOutputConfig (outputConfig )
88
87
.build ();
89
88
90
- ApiFuture <Operation > future = client .asyncBatchAnnotateImagesCallable ().futureCall (request );
91
- // Wait for the request to finish. (The result is not used, since the API saves the result to
92
- // the specified location on GCS.)
93
- Operation response = future .get (180 , TimeUnit .SECONDS );
94
89
90
+ OperationFuture <AsyncBatchAnnotateImagesResponse , OperationMetadata > response =
91
+ client .asyncBatchAnnotateImagesAsync (request );
95
92
System .out .println ("Waiting for the operation to finish." );
96
93
94
+ // we're not processing the response, since we'll be reading the output from GCS.
95
+ response .get (180 , TimeUnit .SECONDS );
96
+
97
97
// Once the request has completed and the output has been
98
98
// written to GCS, we can list all the output files.
99
99
Storage storage = StorageOptions .getDefaultInstance ().getService ();
0 commit comments