2323import com .google .api .client .json .jackson2 .JacksonFactory ;
2424import com .google .api .services .vision .v1 .Vision ;
2525import com .google .api .services .vision .v1 .VisionScopes ;
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 ;
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 ;
3434import com .google .common .collect .ImmutableList ;
3535
3636import 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 <FaceAnnotation > faces = app .detectFaces (inputPath , MAX_RESULTS );
84+ List <GoogleCloudVisionV1FaceAnnotation > 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 <FaceAnnotation > detectFaces (Path path , int maxResults ) throws IOException {
118+ public List <GoogleCloudVisionV1FaceAnnotation > detectFaces (Path path , int maxResults ) throws IOException {
119119 byte [] data = Files .readAllBytes (path );
120120
121- AnnotateImageRequest request =
122- new AnnotateImageRequest ()
123- .setImage (new Image ().encodeContent (data ))
121+ GoogleCloudVisionV1AnnotateImageRequest request =
122+ new GoogleCloudVisionV1AnnotateImageRequest ()
123+ .setImage (new GoogleCloudVisionV1Image ().encodeContent (data ))
124124 .setFeatures (ImmutableList .of (
125- new Feature ()
125+ new GoogleCloudVisionV1Feature ()
126126 .setType ("FACE_DETECTION" )
127127 .setMaxResults (maxResults )));
128128 Vision .Images .Annotate annotate =
129129 vision .images ()
130- .annotate (new BatchAnnotateImagesRequest ().setRequests (ImmutableList .of (request )));
130+ .annotate (new GoogleCloudVisionV1BatchAnnotateImagesRequest ().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- BatchAnnotateImagesResponse batchResponse = annotate .execute ();
134+ GoogleCloudVisionV1BatchAnnotateImagesResponse batchResponse = annotate .execute ();
135135 assert batchResponse .getResponses ().size () == 1 ;
136- AnnotateImageResponse response = batchResponse .getResponses ().get (0 );
136+ GoogleCloudVisionV1AnnotateImageResponse response = batchResponse .getResponses ().get (0 );
137137 if (response .getFaceAnnotations () == null ) {
138138 throw new IOException (
139139 response .getError () != null
@@ -148,7 +148,7 @@ public List<FaceAnnotation> detectFaces(Path path, int maxResults) throws IOExce
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 <FaceAnnotation > faces )
151+ private static void writeWithFaces (Path inputPath , Path outputPath , List <GoogleCloudVisionV1FaceAnnotation > 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<FaceAnn
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 <FaceAnnotation > faces ) {
162- for (FaceAnnotation face : faces ) {
161+ public static void annotateWithFaces (BufferedImage img , List <GoogleCloudVisionV1FaceAnnotation > faces ) {
162+ for (GoogleCloudVisionV1FaceAnnotation 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 , FaceAnnotation face ) {
170+ private static void annotateWithFace (BufferedImage img , GoogleCloudVisionV1FaceAnnotation face ) {
171171 Graphics2D gfx = img .createGraphics ();
172172 Polygon poly = new Polygon ();
173- for (Vertex vertex : face .getFdBoundingPoly ().getVertices ()) {
173+ for (GoogleCloudVisionV1Vertex vertex : face .getFdBoundingPoly ().getVertices ()) {
174174 poly .addPoint (vertex .getX (), vertex .getY ());
175175 }
176176 gfx .setStroke (new BasicStroke (5 ));
0 commit comments