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+ */
1416
1517package com .example .vision ;
1618
5658public class Detect {
5759
5860 /**
59- * Detects entities,sentiment and syntax in a document using the Natural Language API.
61+ * Detects entities, sentiment, and syntax in a document using the Vision API.
6062 *
6163 * @throws Exception on errors while closing the client.
6264 * @throws IOException on Input/Output errors.
@@ -75,13 +77,12 @@ public static void argsHelper(String[] args, PrintStream out) throws Exception,
7577 if (args .length < 1 ) {
7678 out .println ("Usage:" );
7779 out .printf (
78- "\t java %s \" <command>\" \" <path-to-image>\" \n "
80+ "\t mvn exec:java -DDetect -Dexec.args= \" <command> <path-to-image>\" \n "
7981 + "Commands:\n "
8082 + "\t faces | labels | landmarks | logos | text | safe-search | properties"
8183 + "| web | web-entities | web-entities-include-geo | crop \n "
8284 + "Path:\n \t A file path (ex: ./resources/wakeupcat.jpg) or a URI for a Cloud Storage "
83- + "resource (gs://...)\n " ,
84- Detect .class .getCanonicalName ());
85+ + "resource (gs://...)\n " );
8586 return ;
8687 }
8788 String command = args [0 ];
@@ -207,9 +208,10 @@ public static void detectFaces(String filePath, PrintStream out) throws Exceptio
207208 }
208209
209210 /**
210- * Detects faces in the specified remote image.
211+ * Detects faces in the specified remote image on Google Cloud Storage .
211212 *
212- * @param gcsPath The path to the remote file to perform face detection on.
213+ * @param gcsPath The path to the remote file on Google Cloud Storage to perform face detection
214+ * on.
213215 * @param out A {@link PrintStream} to write detected features to.
214216 * @throws Exception on errors while closing the client.
215217 * @throws IOException on Input/Output errors.
@@ -287,9 +289,10 @@ public static void detectLabels(String filePath, PrintStream out) throws Excepti
287289 }
288290
289291 /**
290- * Detects labels in the specified remote image.
292+ * Detects labels in the specified remote image on Google Cloud Storage .
291293 *
292- * @param gcsPath The path to the remote file to perform label detection on.
294+ * @param gcsPath The path to the remote file on Google Cloud Storage to perform label detection
295+ * on.
293296 * @param out A {@link PrintStream} to write detected features to.
294297 * @throws Exception on errors while closing the client.
295298 * @throws IOException on Input/Output errors.
@@ -365,16 +368,16 @@ public static void detectLandmarks(String filePath, PrintStream out) throws Exce
365368 /**
366369 * Detects landmarks in the specified URI.
367370 *
368- * @param url The path to the file to perform landmark detection on.
371+ * @param uri The path to the file to perform landmark detection on.
369372 * @param out A {@link PrintStream} to write detected landmarks to.
370373 * @throws Exception on errors while closing the client.
371374 * @throws IOException on Input/Output errors.
372375 */
373- public static void detectLandmarksUrl (String url , PrintStream out ) throws Exception ,
376+ public static void detectLandmarksUrl (String uri , PrintStream out ) throws Exception ,
374377 IOException {
375378 List <AnnotateImageRequest > requests = new ArrayList <>();
376379
377- ImageSource imgSource = ImageSource .newBuilder ().setImageUri (url ).build ();
380+ ImageSource imgSource = ImageSource .newBuilder ().setImageUri (uri ).build ();
378381 Image img = Image .newBuilder ().setSource (imgSource ).build ();
379382 Feature feat = Feature .newBuilder ().setType (Type .LANDMARK_DETECTION ).build ();
380383 AnnotateImageRequest request =
@@ -401,9 +404,10 @@ public static void detectLandmarksUrl(String url, PrintStream out) throws Except
401404 }
402405
403406 /**
404- * Detects landmarks in the specified remote image .
407+ * Detects landmarks in the specified remote imageon Google Cloud Storage .
405408 *
406- * @param gcsPath The path to the remote file to perform landmark detection on.
409+ * @param gcsPath The path to the remote file on Google Cloud Storage to perform landmark
410+ * detection on.
407411 * @param out A {@link PrintStream} to write detected landmarks to.
408412 * @throws Exception on errors while closing the client.
409413 * @throws IOException on Input/Output errors.
@@ -476,9 +480,10 @@ public static void detectLogos(String filePath, PrintStream out) throws Exceptio
476480 }
477481
478482 /**
479- * Detects logos in the specified remote image.
483+ * Detects logos in the specified remote image on Google Cloud Storage .
480484 *
481- * @param gcsPath The path to the remote file to perform logo detection on.
485+ * @param gcsPath The path to the remote file on Google Cloud Storage to perform logo detection
486+ * on.
482487 * @param out A {@link PrintStream} to write detected logos to.
483488 * @throws Exception on errors while closing the client.
484489 * @throws IOException on Input/Output errors.
@@ -551,9 +556,9 @@ public static void detectText(String filePath, PrintStream out) throws Exception
551556 }
552557
553558 /**
554- * Detects text in the specified remote image.
559+ * Detects text in the specified remote image on Google Cloud Storage .
555560 *
556- * @param gcsPath The path to the remote file to detect text in.
561+ * @param gcsPath The path to the remote file on Google Cloud Storage to detect text in.
557562 * @param out A {@link PrintStream} to write the detected text to.
558563 * @throws Exception on errors while closing the client.
559564 * @throws IOException on Input/Output errors.
@@ -632,9 +637,10 @@ public static void detectProperties(String filePath, PrintStream out) throws Exc
632637 }
633638
634639 /**
635- * Detects image properties such as color frequency from the specified remote image.
640+ * Detects image properties such as color frequency from the specified remote image on Google
641+ * Cloud Storage.
636642 *
637- * @param gcsPath The path to the remote file to detect properties on.
643+ * @param gcsPath The path to the remote file on Google Cloud Storage to detect properties on.
638644 * @param out A {@link PrintStream} to write
639645 * @throws Exception on errors while closing the client.
640646 * @throws IOException on Input/Output errors.
@@ -721,9 +727,10 @@ public static void detectSafeSearch(String filePath, PrintStream out) throws Exc
721727
722728 // [START vision_detect_safe_search_uri]
723729 /**
724- * Detects whether the specified remote image has features you would want to moderate.
730+ * Detects whether the specified image on Google Cloud Storage has features you would want
731+ * to moderate.
725732 *
726- * @param gcsPath The path to the remote file to detect safe-search on.
733+ * @param gcsPath The path to the remote file on Google Cloud Storage to detect safe-search on.
727734 * @param out A {@link PrintStream} to write the results to.
728735 * @throws Exception on errors while closing the client.
729736 * @throws IOException on Input/Output errors.
@@ -830,9 +837,10 @@ public static void detectWebDetections(String filePath, PrintStream out) throws
830837
831838 // [START vision_detect_web_uri]
832839 /**
833- * Detects whether the specified remote image has features you would want to moderate.
840+ * Detects whether the remote image on Google Cloud Storage has features you would want to
841+ * moderate.
834842 *
835- * @param gcsPath The path to the remote file to detect web annotations.
843+ * @param gcsPath The path to the remote on Google Cloud Storage file to detect web annotations.
836844 * @param out A {@link PrintStream} to write the results to.
837845 * @throws Exception on errors while closing the client.
838846 * @throws IOException on Input/Output errors.
@@ -929,8 +937,8 @@ public static void detectWebEntities(String filePath, PrintStream out) throws Ex
929937 }
930938
931939 /**
932- * Find web entities given the uri to an image .
933- * @param gcsPath The path to the remote file to detect web entities.
940+ * Find web entities given the remote image on Google Cloud Storage .
941+ * @param gcsPath The path to the remote file on Google Cloud Storage to detect web entities.
934942 * @param out A {@link PrintStream} to write the results to.
935943 * @throws Exception on errors while closing the client.
936944 * @throws IOException on Input/Output errors.
@@ -1016,8 +1024,9 @@ public static void detectWebEntitiesIncludeGeoResults(String filePath, PrintStre
10161024
10171025 // [START vision_web_entities_include_geo_results_uri]
10181026 /**
1019- * Find web entities given the uri to an image.
1020- * @param gcsPath The path to the remote file to detect web entities with geo results.
1027+ * Find web entities given the remote image on Google Cloud Storage.
1028+ * @param gcsPath The path to the remote file on Google Cloud Storage to detect web entities with
1029+ * geo results.
10211030 * @param out A {@link PrintStream} to write the results to.
10221031 * @throws Exception on errors while closing the client.
10231032 * @throws IOException on Input/Output errors.
@@ -1104,9 +1113,9 @@ public static void detectCropHints(String filePath, PrintStream out) throws Exce
11041113 }
11051114
11061115 /**
1107- * Suggests a region to crop to for a remote file.
1116+ * Suggests a region to crop to for a remote file on Google Cloud Storage .
11081117 *
1109- * @param gcsPath The path to the remote file to detect safe-search on.
1118+ * @param gcsPath The path to the remote file on Google Cloud Storage to detect safe-search on.
11101119 * @param out A {@link PrintStream} to write the results to.
11111120 * @throws Exception on errors while closing the client.
11121121 * @throws IOException on Input/Output errors.
@@ -1208,9 +1217,9 @@ public static void detectDocumentText(String filePath, PrintStream out) throws E
12081217
12091218 // [START vision_detect_document_uri]
12101219 /**
1211- * Performs document text detection on a local image file .
1220+ * Performs document text detection on a remote image on Google Cloud Storage .
12121221 *
1213- * @param gcsPath The path to the remote file to detect document text on.
1222+ * @param gcsPath The path to the remote file on Google Cloud Storage to detect document text on.
12141223 * @param out A {@link PrintStream} to write the results to.
12151224 * @throws Exception on errors while closing the client.
12161225 * @throws IOException on Input/Output errors.
@@ -1268,4 +1277,4 @@ public static void detectDocumentTextGcs(String gcsPath, PrintStream out) throws
12681277 }
12691278 }
12701279 // [END vision_detect_document_uri]
1271- }
1280+ }
0 commit comments