Skip to content

Commit e087b28

Browse files
nnegreychingor13
authored andcommitted
samples: Vision v1p1beta1 samples (#951)
* Copy initial files over to v1p1beta1 directory * Add Java vision v1p1beta1 samples * Update beta/ cloud-client/ directories * Update README
1 parent e07dcd7 commit e087b28

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

vision/snippets/src/main/java/com/example/vision/Detect.java

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
/**
2-
* Copyright 2017, Google, Inc.
3-
*
4-
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5-
* except in compliance with the License. You may obtain a copy of the License at
6-
*
7-
* <p>http://www.apache.org/licenses/LICENSE-2.0
8-
*
9-
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
10-
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11-
* express or implied. See the License for the specific language governing permissions and
12-
* limitations under the License.
13-
*/
1+
/*
2+
Copyright 2017, Google, Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
1417
package com.example.vision;
1518

1619
import com.google.cloud.vision.v1.AnnotateImageRequest;
@@ -50,7 +53,7 @@
5053
public class Detect {
5154

5255
/**
53-
* Detects entities,sentiment and syntax in a document using the Natural Language API.
56+
* Detects entities,sentiment and syntax in a document using the Vision API.
5457
*
5558
* @throws Exception on errors while closing the client.
5659
* @throws IOException on Input/Output errors.
@@ -69,13 +72,12 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception,
6972
if (args.length < 1) {
7073
out.println("Usage:");
7174
out.printf(
72-
"\tjava %s \"<command>\" \"<path-to-image>\"\n"
75+
"\tmvn exec:java -DDetect -Dexec.args=\"<command> <path-to-image>\"\n"
7376
+ "Commands:\n"
7477
+ "\tfaces | labels | landmarks | logos | text | safe-search | properties"
7578
+ "| web | crop \n"
7679
+ "Path:\n\tA file path (ex: ./resources/wakeupcat.jpg) or a URI for a Cloud Storage "
77-
+ "resource (gs://...)\n",
78-
Detect.class.getCanonicalName());
80+
+ "resource (gs://...)\n");
7981
return;
8082
}
8183
String command = args[0];
@@ -147,14 +149,6 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception,
147149
}
148150
}
149151

150-
/**
151-
* Constructs a {@link Detect} which connects to the Cloud Vision API.
152-
*
153-
* @param client The Vision API client.
154-
*/
155-
public Detect() {
156-
}
157-
158152
/**
159153
* Detects faces in the specified local image.
160154
*
@@ -198,9 +192,10 @@ public static void detectFaces(String filePath, PrintStream out) throws Exceptio
198192
}
199193

200194
/**
201-
* Detects faces in the specified remote image.
195+
* Detects faces in the specified remote image on Google Cloud Storage.
202196
*
203-
* @param gcsPath The path to the remote file to perform face detection on.
197+
* @param gcsPath The path to the remote file on Google Cloud Storage to perform face detection
198+
* on.
204199
* @param out A {@link PrintStream} to write detected features to.
205200
* @throws Exception on errors while closing the client.
206201
* @throws IOException on Input/Output errors.
@@ -278,9 +273,10 @@ public static void detectLabels(String filePath, PrintStream out) throws Excepti
278273
}
279274

280275
/**
281-
* Detects labels in the specified remote image.
276+
* Detects labels in the specified remote image on Google Cloud Storage.
282277
*
283-
* @param gcsPath The path to the remote file to perform label detection on.
278+
* @param gcsPath The path to the remote file on Google Cloud Storage to perform label detection
279+
* on.
284280
* @param out A {@link PrintStream} to write detected features to.
285281
* @throws Exception on errors while closing the client.
286282
* @throws IOException on Input/Output errors.
@@ -356,16 +352,16 @@ public static void detectLandmarks(String filePath, PrintStream out) throws Exce
356352
/**
357353
* Detects landmarks in the specified URI.
358354
*
359-
* @param url The path to the file to perform landmark detection on.
355+
* @param uri The path to the file to perform landmark detection on.
360356
* @param out A {@link PrintStream} to write detected landmarks to.
361357
* @throws Exception on errors while closing the client.
362358
* @throws IOException on Input/Output errors.
363359
*/
364-
public static void detectLandmarksUrl(String url, PrintStream out) throws Exception,
360+
public static void detectLandmarksUrl(String uri, PrintStream out) throws Exception,
365361
IOException {
366362
List<AnnotateImageRequest> requests = new ArrayList<>();
367363

368-
ImageSource imgSource = ImageSource.newBuilder().setImageUri(url).build();
364+
ImageSource imgSource = ImageSource.newBuilder().setImageUri(uri).build();
369365
Image img = Image.newBuilder().setSource(imgSource).build();
370366
Feature feat = Feature.newBuilder().setType(Type.LANDMARK_DETECTION).build();
371367
AnnotateImageRequest request =
@@ -392,9 +388,10 @@ public static void detectLandmarksUrl(String url, PrintStream out) throws Except
392388
}
393389

394390
/**
395-
* Detects landmarks in the specified remote image.
391+
* Detects landmarks in the specified remote image on Google Cloud Storage.
396392
*
397-
* @param gcsPath The path to the remote file to perform landmark detection on.
393+
* @param gcsPath The path to the remote file on Google Cloud Storage to perform landmark
394+
* detection on.
398395
* @param out A {@link PrintStream} to write detected landmarks to.
399396
* @throws Exception on errors while closing the client.
400397
* @throws IOException on Input/Output errors.
@@ -467,9 +464,10 @@ public static void detectLogos(String filePath, PrintStream out) throws Exceptio
467464
}
468465

469466
/**
470-
* Detects logos in the specified remote image.
467+
* Detects logos in the specified remote image on Google Cloud Storage.
471468
*
472-
* @param gcsPath The path to the remote file to perform logo detection on.
469+
* @param gcsPath The path to the remote file on Google Cloud Storage to perform logo detection
470+
* on.
473471
* @param out A {@link PrintStream} to write detected logos to.
474472
* @throws Exception on errors while closing the client.
475473
* @throws IOException on Input/Output errors.
@@ -542,9 +540,9 @@ public static void detectText(String filePath, PrintStream out) throws Exception
542540
}
543541

544542
/**
545-
* Detects text in the specified remote image.
543+
* Detects text in the specified remote image on Google Cloud Storage.
546544
*
547-
* @param gcsPath The path to the remote file to detect text in.
545+
* @param gcsPath The path to the remote file on Google Cloud Storage to detect text in.
548546
* @param out A {@link PrintStream} to write the detected text to.
549547
* @throws Exception on errors while closing the client.
550548
* @throws IOException on Input/Output errors.
@@ -623,9 +621,10 @@ public static void detectProperties(String filePath, PrintStream out) throws Exc
623621
}
624622

625623
/**
626-
* Detects image properties such as color frequency from the specified remote image.
624+
* Detects image properties such as color frequency from the specified remote image on Google
625+
* Cloud Storage.
627626
*
628-
* @param gcsPath The path to the remote file to detect properties on.
627+
* @param gcsPath The path to the remote file on Google Cloud Storage to detect properties on.
629628
* @param out A {@link PrintStream} to write
630629
* @throws Exception on errors while closing the client.
631630
* @throws IOException on Input/Output errors.
@@ -708,9 +707,10 @@ public static void detectSafeSearch(String filePath, PrintStream out) throws Exc
708707
}
709708

710709
/**
711-
* Detects whether the specified remote image has features you would want to moderate.
710+
* Detects whether the specified remote image on Google Cloud Storage has features you would want
711+
* to moderate.
712712
*
713-
* @param gcsPath The path to the remote file to detect safe-search on.
713+
* @param gcsPath The path to the remote file on Google Cloud Storage to detect safe-search on.
714714
* @param out A {@link PrintStream} to write the results to.
715715
* @throws Exception on errors while closing the client.
716716
* @throws IOException on Input/Output errors.
@@ -805,9 +805,9 @@ public static void detectWebDetections(String filePath, PrintStream out) throws
805805
}
806806

807807
/**
808-
* Detects whether the specified remote image has features you would want to moderate.
808+
* Detects whether the specified remote image on Google Cloud Storage has features you would want to moderate.
809809
*
810-
* @param gcsPath The path to the remote file to detect safe-search on.
810+
* @param gcsPath The path to the remote file on Google Cloud Storage to detect safe-search on.
811811
* @param out A {@link PrintStream} to write the results to.
812812
* @throws Exception on errors while closing the client.
813813
* @throws IOException on Input/Output errors.
@@ -899,9 +899,9 @@ public static void detectCropHints(String filePath, PrintStream out) throws Exce
899899
}
900900

901901
/**
902-
* Suggests a region to crop to for a remote file.
902+
* Suggests a region to crop to for a remote file on Google Cloud Storage.
903903
*
904-
* @param gcsPath The path to the remote file to detect safe-search on.
904+
* @param gcsPath The path to the remote file on Google Cloud Storage to detect safe-search on.
905905
* @param out A {@link PrintStream} to write the results to.
906906
* @throws Exception on errors while closing the client.
907907
* @throws IOException on Input/Output errors.
@@ -996,9 +996,9 @@ public static void detectDocumentText(String filePath, PrintStream out) throws E
996996
}
997997

998998
/**
999-
* Performs document text detection on a local image file.
999+
* Performs document text detection on a local image file on Google Cloud Storage.
10001000
*
1001-
* @param gcsPath The path to the remote file to detect document text on.
1001+
* @param gcsPath The path to the remote file on Google Cloud Storage to detect document text on.
10021002
* @param out A {@link PrintStream} to write the results to.
10031003
* @throws Exception on errors while closing the client.
10041004
* @throws IOException on Input/Output errors.

vision/snippets/src/test/java/com/example/vision/DetectIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2016, Google, Inc.
2+
Copyright 2017, Google, Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)