Skip to content

Commit b22eabe

Browse files
committed
Merge pull request GoogleCloudPlatform#228 from GoogleCloudPlatform/swast-vision
Copy Java samples from cloud-vision repo.
2 parents 7fc325e + 5fa501d commit b22eabe

File tree

40 files changed

+2182
-0
lines changed

40 files changed

+2182
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ service-account.json
3535
.project
3636
.classpath
3737
.settings
38+
39+
# vim
40+
[._]*.s[a-w][a-z]
41+
[._]s[a-w][a-z]
42+
Session.vim
43+
.netrwhist
44+
*~
45+
tags

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@
101101
<module>storage/xml-api/serviceaccount-appengine-sample</module>
102102
<module>taskqueue/deferred</module>
103103
<module>unittests</module>
104+
<module>vision/face-detection</module>
105+
<module>vision/label</module>
106+
<module>vision/landmark-detection</module>
107+
<module>vision/text</module>
104108
</modules>
105109

106110
<dependencyManagement>

vision/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Google Cloud Vision API Java examples
2+
3+
This directory contains [Cloud Vision API](https://cloud.google.com/vision/) Java samples.
4+
5+
## Prerequisites
6+
7+
### Download Maven
8+
9+
This sample uses the [Apache Maven][maven] build system. Before getting started, be
10+
sure to [download][maven-download] and [install][maven-install] it. When you use
11+
Maven as described here, it will automatically download the needed client
12+
libraries.
13+
14+
[maven]: https://maven.apache.org
15+
[maven-download]: https://maven.apache.org/download.cgi
16+
[maven-install]: https://maven.apache.org/install.html
17+
18+
### Setup
19+
20+
* Create a project with the [Google Cloud Console][cloud-console], and enable
21+
the [Vision API][vision-api].
22+
* Set up your environment with [Application Default Credentials][adc]. For
23+
example, from the Cloud Console, you might create a service account,
24+
download its json credentials file, then set the appropriate environment
25+
variable:
26+
27+
```bash
28+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
29+
```
30+
31+
[cloud-console]: https://console.cloud.google.com
32+
[vision-api]: https://console.cloud.google.com/apis/api/vision.googleapis.com/overview?project=_
33+
[adc]: https://cloud.google.com/docs/authentication#developer_workflow
34+
35+
## Samples
36+
37+
### Label Detection
38+
39+
This sample annotates an image with labels based on its content.
40+
41+
- [Java Code](label)
42+
43+
### Face Detection
44+
45+
This sample identifies faces within an image.
46+
47+
- [Quickstart Walkthrough](https://cloud.google.com/vision/docs/face-tutorial)
48+
- [Java Code](face_detection)
49+
50+
### Landmark Detection Using Google Cloud Storage
51+
52+
This sample identifies a landmark within an image stored on
53+
Google Cloud Storage.
54+
55+
- [Documentation and Java Code](landmark_detection)
56+
57+
### Text Detection Using the Vision API
58+
59+
This sample uses `TEXT_DETECTION` Vision API requests to build an inverted index
60+
from the stemmed words found in the images, and stores that index in a
61+
[Redis](redis.io) database. The example uses the
62+
[OpenNLP](https://opennlp.apache.org/) library (Open Natural Language
63+
Processing) for finding stopwords and doing stemming. The resulting index can be
64+
queried to find images that match a given set of words, and to list text that
65+
was found in each matching image.
66+
67+
[Documentation and Java Code](text)
68+

vision/face-detection/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output.jpg

vision/face-detection/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Google Cloud Vision API Java Face Detection example
2+
3+
## Download Maven
4+
5+
This sample uses the [Apache Maven][maven] build system. Before getting started, be
6+
sure to [download][maven-download] and [install][maven-install] it. When you use
7+
Maven as described here, it will automatically download the needed client
8+
libraries.
9+
10+
[maven]: https://maven.apache.org
11+
[maven-download]: https://maven.apache.org/download.cgi
12+
[maven-install]: https://maven.apache.org/install.html
13+
14+
## Setup
15+
16+
* Create a project with the [Google Cloud Console][cloud-console], and enable
17+
the [Vision API][vision-api].
18+
* Set up your environment with [Application Default Credentials][adc]. For
19+
example, from the Cloud Console, you might create a service account,
20+
download its json credentials file, then set the appropriate environment
21+
variable:
22+
23+
```bash
24+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
25+
```
26+
27+
[cloud-console]: https://console.cloud.google.com
28+
[vision-api]: https://console.cloud.google.com/apis/api/vision.googleapis.com/overview?project=_
29+
[adc]: https://cloud.google.com/docs/authentication#developer_workflow
30+
31+
## Run the sample
32+
33+
To build and run the sample, run the following from this directory:
34+
35+
```bash
36+
mvn clean compile assembly:single
37+
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
38+
```
39+
40+
For more information about face detection see the [Quickstart][quickstart]
41+
guide.
42+
43+
[quickstart]: https://cloud.google.com/vision/docs/face-tutorial

vision/face-detection/data/bad.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I am not an image. Labelling shouldn't work on me.

vision/face-detection/data/face.jpg

66.5 KB
Loading

vision/face-detection/pom.xml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2016 Google Inc. All Rights Reserved.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project>
18+
<modelVersion>4.0.0</modelVersion>
19+
<packaging>jar</packaging>
20+
<version>1.0-SNAPSHOT</version>
21+
<groupId>com.google.cloud.vision.samples</groupId>
22+
<artifactId>vision-face-detection</artifactId>
23+
24+
<!-- Parent defines shared plugins for linting and unit testing. -->
25+
<parent>
26+
<groupId>com.google.cloud</groupId>
27+
<artifactId>doc-samples</artifactId>
28+
<version>1.0.0</version>
29+
<relativePath>../..</relativePath>
30+
</parent>
31+
32+
<dependencies>
33+
<!-- [START dependencies] -->
34+
<dependency>
35+
<groupId>com.google.apis</groupId>
36+
<artifactId>google-api-services-vision</artifactId>
37+
<version>v1-rev2-1.21.0</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.google.api-client</groupId>
41+
<artifactId>google-api-client</artifactId>
42+
<version>1.21.0</version>
43+
</dependency>
44+
<!-- [END dependencies] -->
45+
<dependency>
46+
<groupId>com.google.guava</groupId>
47+
<artifactId>guava</artifactId>
48+
<version>19.0</version>
49+
</dependency>
50+
51+
<!-- Test Dependencies -->
52+
<dependency>
53+
<groupId>junit</groupId>
54+
<artifactId>junit</artifactId>
55+
<version>4.12</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>com.google.truth</groupId>
60+
<artifactId>truth</artifactId>
61+
<version>0.28</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<!-- for checking HTTP response codes -->
66+
<groupId>javax.servlet</groupId>
67+
<artifactId>javax.servlet-api</artifactId>
68+
<version>3.1.0</version>
69+
<scope>test</scope>
70+
</dependency>
71+
</dependencies>
72+
<build>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<version>3.3</version>
77+
<artifactId>maven-compiler-plugin</artifactId>
78+
<configuration>
79+
<source>1.7</source>
80+
<target>1.7</target>
81+
</configuration>
82+
</plugin>
83+
<plugin>
84+
<artifactId>maven-assembly-plugin</artifactId>
85+
<configuration>
86+
<archive>
87+
<manifest>
88+
<mainClass>com.google.cloud.vision.samples.facedetect.FaceDetectApp</mainClass>
89+
</manifest>
90+
</archive>
91+
<descriptorRefs>
92+
<descriptorRef>jar-with-dependencies</descriptorRef>
93+
</descriptorRefs>
94+
</configuration>
95+
</plugin>
96+
</plugins>
97+
</build>
98+
</project>

0 commit comments

Comments
 (0)