@@ -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
0 commit comments