Skip to content

Commit

Permalink
samples: Vision v1p1beta1 samples (#951)
Browse files Browse the repository at this point in the history
* Copy initial files over to v1p1beta1 directory

* Add Java vision v1p1beta1 samples

* Update beta/ cloud-client/ directories

* Update README
  • Loading branch information
nnegrey authored and chingor13 committed Aug 13, 2020
1 parent e07dcd7 commit e087b28
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
96 changes: 48 additions & 48 deletions vision/snippets/src/main/java/com/example/vision/Detect.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
/**
* Copyright 2017, Google, Inc.
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* <p>http://www.apache.org/licenses/LICENSE-2.0
*
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
Copyright 2017, Google, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.example.vision;

import com.google.cloud.vision.v1.AnnotateImageRequest;
Expand Down Expand Up @@ -50,7 +53,7 @@
public class Detect {

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

/**
* Constructs a {@link Detect} which connects to the Cloud Vision API.
*
* @param client The Vision API client.
*/
public Detect() {
}

/**
* Detects faces in the specified local image.
*
Expand Down Expand Up @@ -198,9 +192,10 @@ public static void detectFaces(String filePath, PrintStream out) throws Exceptio
}

/**
* Detects faces in the specified remote image.
* Detects faces in the specified remote image on Google Cloud Storage.
*
* @param gcsPath The path to the remote file to perform face detection on.
* @param gcsPath The path to the remote file on Google Cloud Storage to perform face detection
* on.
* @param out A {@link PrintStream} to write detected features to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
Expand Down Expand Up @@ -278,9 +273,10 @@ public static void detectLabels(String filePath, PrintStream out) throws Excepti
}

/**
* Detects labels in the specified remote image.
* Detects labels in the specified remote image on Google Cloud Storage.
*
* @param gcsPath The path to the remote file to perform label detection on.
* @param gcsPath The path to the remote file on Google Cloud Storage to perform label detection
* on.
* @param out A {@link PrintStream} to write detected features to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
Expand Down Expand Up @@ -356,16 +352,16 @@ public static void detectLandmarks(String filePath, PrintStream out) throws Exce
/**
* Detects landmarks in the specified URI.
*
* @param url The path to the file to perform landmark detection on.
* @param uri The path to the file to perform landmark detection on.
* @param out A {@link PrintStream} to write detected landmarks to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
*/
public static void detectLandmarksUrl(String url, PrintStream out) throws Exception,
public static void detectLandmarksUrl(String uri, PrintStream out) throws Exception,
IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();

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

/**
* Detects landmarks in the specified remote image.
* Detects landmarks in the specified remote image on Google Cloud Storage.
*
* @param gcsPath The path to the remote file to perform landmark detection on.
* @param gcsPath The path to the remote file on Google Cloud Storage to perform landmark
* detection on.
* @param out A {@link PrintStream} to write detected landmarks to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
Expand Down Expand Up @@ -467,9 +464,10 @@ public static void detectLogos(String filePath, PrintStream out) throws Exceptio
}

/**
* Detects logos in the specified remote image.
* Detects logos in the specified remote image on Google Cloud Storage.
*
* @param gcsPath The path to the remote file to perform logo detection on.
* @param gcsPath The path to the remote file on Google Cloud Storage to perform logo detection
* on.
* @param out A {@link PrintStream} to write detected logos to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
Expand Down Expand Up @@ -542,9 +540,9 @@ public static void detectText(String filePath, PrintStream out) throws Exception
}

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

/**
* Detects image properties such as color frequency from the specified remote image.
* Detects image properties such as color frequency from the specified remote image on Google
* Cloud Storage.
*
* @param gcsPath The path to the remote file to detect properties on.
* @param gcsPath The path to the remote file on Google Cloud Storage to detect properties on.
* @param out A {@link PrintStream} to write
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
Expand Down Expand Up @@ -708,9 +707,10 @@ public static void detectSafeSearch(String filePath, PrintStream out) throws Exc
}

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

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

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

/**
* Performs document text detection on a local image file.
* Performs document text detection on a local image file on Google Cloud Storage.
*
* @param gcsPath The path to the remote file to detect document text on.
* @param gcsPath The path to the remote file on Google Cloud Storage to detect document text on.
* @param out A {@link PrintStream} to write the results to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016, Google, Inc.
Copyright 2017, Google, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down

0 comments on commit e087b28

Please sign in to comment.