-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from GoogleCloudPlatform/swast-vision
Copy Java samples from cloud-vision repo.
- Loading branch information
Showing
40 changed files
with
2,182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Google Cloud Vision API Java examples | ||
|
||
This directory contains [Cloud Vision API](https://cloud.google.com/vision/) Java samples. | ||
|
||
## Prerequisites | ||
|
||
### Download Maven | ||
|
||
This sample uses the [Apache Maven][maven] build system. Before getting started, be | ||
sure to [download][maven-download] and [install][maven-install] it. When you use | ||
Maven as described here, it will automatically download the needed client | ||
libraries. | ||
|
||
[maven]: https://maven.apache.org | ||
[maven-download]: https://maven.apache.org/download.cgi | ||
[maven-install]: https://maven.apache.org/install.html | ||
|
||
### Setup | ||
|
||
* Create a project with the [Google Cloud Console][cloud-console], and enable | ||
the [Vision API][vision-api]. | ||
* Set up your environment with [Application Default Credentials][adc]. For | ||
example, from the Cloud Console, you might create a service account, | ||
download its json credentials file, then set the appropriate environment | ||
variable: | ||
|
||
```bash | ||
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json | ||
``` | ||
|
||
[cloud-console]: https://console.cloud.google.com | ||
[vision-api]: https://console.cloud.google.com/apis/api/vision.googleapis.com/overview?project=_ | ||
[adc]: https://cloud.google.com/docs/authentication#developer_workflow | ||
|
||
## Samples | ||
|
||
### Label Detection | ||
|
||
This sample annotates an image with labels based on its content. | ||
|
||
- [Java Code](label) | ||
|
||
### Face Detection | ||
|
||
This sample identifies faces within an image. | ||
|
||
- [Quickstart Walkthrough](https://cloud.google.com/vision/docs/face-tutorial) | ||
- [Java Code](face_detection) | ||
|
||
### Landmark Detection Using Google Cloud Storage | ||
|
||
This sample identifies a landmark within an image stored on | ||
Google Cloud Storage. | ||
|
||
- [Documentation and Java Code](landmark_detection) | ||
|
||
### Text Detection Using the Vision API | ||
|
||
This sample uses `TEXT_DETECTION` Vision API requests to build an inverted index | ||
from the stemmed words found in the images, and stores that index in a | ||
[Redis](redis.io) database. The example uses the | ||
[OpenNLP](https://opennlp.apache.org/) library (Open Natural Language | ||
Processing) for finding stopwords and doing stemming. The resulting index can be | ||
queried to find images that match a given set of words, and to list text that | ||
was found in each matching image. | ||
|
||
[Documentation and Java Code](text) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Google Cloud Vision API Java Face Detection example | ||
|
||
## Download Maven | ||
|
||
This sample uses the [Apache Maven][maven] build system. Before getting started, be | ||
sure to [download][maven-download] and [install][maven-install] it. When you use | ||
Maven as described here, it will automatically download the needed client | ||
libraries. | ||
|
||
[maven]: https://maven.apache.org | ||
[maven-download]: https://maven.apache.org/download.cgi | ||
[maven-install]: https://maven.apache.org/install.html | ||
|
||
## Setup | ||
|
||
* Create a project with the [Google Cloud Console][cloud-console], and enable | ||
the [Vision API][vision-api]. | ||
* Set up your environment with [Application Default Credentials][adc]. For | ||
example, from the Cloud Console, you might create a service account, | ||
download its json credentials file, then set the appropriate environment | ||
variable: | ||
|
||
```bash | ||
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json | ||
``` | ||
|
||
[cloud-console]: https://console.cloud.google.com | ||
[vision-api]: https://console.cloud.google.com/apis/api/vision.googleapis.com/overview?project=_ | ||
[adc]: https://cloud.google.com/docs/authentication#developer_workflow | ||
|
||
## Run the sample | ||
|
||
To build and run the sample, run the following from this directory: | ||
|
||
```bash | ||
mvn clean compile assembly:single | ||
java -cp target/vision-face-detection-1.0-SNAPSHOT-jar-with-dependencies.jar com.google.cloud.vision.samples.facedetect.FaceDetectApp data/face.jpg output.jpg | ||
``` | ||
|
||
For more information about face detection see the [Quickstart][quickstart] | ||
guide. | ||
|
||
[quickstart]: https://cloud.google.com/vision/docs/face-tutorial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
I am not an image. Labelling shouldn't work on me. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2016 Google Inc. All Rights Reserved. | ||
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. | ||
--> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<groupId>com.google.cloud.vision.samples</groupId> | ||
<artifactId>vision-face-detection</artifactId> | ||
|
||
<!-- Parent defines shared plugins for linting and unit testing. --> | ||
<parent> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>doc-samples</artifactId> | ||
<version>1.0.0</version> | ||
<relativePath>../..</relativePath> | ||
</parent> | ||
|
||
<dependencies> | ||
<!-- [START dependencies] --> | ||
<dependency> | ||
<groupId>com.google.apis</groupId> | ||
<artifactId>google-api-services-vision</artifactId> | ||
<version>v1-rev2-1.21.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.api-client</groupId> | ||
<artifactId>google-api-client</artifactId> | ||
<version>1.21.0</version> | ||
</dependency> | ||
<!-- [END dependencies] --> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>19.0</version> | ||
</dependency> | ||
|
||
<!-- Test Dependencies --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.truth</groupId> | ||
<artifactId>truth</artifactId> | ||
<version>0.28</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<!-- for checking HTTP response codes --> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<version>3.3</version> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>com.google.cloud.vision.samples.facedetect.FaceDetectApp</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.