Skip to content

Commit

Permalink
Merge pull request #228 from GoogleCloudPlatform/swast-vision
Browse files Browse the repository at this point in the history
Copy Java samples from cloud-vision repo.
  • Loading branch information
tswast committed May 5, 2016
2 parents 7fc325e + 5fa501d commit b22eabe
Show file tree
Hide file tree
Showing 40 changed files with 2,182 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ service-account.json
.project
.classpath
.settings

# vim
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
Session.vim
.netrwhist
*~
tags
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
<module>storage/xml-api/serviceaccount-appengine-sample</module>
<module>taskqueue/deferred</module>
<module>unittests</module>
<module>vision/face-detection</module>
<module>vision/label</module>
<module>vision/landmark-detection</module>
<module>vision/text</module>
</modules>

<dependencyManagement>
Expand Down
68 changes: 68 additions & 0 deletions vision/README.md
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)

1 change: 1 addition & 0 deletions vision/face-detection/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output.jpg
43 changes: 43 additions & 0 deletions vision/face-detection/README.md
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
1 change: 1 addition & 0 deletions vision/face-detection/data/bad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am not an image. Labelling shouldn't work on me.
Binary file added vision/face-detection/data/face.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions vision/face-detection/pom.xml
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>
Loading

0 comments on commit b22eabe

Please sign in to comment.