Skip to content

Commit 4f74c7d

Browse files
authored
Merge pull request #2224 from daspecster/vision-face-detection
Add Vision API Face detection.
2 parents 891b060 + 7520c5c commit 4f74c7d

15 files changed

Lines changed: 1839 additions & 1093 deletions

File tree

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
vision-client
152152
vision-image
153153
vision-feature
154+
vision-face
154155

155156
.. toctree::
156157
:maxdepth: 0

docs/vision-face.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Vision Face
2+
===========
3+
4+
Face
5+
~~~~
6+
7+
.. automodule:: google.cloud.vision.face
8+
:members:
9+
:undoc-members:
10+
:show-inheritance:

docs/vision-image.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ Image
88
:members:
99
:undoc-members:
1010
:show-inheritance:
11+
12+
Geometry
13+
~~~~~~~~
14+
15+
.. automodule:: google.cloud.vision.geometry
16+
:members:
17+
:undoc-members:
18+
:show-inheritance:
19+
20+
Likelihood
21+
~~~~~~~~~~
22+
23+
.. automodule:: google.cloud.vision.likelihood
24+
:members:
25+
:undoc-members:
26+
:show-inheritance:

docs/vision-usage.rst

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,29 @@ Annotate a single image
3838

3939
.. code-block:: python
4040
41+
>>> import io
4142
>>> from google.cloud import vision
4243
>>> client = vision.Client()
43-
>>> image = client.image('./image.png')
44+
>>> with io.open('./image.png', 'rb') as image_file:
45+
... image = client.image(content=image_file.read())
4446
>>> faces = image.detect_faces(limit=10)
47+
>>> faces[0].landmarks.left_eye.position.x_coordinate
48+
... 1004.8003
4549
4650
Annotate multiple images
4751
~~~~~~~~~~~~~~~~~~~~~~~~
4852

4953
.. code-block:: python
5054
51-
>>> first_image = client.image('./image.jpg')
52-
>>> second_image = client.image('gs://my-storage-bucket/image2.jpg')
53-
>>> with client.batch():
54-
... labels = first_image.detect_labels()
55-
... faces = second_image.detect_faces(limit=10)
56-
57-
or
58-
59-
.. code-block:: python
60-
61-
>>> images = []
62-
>>> images.append(client.image('./image.jpg'))
63-
>>> images.append(client.image('gs://my-storage-bucket/image2.jpg'))
64-
>>> faces = client.detect_faces_multi(images, limit=10)
55+
>>> import io
56+
>>> from gcloud import vision
57+
>>> client = vision.Client()
58+
>>> with io.open('./image.png', 'rb') as image_file:
59+
... image_one = client.image(content=image_file.read())
60+
>>> image_two = client.image(source_uri='gs://my-storage-bucket/image.jpg')
61+
>>> with client.batch():
62+
... labels = image_one.detect_labels()
63+
... faces = image_two.detect_faces(limit=10)
6564
6665
No results returned
6766
~~~~~~~~~~~~~~~~~~~
@@ -72,7 +71,7 @@ Failing annotations return no results for the feature type requested.
7271
7372
>>> from google.cloud import vision
7473
>>> client = vision.Client()
75-
>>> image = client.image('./image.jpg')
74+
>>> image = client.image(source_uri='gs://my-storage-bucket/image.jpg')
7675
>>> logos = image.detect_logos(limit=10)
7776
>>> logos
7877
[]
@@ -86,9 +85,13 @@ You can call the detection method manually.
8685
.. code-block:: python
8786
8887
>>> from google.cloud import vision
88+
>>> from google.cloud.vision.image import Feature
89+
>>> from google.cloud.vision.image import FeatureTypes
8990
>>> client = vision.Client()
90-
>>> image = client.image('gs://my-test-bucket/image.jpg')
91-
>>> faces = image.detect(type=vision.FACE_DETECTION, limit=10)
91+
>>> image = client.image(source_uri='gs://my-test-bucket/image.jpg')
92+
>>> features = [Feature(FeatureTypes.FACE_DETECTION, 5),
93+
... Feature(FeatureTypes.LOGO_DETECTION, 3)]
94+
>>> annotations = image.detect(features)
9295
9396
Face Detection
9497
~~~~~~~~~~~~~~
@@ -102,11 +105,11 @@ see: https://cloud.google.com/vision/reference/rest/v1/images/annotate#type_1
102105
103106
>>> from google.cloud import vision
104107
>>> client = vision.Client()
105-
>>> image = client.image('./image.jpg')
108+
>>> image = client.image(source_uri='gs://my-test-bucket/image.jpg')
106109
>>> faces = image.detect_faces(limit=10)
107-
>>> faces[0].landmarks[0].type
110+
>>> faces[0].landmarks.left_eye.landmark_type
108111
'LEFT_EYE'
109-
>>> faces[0].landmarks[0].position.x
112+
>>> faces[0].landmarks.left_eye.position.x_coordinate
110113
1301.2404
111114
>>> faces[0].detection_confidence
112115
0.9863683
@@ -128,7 +131,7 @@ attempt to identify those objects.
128131
129132
>>> from google.cloud import vision
130133
>>> client = vision.Client()
131-
>>> image = client.image('./image.jpg')
134+
>>> image = client.image(source_uri='gs://my-storage-bucket/image.jpg')
132135
>>> labels = image.detect_labels(limit=3)
133136
>>> labels[0].description
134137
'automobile'
@@ -155,9 +158,9 @@ locations if available.
155158
-33.857123
156159
>>> landmarks[0].locations[0].longitude
157160
151.213921
158-
>>> landmarks[0].bounding_poly.vertices[0].x
161+
>>> landmarks[0].bounding_poly.vertices[0].x_coordinate
159162
78
160-
>>> landmarks[0].bounding_poly.vertices[0].y
163+
>>> landmarks[0].bounding_poly.vertices[0].y_coordinate
161164
162
162165
163166
Logo Detection
@@ -175,9 +178,9 @@ Google Vision can also attempt to detect company and brand logos in images.
175178
'Google'
176179
>>> logos[0].score
177180
0.9795432
178-
>>> logos[0].bounding_poly.vertices[0].x
181+
>>> logos[0].bounding_poly.vertices[0].x_coordinate
179182
78
180-
>>> logos[0].bounding_poly.vertices[0].y
183+
>>> logos[0].bounding_poly.vertices[0].y_coordinate
181184
62
182185
183186
Safe Search Detection

google/cloud/vision/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
# limitations under the License.
1414

1515
"""Google Cloud Vision API package."""
16+
from google.cloud.vision.client import Client

0 commit comments

Comments
 (0)