From 4ca8a849b3296fe555f90eb5ab512d68135dcfae Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 11:31:23 -0700 Subject: [PATCH 01/36] Migrate quickstart to gapic --- vision/cloud-client/quickstart/quickstart.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/quickstart/quickstart.py b/vision/cloud-client/quickstart/quickstart.py index 0453587fe9e..fa0dcb30b4d 100644 --- a/vision/cloud-client/quickstart/quickstart.py +++ b/vision/cloud-client/quickstart/quickstart.py @@ -21,10 +21,11 @@ def run_quickstart(): import os # Imports the Google Cloud client library - from google.cloud import vision + from google.cloud.vision import ImageAnnotatorClient + from google.cloud.vision import types # Instantiates a client - vision_client = vision.Client() + client = ImageAnnotatorClient() # The name of the image file to annotate file_name = os.path.join( @@ -34,11 +35,12 @@ def run_quickstart(): # Loads the image into memory with io.open(file_name, 'rb') as image_file: content = image_file.read() - image = vision_client.image( + image = types.Image( content=content) # Performs label detection on the image file - labels = image.detect_labels() + response = client.label_detection(image=image) + labels = response.label_annotations print('Labels:') for label in labels: From 91b07c0ee6f4761b4cd74532792b8fc8d89749fa Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 12:02:44 -0700 Subject: [PATCH 02/36] formatting --- vision/cloud-client/quickstart/quickstart.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vision/cloud-client/quickstart/quickstart.py b/vision/cloud-client/quickstart/quickstart.py index fa0dcb30b4d..08c68bdaec2 100644 --- a/vision/cloud-client/quickstart/quickstart.py +++ b/vision/cloud-client/quickstart/quickstart.py @@ -35,8 +35,7 @@ def run_quickstart(): # Loads the image into memory with io.open(file_name, 'rb') as image_file: content = image_file.read() - image = types.Image( - content=content) + image = types.Image(content=content) # Performs label detection on the image file response = client.label_detection(image=image) From 3cd44bbfc71663b853dced9d62522bc344588e21 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 12:34:09 -0700 Subject: [PATCH 03/36] updating detect_faces, failing tests --- vision/cloud-client/detect/detect.py | 93 ++++++++++++++-------------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 34037fb3f58..0df016256bd 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -31,25 +31,27 @@ import argparse import io -from google.cloud import vision +from google.cloud.vision import ImageAnnotatorClient +from google.cloud.vision import types def detect_faces(path): """Detects faces in an image.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) - faces = image.detect_faces() + response = client.detect_faces(image=image) + faces = response.face_annotations print('Faces:') for face in faces: - print('anger: {}'.format(face.emotions.anger)) - print('joy: {}'.format(face.emotions.joy)) - print('surprise: {}'.format(face.emotions.surprise)) + print('anger: {}'.format(face.anger_likelihood)) + print('joy: {}'.format(face.joy_likelihood)) + print('surprise: {}'.format(face.surprise_likelihood)) vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate) for bound in face.bounds.vertices]) @@ -59,8 +61,9 @@ def detect_faces(path): def detect_faces_uri(uri): """Detects faces in the file located in Google Cloud Storage or the web.""" - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image() + image.source.image_uri = uri faces = image.detect_faces() print('Faces:') @@ -78,12 +81,12 @@ def detect_faces_uri(uri): def detect_labels(path): """Detects labels in the file.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) labels = image.detect_labels() print('Labels:') @@ -95,8 +98,8 @@ def detect_labels(path): def detect_labels_uri(uri): """Detects labels in the file located in Google Cloud Storage or on the Web.""" - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) labels = image.detect_labels() print('Labels:') @@ -107,12 +110,12 @@ def detect_labels_uri(uri): def detect_landmarks(path): """Detects landmarks in the file.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) landmarks = image.detect_landmarks() print('Landmarks:') @@ -124,8 +127,8 @@ def detect_landmarks(path): def detect_landmarks_uri(uri): """Detects landmarks in the file located in Google Cloud Storage or on the Web.""" - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) landmarks = image.detect_landmarks() print('Landmarks:') @@ -136,12 +139,12 @@ def detect_landmarks_uri(uri): def detect_logos(path): """Detects logos in the file.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) logos = image.detect_logos() print('Logos:') @@ -153,8 +156,8 @@ def detect_logos(path): def detect_logos_uri(uri): """Detects logos in the file located in Google Cloud Storage or on the Web. """ - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) logos = image.detect_logos() print('Logos:') @@ -165,12 +168,12 @@ def detect_logos_uri(uri): def detect_safe_search(path): """Detects unsafe features in the file.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) safe = image.detect_safe_search() print('Safe search:') @@ -183,8 +186,8 @@ def detect_safe_search(path): def detect_safe_search_uri(uri): """Detects unsafe features in the file located in Google Cloud Storage or on the Web.""" - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) safe = image.detect_safe_search() print('adult: {}'.format(safe.adult)) @@ -195,12 +198,12 @@ def detect_safe_search_uri(uri): def detect_text(path): """Detects text in the file.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) texts = image.detect_text() print('Texts:') @@ -217,8 +220,8 @@ def detect_text(path): def detect_text_uri(uri): """Detects text in the file located in Google Cloud Storage or on the Web. """ - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) texts = image.detect_text() print('Texts:') @@ -234,12 +237,12 @@ def detect_text_uri(uri): def detect_properties(path): """Detects image properties in the file.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) props = image.detect_properties() print('Properties:') @@ -255,8 +258,8 @@ def detect_properties(path): def detect_properties_uri(uri): """Detects image properties in the file located in Google Cloud Storage or on the Web.""" - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) props = image.detect_properties() print('Properties:') @@ -271,12 +274,12 @@ def detect_properties_uri(uri): def detect_web(path): """Detects web annotations given an image.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) notes = image.detect_web() @@ -313,8 +316,8 @@ def detect_web(path): def detect_web_uri(uri): """Detects web annotations in the file located in Google Cloud Storage.""" - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) notes = image.detect_web() @@ -351,10 +354,10 @@ def detect_web_uri(uri): def detect_crop_hints(path): """Detects crop hints in an image.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) hints = image.detect_crop_hints({1.77}) @@ -369,8 +372,8 @@ def detect_crop_hints(path): def detect_crop_hints_uri(uri): """Detects crop hints in the file located in Google Cloud Storage.""" - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) hints = image.detect_crop_hints({1.77}) for n, hint in enumerate(hints): @@ -384,12 +387,12 @@ def detect_crop_hints_uri(uri): def detect_document(path): """Detects document features in an image.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) document = image.detect_full_text() @@ -414,8 +417,8 @@ def detect_document(path): def detect_document_uri(uri): """Detects document features in the file located in Google Cloud Storage.""" - vision_client = vision.Client() - image = vision_client.image(source_uri=uri) + client = ImageAnnotatorClient() + image = types.Image(source_uri=uri) document = image.detect_full_text() From 1ec2eeff5e6fad32ccd4bce69d1f0b518c828955 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 14:35:24 -0700 Subject: [PATCH 04/36] Migrate detect_faces to gapic --- vision/cloud-client/detect/detect.py | 28 +++++++++++++---------- vision/cloud-client/detect/detect_test.py | 4 ++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 0df016256bd..2964fc1a13b 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -33,7 +33,10 @@ from google.cloud.vision import ImageAnnotatorClient from google.cloud.vision import types +from google.cloud.vision import enums +likelihood_name = {value : name for name, value in \ +vars(enums.Likelihood).iteritems() if not name.startswith('__')} def detect_faces(path): """Detects faces in an image.""" @@ -44,17 +47,17 @@ def detect_faces(path): image = types.Image(content=content) - response = client.detect_faces(image=image) + response = client.face_detection(image=image) faces = response.face_annotations print('Faces:') for face in faces: - print('anger: {}'.format(face.anger_likelihood)) - print('joy: {}'.format(face.joy_likelihood)) - print('surprise: {}'.format(face.surprise_likelihood)) + print('anger: {}'.format(likelihood_name[face.anger_likelihood])) + print('joy: {}'.format(likelihood_name[face.joy_likelihood])) + print('surprise: {}'.format(likelihood_name[face.surprise_likelihood])) - vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate) - for bound in face.bounds.vertices]) + vertices = (['({},{})'.format(bound.x, bound.y) + for bound in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) @@ -65,16 +68,17 @@ def detect_faces_uri(uri): image = types.Image() image.source.image_uri = uri - faces = image.detect_faces() + response = client.face_detection(image=image) + faces = response.face_annotations print('Faces:') for face in faces: - print('anger: {}'.format(face.emotions.anger)) - print('joy: {}'.format(face.emotions.joy)) - print('surprise: {}'.format(face.emotions.surprise)) + print('anger: {}'.format(likelihood_name[face.anger_likelihood])) + print('joy: {}'.format(likelihood_name[face.joy_likelihood])) + print('surprise: {}'.format(likelihood_name[face.surprise_likelihood])) - vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate) - for bound in face.bounds.vertices]) + vertices = (['({},{})'.format(bound.x, bound.y) + for bound in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) diff --git a/vision/cloud-client/detect/detect_test.py b/vision/cloud-client/detect/detect_test.py index ac19579546f..ebebd40892f 100644 --- a/vision/cloud-client/detect/detect_test.py +++ b/vision/cloud-client/detect/detect_test.py @@ -71,14 +71,14 @@ def test_faces(capsys): 'resources/face_no_surprise.jpg') detect.detect_faces(file_name) out, _ = capsys.readouterr() - assert 'Likelihood.POSSIBLE' in out + assert 'POSSIBLE' in out def test_faces_uri(capsys): file_name = 'gs://{}/vision/face_no_surprise.jpg'.format(BUCKET) detect.detect_faces_uri(file_name) out, _ = capsys.readouterr() - assert 'Likelihood.POSSIBLE' in out + assert 'POSSIBLE' in out def test_faces_http(capsys): From b776c643a746a695c1faecb50c294655b973999f Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 14:47:49 -0700 Subject: [PATCH 05/36] Migrate detect_labels to gapic --- vision/cloud-client/detect/detect.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 2964fc1a13b..0ded2c0a2f0 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -92,7 +92,8 @@ def detect_labels(path): image = types.Image(content=content) - labels = image.detect_labels() + response = client.label_detection(image=image) + labels = response.label_annotations print('Labels:') for label in labels: @@ -103,9 +104,11 @@ def detect_labels_uri(uri): """Detects labels in the file located in Google Cloud Storage or on the Web.""" client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri - labels = image.detect_labels() + response = client.label_detection(image=image) + labels = response.label_annotations print('Labels:') for label in labels: From 5b27f6d38751ceab53a984ea433290760ed1b849 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 14:54:27 -0700 Subject: [PATCH 06/36] Migrate detect_landmarks to gapic --- vision/cloud-client/detect/detect.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 0ded2c0a2f0..969cbb78762 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -124,7 +124,8 @@ def detect_landmarks(path): image = types.Image(content=content) - landmarks = image.detect_landmarks() + response = client.landmark_detection(image=image) + landmarks = response.landmark_annotations print('Landmarks:') for landmark in landmarks: @@ -135,9 +136,11 @@ def detect_landmarks_uri(uri): """Detects landmarks in the file located in Google Cloud Storage or on the Web.""" client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri - landmarks = image.detect_landmarks() + response = client.landmark_detection(image=image) + landmarks = response.landmark_annotations print('Landmarks:') for landmark in landmarks: From 14395456cb0f473f9b2a3d3be93f53610df2bb5d Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 14:57:05 -0700 Subject: [PATCH 07/36] Migrate detect_logos to gapic --- vision/cloud-client/detect/detect.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 969cbb78762..02dff70f809 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -156,7 +156,8 @@ def detect_logos(path): image = types.Image(content=content) - logos = image.detect_logos() + response = client.logo_detection(image=image) + logos = response.logo_annotations print('Logos:') for logo in logos: @@ -167,9 +168,11 @@ def detect_logos_uri(uri): """Detects logos in the file located in Google Cloud Storage or on the Web. """ client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri - logos = image.detect_logos() + response = client.logo_detection(image=image) + logos = response.logo_annotations print('Logos:') for logo in logos: From 27238f152accf7722dcd01401cc45f74cd746425 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 14:58:16 -0700 Subject: [PATCH 08/36] remove "Likelihood" from test outputs --- vision/cloud-client/detect/detect_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect_test.py b/vision/cloud-client/detect/detect_test.py index ebebd40892f..7bea41af2ca 100644 --- a/vision/cloud-client/detect/detect_test.py +++ b/vision/cloud-client/detect/detect_test.py @@ -86,7 +86,7 @@ def test_faces_http(capsys): 'face_no_surprise.jpg') detect.detect_faces_uri(uri.format(BUCKET)) out, _ = capsys.readouterr() - assert 'Likelihood.POSSIBLE' in out + assert 'POSSIBLE' in out def test_logos(capsys): @@ -118,21 +118,21 @@ def test_safe_search(capsys): 'resources/wakeupcat.jpg') detect.detect_safe_search(file_name) out, _ = capsys.readouterr() - assert 'Likelihood.VERY_LIKELY' in out + assert 'VERY_LIKELY' in out def test_safe_search_uri(capsys): file_name = 'gs://{}/vision/wakeupcat.jpg'.format(BUCKET) detect.detect_safe_search_uri(file_name) out, _ = capsys.readouterr() - assert 'Likelihood.VERY_LIKELY' in out + assert 'VERY_LIKELY' in out def test_safe_search_http(capsys): uri = 'https://storage-download.googleapis.com/{}/vision/wakeupcat.jpg' detect.detect_safe_search_uri(uri.format(BUCKET)) out, _ = capsys.readouterr() - assert 'Likelihood.VERY_LIKELY' in out + assert 'VERY_LIKELY' in out def test_detect_text(capsys): From ceb206b953044a872f1769744548999c017f7ab3 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 15:52:54 -0700 Subject: [PATCH 09/36] Migrate detect_safe_search to gapic --- vision/cloud-client/detect/detect.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 02dff70f809..1c6f0f9c9c5 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -188,25 +188,29 @@ def detect_safe_search(path): image = types.Image(content=content) - safe = image.detect_safe_search() + response = client.safe_search_detection(image=image) + safe = response.safe_search_annotation print('Safe search:') - print('adult: {}'.format(safe.adult)) - print('medical: {}'.format(safe.medical)) - print('spoofed: {}'.format(safe.spoof)) - print('violence: {}'.format(safe.violence)) + print('adult: {}'.format(likelihood_name[safe.adult])) + print('medical: {}'.format(likelihood_name[safe.medical])) + print('spoofed: {}'.format(likelihood_name[safe.spoof])) + print('violence: {}'.format(likelihood_name[safe.violence])) def detect_safe_search_uri(uri): """Detects unsafe features in the file located in Google Cloud Storage or on the Web.""" client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri - safe = image.detect_safe_search() - print('adult: {}'.format(safe.adult)) - print('medical: {}'.format(safe.medical)) - print('spoofed: {}'.format(safe.spoof)) - print('violence: {}'.format(safe.violence)) + response = client.safe_search_detection(image=image) + safe = response.safe_search_annotation + print('Safe search:') + print('adult: {}'.format(likelihood_name[safe.adult])) + print('medical: {}'.format(likelihood_name[safe.medical])) + print('spoofed: {}'.format(likelihood_name[safe.spoof])) + print('violence: {}'.format(likelihood_name[safe.violence])) def detect_text(path): From 073f8b6ea5431ebba093bfc8600a879e0bb4d039 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 15:56:17 -0700 Subject: [PATCH 10/36] Migrate detect_text to gapic --- vision/cloud-client/detect/detect.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 1c6f0f9c9c5..ac2e0182636 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -222,14 +222,15 @@ def detect_text(path): image = types.Image(content=content) - texts = image.detect_text() + response = client.text_detection(image=image) + texts = response.text_annotations print('Texts:') for text in texts: print('\n"{}"'.format(text.description)) - vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate) - for bound in text.bounds.vertices]) + vertices = (['({},{})'.format(bound.x, bound.y) + for bound in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) @@ -238,16 +239,18 @@ def detect_text_uri(uri): """Detects text in the file located in Google Cloud Storage or on the Web. """ client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri - texts = image.detect_text() + response = client.text_detection(image=image) + texts = response.text_annotations print('Texts:') for text in texts: print('\n"{}"'.format(text.description)) - vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate) - for bound in text.bounds.vertices]) + vertices = (['({},{})'.format(bound.x, bound.y) + for bound in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) From aa03a599036fe75226871eef3430d467dca5ca8a Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 16:03:11 -0700 Subject: [PATCH 11/36] Migrate detect_properties to gapic --- vision/cloud-client/detect/detect.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index ac2e0182636..ef54bcbf98d 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -264,10 +264,11 @@ def detect_properties(path): image = types.Image(content=content) - props = image.detect_properties() + response = client.image_properties(image=image) + props = response.image_properties_annotation print('Properties:') - for color in props.colors: + for color in props.dominant_colors.colors: print('fraction: {}'.format(color.pixel_fraction)) print('\tr: {}'.format(color.color.red)) print('\tg: {}'.format(color.color.green)) @@ -279,12 +280,14 @@ def detect_properties_uri(uri): """Detects image properties in the file located in Google Cloud Storage or on the Web.""" client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri - props = image.detect_properties() + response = client.image_properties(image=image) + props = response.image_properties_annotation print('Properties:') - for color in props.colors: + for color in props.dominant_colors.colors: print('frac: {}'.format(color.pixel_fraction)) print('\tr: {}'.format(color.color.red)) print('\tg: {}'.format(color.color.green)) From 7f96de36da3bd6f5a636f8ec08c89c7984a49187 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 27 Jun 2017 16:09:36 -0700 Subject: [PATCH 12/36] Migrate detect_web to gapic --- vision/cloud-client/detect/detect.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index ef54bcbf98d..f194fc53d07 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -304,7 +304,8 @@ def detect_web(path): image = types.Image(content=content) - notes = image.detect_web() + response = client.web_detection(image=image) + notes = response.web_detection if notes.pages_with_matching_images: print('\n{} Pages with matching images retrieved') @@ -340,9 +341,11 @@ def detect_web(path): def detect_web_uri(uri): """Detects web annotations in the file located in Google Cloud Storage.""" client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri - notes = image.detect_web() + response = client.web_detection(image=image) + notes = response.web_detection if notes.pages_with_matching_images: print('\n{} Pages with matching images retrieved') From 0d100dbb4576eb89d05e7fc8cacc5b0b9616d7b5 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 09:56:28 -0700 Subject: [PATCH 13/36] Migrate crophints to gapic --- vision/cloud-client/detect/detect.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index f194fc53d07..0464ca53cc1 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -385,13 +385,17 @@ def detect_crop_hints(path): content = image_file.read() image = types.Image(content=content) - hints = image.detect_crop_hints({1.77}) + crop_hints_params = types.CropHintsParams(aspect_ratios=[1.77]) + image_context = types.ImageContext(crop_hints_params=crop_hints_params) + + response = client.crop_hints(image=image, image_context=image_context) + hints = response.crop_hints_annotation.crop_hints for n, hint in enumerate(hints): print('\nCrop Hint: {}'.format(n)) - vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate) - for bound in hint.bounds.vertices]) + vertices = (['({},{})'.format(bound.x, bound.y) + for bound in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) @@ -399,14 +403,20 @@ def detect_crop_hints(path): def detect_crop_hints_uri(uri): """Detects crop hints in the file located in Google Cloud Storage.""" client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri + + crop_hints_params = types.CropHintsParams(aspect_ratios=[1.77]) + image_context = types.ImageContext(crop_hints_params=crop_hints_params) + + response = client.crop_hints(image=image, image_context=image_context) + hints = response.crop_hints_annotation.crop_hints - hints = image.detect_crop_hints({1.77}) for n, hint in enumerate(hints): print('\nCrop Hint: {}'.format(n)) - vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate) - for bound in hint.bounds.vertices]) + vertices = (['({},{})'.format(bound.x, bound.y) + for bound in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) From af855eec3eadb24e23b5ff1f40d4551399847e66 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 10:11:56 -0700 Subject: [PATCH 14/36] Migrate detect_document to gapic; --- vision/cloud-client/detect/detect.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 0464ca53cc1..c0c7337a6a3 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -430,7 +430,8 @@ def detect_document(path): image = types.Image(content=content) - document = image.detect_full_text() + response = client.document_text_detection(image=image) + document = response.full_text_annotation for page in document.pages: for block in page.blocks: @@ -454,9 +455,11 @@ def detect_document_uri(uri): """Detects document features in the file located in Google Cloud Storage.""" client = ImageAnnotatorClient() - image = types.Image(source_uri=uri) + image = types.Image() + image.source.image_uri = uri - document = image.detect_full_text() + response = client.document_text_detection(image=image) + document = response.full_text_annotation for page in document.pages: for block in page.blocks: From 64981131da94dbe6fe58b653ba22bd201709fa02 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 10:19:38 -0700 Subject: [PATCH 15/36] Migrate crop_hints.py to gapic --- vision/cloud-client/crop_hints/crop_hints.py | 27 ++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/vision/cloud-client/crop_hints/crop_hints.py b/vision/cloud-client/crop_hints/crop_hints.py index 1f656c9776c..f51d3f5b463 100644 --- a/vision/cloud-client/crop_hints/crop_hints.py +++ b/vision/cloud-client/crop_hints/crop_hints.py @@ -25,7 +25,8 @@ import argparse import io -from google.cloud import vision +from google.cloud.vision import ImageAnnotatorClient +from google.cloud.vision import types from PIL import Image, ImageDraw # [END imports] @@ -33,15 +34,21 @@ def get_crop_hint(path): # [START get_crop_hint] """Detect crop hints on a single image and return the first result.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) + + crop_hints_params = types.CropHintsParams(aspect_ratios=[1.77]) + image_context = types.ImageContext(crop_hints_params=crop_hints_params) + + response = client.crop_hints(image=image, image_context=image_context) + hints = response.crop_hints_annotation.crop_hints # Return bounds for the first crop hint using an aspect ratio of 1.77. - return image.detect_crop_hints({1.77})[0].bounds.vertices + return hints[0].bounding_poly.vertices # [END get_crop_hint] @@ -53,10 +60,10 @@ def draw_hint(image_file): im = Image.open(image_file) draw = ImageDraw.Draw(im) draw.polygon([ - vects[0].x_coordinate, vects[0].y_coordinate, - vects[1].x_coordinate, vects[1].y_coordinate, - vects[2].x_coordinate, vects[2].y_coordinate, - vects[3].x_coordinate, vects[3].y_coordinate], None, 'red') + vects[0].x, vects[0].y, + vects[1].x, vects[1].y, + vects[2].x, vects[2].y, + vects[3].x, vects[3].y], None, 'red') im.save('output-hint.jpg', 'JPEG') # [END draw_hint] @@ -67,8 +74,8 @@ def crop_to_hint(image_file): vects = get_crop_hint(image_file) im = Image.open(image_file) - im2 = im.crop([vects[0].x_coordinate, vects[0].y_coordinate, - vects[2].x_coordinate - 1, vects[2].y_coordinate - 1]) + im2 = im.crop([vects[0].x, vects[0].y, + vects[2].x - 1, vects[2].y - 1]) im2.save('output-crop.jpg', 'JPEG') # [END crop_to_hint] From 328390b84e7ef6df00c9d993d1b3fb15a0f2b392 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 10:33:44 -0700 Subject: [PATCH 16/36] hard code the likelihood names --- vision/cloud-client/detect/detect.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index c0c7337a6a3..52fc939e9da 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -35,8 +35,9 @@ from google.cloud.vision import types from google.cloud.vision import enums -likelihood_name = {value : name for name, value in \ -vars(enums.Likelihood).iteritems() if not name.startswith('__')} +# Names of likelihood from google.cloud.vision.enums +likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') def detect_faces(path): """Detects faces in an image.""" From 54021a3be00fcd06914cd8538af969f84f1cbea4 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 11:12:18 -0700 Subject: [PATCH 17/36] Make code snippets more self-contained --- vision/cloud-client/detect/detect.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 52fc939e9da..65bca5e3867 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -41,6 +41,10 @@ def detect_faces(path): """Detects faces in an image.""" + # Names of likelihood from google.cloud.vision.enums + likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: @@ -65,6 +69,10 @@ def detect_faces(path): def detect_faces_uri(uri): """Detects faces in the file located in Google Cloud Storage or the web.""" + # Names of likelihood from google.cloud.vision.enums + likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') + client = ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -182,6 +190,10 @@ def detect_logos_uri(uri): def detect_safe_search(path): """Detects unsafe features in the file.""" + # Names of likelihood from google.cloud.vision.enums + likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') + client = ImageAnnotatorClient() with io.open(path, 'rb') as image_file: @@ -201,6 +213,10 @@ def detect_safe_search(path): def detect_safe_search_uri(uri): """Detects unsafe features in the file located in Google Cloud Storage or on the Web.""" + # Names of likelihood from google.cloud.vision.enums + likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') + client = ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri From 05c48df985a1716cf729197612e56e5a5c991505 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 11:16:04 -0700 Subject: [PATCH 18/36] Migrate doctext.py to gapic --- vision/cloud-client/document_text/doctext.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/document_text/doctext.py b/vision/cloud-client/document_text/doctext.py index 9fb535ff65f..083e0bcd652 100644 --- a/vision/cloud-client/document_text/doctext.py +++ b/vision/cloud-client/document_text/doctext.py @@ -25,7 +25,8 @@ from enum import Enum import io -from google.cloud import vision +from google.cloud.vision import ImageAnnotatorClient +from google.cloud.vision import types from PIL import Image, ImageDraw # [END imports] @@ -56,15 +57,17 @@ def draw_boxes(image, blocks, color): def get_document_bounds(image_file, feature): # [START detect_bounds] """Returns document bounds given an image.""" - vision_client = vision.Client() + client = ImageAnnotatorClient() bounds = [] with io.open(image_file, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) - document = image.detect_full_text() + image = types.Image(content=content) + + response = client.document_text_detection(image=image) + document = response.full_text_annotation # Collect specified feature bounds by enumerating all document features for page in document.pages: From f6595f608ccee602e56d0e5baf08b8add19c408f Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 11:23:27 -0700 Subject: [PATCH 19/36] Migrate web_detect.py to gapic --- vision/cloud-client/web/web_detect.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index 622aae61a9e..73285f71d27 100644 --- a/vision/cloud-client/web/web_detect.py +++ b/vision/cloud-client/web/web_detect.py @@ -26,26 +26,27 @@ import argparse import io -from google.cloud import vision +from google.cloud.vision import ImageAnnotatorClient +from google.cloud.vision import types # [END imports] def annotate(path): """Returns web annotations given the path to an image.""" # [START get_annotations] - image = None - vision_client = vision.Client() + client = ImageAnnotatorClient() if path.startswith('http') or path.startswith('gs:'): - image = vision_client.image(source_uri=path) + image = types.Image() + image.source.image_uri = path else: with io.open(path, 'rb') as image_file: content = image_file.read() - image = vision_client.image(content=content) + image = types.Image(content=content) - return image.detect_web() + return client.web_detection(image=image).web_detection # [END get_annotations] From fe57c07259e48e9c00de655bfab85f20d1fafe2d Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 11:28:54 -0700 Subject: [PATCH 20/36] Migrate faces.py to gapic --- vision/cloud-client/face_detection/faces.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 6baef63c76b..4a65e150cc8 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -18,7 +18,8 @@ import argparse -from google.cloud import vision +from google.cloud.vision import ImageAnnotatorClient +from google.cloud.vision import types from PIL import Image, ImageDraw @@ -31,12 +32,14 @@ def detect_face(face_file, max_results=4): Returns: An array of Face objects with information about the picture. """ + client = ImageAnnotatorClient() + content = face_file.read() # [START get_vision_service] - image = vision.Client().image(content=content) + image = types.Image(content=content) # [END get_vision_service] - return image.detect_faces() + return client.face_detection(image=image).face_annotations def highlight_faces(image, faces, output_filename): @@ -53,8 +56,8 @@ def highlight_faces(image, faces, output_filename): draw = ImageDraw.Draw(im) for face in faces: - box = [(bound.x_coordinate, bound.y_coordinate) - for bound in face.bounds.vertices] + box = [(bound.x, bound.y) + for bound in face.bounding_poly.vertices] draw.line(box + [box[0]], width=5, fill='#00ff00') im.save(output_filename) From 4977de9854a7102eb1436ce0e7a9d2c514df230e Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 28 Jun 2017 11:37:45 -0700 Subject: [PATCH 21/36] flake8 --- vision/cloud-client/detect/detect.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 65bca5e3867..24d0b39b5e9 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -33,17 +33,17 @@ from google.cloud.vision import ImageAnnotatorClient from google.cloud.vision import types -from google.cloud.vision import enums # Names of likelihood from google.cloud.vision.enums likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY') + def detect_faces(path): """Detects faces in an image.""" # Names of likelihood from google.cloud.vision.enums likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') + 'LIKELY', 'VERY_LIKELY') client = ImageAnnotatorClient() @@ -71,7 +71,7 @@ def detect_faces_uri(uri): """Detects faces in the file located in Google Cloud Storage or the web.""" # Names of likelihood from google.cloud.vision.enums likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') + 'LIKELY', 'VERY_LIKELY') client = ImageAnnotatorClient() image = types.Image() @@ -192,7 +192,7 @@ def detect_safe_search(path): """Detects unsafe features in the file.""" # Names of likelihood from google.cloud.vision.enums likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') + 'LIKELY', 'VERY_LIKELY') client = ImageAnnotatorClient() @@ -215,7 +215,7 @@ def detect_safe_search_uri(uri): on the Web.""" # Names of likelihood from google.cloud.vision.enums likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') + 'LIKELY', 'VERY_LIKELY') client = ImageAnnotatorClient() image = types.Image() From e43c0903a5a8356b61c8430bdcad2f6603348898 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 29 Jun 2017 12:04:57 -0700 Subject: [PATCH 22/36] fix missing string format --- vision/cloud-client/web/web_detect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index 73285f71d27..5cd1ff258ca 100644 --- a/vision/cloud-client/web/web_detect.py +++ b/vision/cloud-client/web/web_detect.py @@ -54,7 +54,8 @@ def report(annotations): """Prints detected features in the provided web annotations.""" # [START print_annotations] if annotations.pages_with_matching_images: - print('\n{} Pages with matching images retrieved') + print('\n{} Pages with matching images retrieved'.format( + len(annotations.pages_with_matching_images))) for page in annotations.pages_with_matching_images: print('Score : {}'.format(page.score)) From 389251e007bf8d4143428e4f9cbae1760ca157a1 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Thu, 29 Jun 2017 12:09:37 -0700 Subject: [PATCH 23/36] remove url scores from sample output --- vision/cloud-client/detect/detect.py | 6 ------ vision/cloud-client/web/web_detect.py | 3 --- 2 files changed, 9 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 24d0b39b5e9..27f3a05ee5b 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -328,7 +328,6 @@ def detect_web(path): print('\n{} Pages with matching images retrieved') for page in notes.pages_with_matching_images: - print('Score : {}'.format(page.score)) print('Url : {}'.format(page.url)) if notes.full_matching_images: @@ -336,7 +335,6 @@ def detect_web(path): len(notes.full_matching_images))) for image in notes.full_matching_images: - print('Score: {}'.format(image.score)) print('Url : {}'.format(image.url)) if notes.partial_matching_images: @@ -344,7 +342,6 @@ def detect_web(path): len(notes.partial_matching_images))) for image in notes.partial_matching_images: - print('Score: {}'.format(image.score)) print('Url : {}'.format(image.url)) if notes.web_entities: @@ -368,7 +365,6 @@ def detect_web_uri(uri): print('\n{} Pages with matching images retrieved') for page in notes.pages_with_matching_images: - print('Score : {}'.format(page.score)) print('Url : {}'.format(page.url)) if notes.full_matching_images: @@ -376,7 +372,6 @@ def detect_web_uri(uri): len(notes.full_matching_images))) for image in notes.full_matching_images: - print('Score: {}'.format(image.score)) print('Url : {}'.format(image.url)) if notes.partial_matching_images: @@ -384,7 +379,6 @@ def detect_web_uri(uri): len(notes.partial_matching_images))) for image in notes.partial_matching_images: - print('Score: {}'.format(image.score)) print('Url : {}'.format(image.url)) if notes.web_entities: diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index 5cd1ff258ca..0872d666555 100644 --- a/vision/cloud-client/web/web_detect.py +++ b/vision/cloud-client/web/web_detect.py @@ -58,7 +58,6 @@ def report(annotations): len(annotations.pages_with_matching_images))) for page in annotations.pages_with_matching_images: - print('Score : {}'.format(page.score)) print('Url : {}'.format(page.url)) if annotations.full_matching_images: @@ -66,7 +65,6 @@ def report(annotations): len(annotations.full_matching_images))) for image in annotations.full_matching_images: - print('Score: {}'.format(image.score)) print('Url : {}'.format(image.url)) if annotations.partial_matching_images: @@ -74,7 +72,6 @@ def report(annotations): len(annotations.partial_matching_images))) for image in annotations.partial_matching_images: - print('Score: {}'.format(image.score)) print('Url : {}'.format(image.url)) if annotations.web_entities: From d150fe16a9f789ba5b43af9dd8e0505e54f181ad Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 5 Jul 2017 12:37:03 -0700 Subject: [PATCH 24/36] region tags update --- vision/cloud-client/face_detection/faces.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 4a65e150cc8..0bb5649ab64 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -18,7 +18,9 @@ import argparse +# [START import_client_library] from google.cloud.vision import ImageAnnotatorClient +# [START import_client_library] from google.cloud.vision import types from PIL import Image, ImageDraw @@ -32,12 +34,12 @@ def detect_face(face_file, max_results=4): Returns: An array of Face objects with information about the picture. """ + # [START get_vision_service] client = ImageAnnotatorClient() + # [END get_vision_service] content = face_file.read() - # [START get_vision_service] image = types.Image(content=content) - # [END get_vision_service] return client.face_detection(image=image).face_annotations From ecc5ea815f936a2e094d92d74cc77c78bd4232a5 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 5 Jul 2017 12:51:21 -0700 Subject: [PATCH 25/36] region tag correction --- vision/cloud-client/face_detection/faces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 0bb5649ab64..a0e3ded7c9e 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -20,7 +20,7 @@ # [START import_client_library] from google.cloud.vision import ImageAnnotatorClient -# [START import_client_library] +# [END import_client_library] from google.cloud.vision import types from PIL import Image, ImageDraw From b70b687e20e5a47efe147dd34996942894659972 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 5 Jul 2017 14:50:04 -0700 Subject: [PATCH 26/36] move region tag in get crop hints --- vision/cloud-client/crop_hints/crop_hints.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vision/cloud-client/crop_hints/crop_hints.py b/vision/cloud-client/crop_hints/crop_hints.py index f51d3f5b463..d769c1b4582 100644 --- a/vision/cloud-client/crop_hints/crop_hints.py +++ b/vision/cloud-client/crop_hints/crop_hints.py @@ -47,10 +47,12 @@ def get_crop_hint(path): response = client.crop_hints(image=image, image_context=image_context) hints = response.crop_hints_annotation.crop_hints - # Return bounds for the first crop hint using an aspect ratio of 1.77. - return hints[0].bounding_poly.vertices + # Get bounds for the first crop hint using an aspect ratio of 1.77. + vertices = hints[0].bounding_poly.vertices # [END get_crop_hint] + return vertices + def draw_hint(image_file): """Draw a border around the image using the hints in the vector list.""" From 1f41a32d28f710932658111c773322da374a4989 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 5 Jul 2017 15:20:32 -0700 Subject: [PATCH 27/36] move region tags --- vision/cloud-client/document_text/doctext.py | 19 ++++++++++--------- vision/cloud-client/web/web_detect.py | 4 +++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/vision/cloud-client/document_text/doctext.py b/vision/cloud-client/document_text/doctext.py index 083e0bcd652..84421beb198 100644 --- a/vision/cloud-client/document_text/doctext.py +++ b/vision/cloud-client/document_text/doctext.py @@ -39,17 +39,17 @@ class FeatureType(Enum): SYMBOL = 5 -def draw_boxes(image, blocks, color): +def draw_boxes(image, bounds, color): """Draw a border around the image using the hints in the vector list.""" # [START draw_blocks] draw = ImageDraw.Draw(image) - for block in blocks: + for bound in bounds: draw.polygon([ - block.vertices[0].x, block.vertices[0].y, - block.vertices[1].x, block.vertices[1].y, - block.vertices[2].x, block.vertices[2].y, - block.vertices[3].x, block.vertices[3].y], None, color) + bound.vertices[0].x, bound.vertices[0].y, + bound.vertices[1].x, bound.vertices[1].y, + bound.vertices[2].x, bound.vertices[2].y, + bound.vertices[3].x, bound.vertices[3].y], None, color) return image # [END draw_blocks] @@ -90,8 +90,9 @@ def get_document_bounds(image_file, feature): if (feature == FeatureType.PAGE): bounds.append(block.bounding_box) - return bounds + # The list `bounds` contains the coordinates of the bounding boxes. # [END detect_bounds] + return bounds def render_doc_text(filein, fileout): @@ -112,7 +113,7 @@ def render_doc_text(filein, fileout): if __name__ == '__main__': - # [START run_crop] + # [START run_doc_text] parser = argparse.ArgumentParser() parser.add_argument('detect_file', help='The image for text detection.') parser.add_argument('-out_file', help='Optional output file', default=0) @@ -120,5 +121,5 @@ def render_doc_text(filein, fileout): parser = argparse.ArgumentParser() render_doc_text(args.detect_file, args.out_file) - # [END run_crop] + # [END run_doc_text] # [END full_tutorial] diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index 0872d666555..e74fe6953db 100644 --- a/vision/cloud-client/web/web_detect.py +++ b/vision/cloud-client/web/web_detect.py @@ -46,9 +46,11 @@ def annotate(path): image = types.Image(content=content) - return client.web_detection(image=image).web_detection + web_detection = client.web_detection(image=image).web_detection # [END get_annotations] + return web_detection + def report(annotations): """Prints detected features in the provided web annotations.""" From 3265d5086c3de400ba6ed2d64482199698ef7a95 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Fri, 7 Jul 2017 10:11:00 -0700 Subject: [PATCH 28/36] import style --- vision/cloud-client/crop_hints/crop_hints.py | 2 +- vision/cloud-client/detect/detect.py | 2 +- vision/cloud-client/document_text/doctext.py | 2 +- vision/cloud-client/face_detection/faces.py | 2 +- vision/cloud-client/quickstart/quickstart.py | 2 +- vision/cloud-client/web/web_detect.py | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vision/cloud-client/crop_hints/crop_hints.py b/vision/cloud-client/crop_hints/crop_hints.py index d769c1b4582..2e1e107fee5 100644 --- a/vision/cloud-client/crop_hints/crop_hints.py +++ b/vision/cloud-client/crop_hints/crop_hints.py @@ -25,7 +25,7 @@ import argparse import io -from google.cloud.vision import ImageAnnotatorClient +from google.cloud import vision from google.cloud.vision import types from PIL import Image, ImageDraw # [END imports] diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 27f3a05ee5b..c5abc837384 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -31,7 +31,7 @@ import argparse import io -from google.cloud.vision import ImageAnnotatorClient +from google.cloud import vision from google.cloud.vision import types # Names of likelihood from google.cloud.vision.enums diff --git a/vision/cloud-client/document_text/doctext.py b/vision/cloud-client/document_text/doctext.py index 84421beb198..5ce2f7b2c2a 100644 --- a/vision/cloud-client/document_text/doctext.py +++ b/vision/cloud-client/document_text/doctext.py @@ -25,7 +25,7 @@ from enum import Enum import io -from google.cloud.vision import ImageAnnotatorClient +from google.cloud import vision from google.cloud.vision import types from PIL import Image, ImageDraw # [END imports] diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index a0e3ded7c9e..f18111f6dcb 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -19,7 +19,7 @@ import argparse # [START import_client_library] -from google.cloud.vision import ImageAnnotatorClient +from google.cloud import vision # [END import_client_library] from google.cloud.vision import types from PIL import Image, ImageDraw diff --git a/vision/cloud-client/quickstart/quickstart.py b/vision/cloud-client/quickstart/quickstart.py index 08c68bdaec2..5d30488291c 100644 --- a/vision/cloud-client/quickstart/quickstart.py +++ b/vision/cloud-client/quickstart/quickstart.py @@ -21,7 +21,7 @@ def run_quickstart(): import os # Imports the Google Cloud client library - from google.cloud.vision import ImageAnnotatorClient + from google.cloud import vision from google.cloud.vision import types # Instantiates a client diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index e74fe6953db..a1f59e12616 100644 --- a/vision/cloud-client/web/web_detect.py +++ b/vision/cloud-client/web/web_detect.py @@ -26,7 +26,7 @@ import argparse import io -from google.cloud.vision import ImageAnnotatorClient +from google.cloud import vision from google.cloud.vision import types # [END imports] @@ -49,7 +49,7 @@ def annotate(path): web_detection = client.web_detection(image=image).web_detection # [END get_annotations] - return web_detection + return web_detection def report(annotations): From 4edd3afade74e44733464252c6d0d0f4b28a4951 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Fri, 7 Jul 2017 10:25:57 -0700 Subject: [PATCH 29/36] client creation --- vision/cloud-client/crop_hints/crop_hints.py | 2 +- vision/cloud-client/detect/detect.py | 40 ++++++++++---------- vision/cloud-client/document_text/doctext.py | 2 +- vision/cloud-client/face_detection/faces.py | 2 +- vision/cloud-client/quickstart/quickstart.py | 2 +- vision/cloud-client/web/web_detect.py | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/vision/cloud-client/crop_hints/crop_hints.py b/vision/cloud-client/crop_hints/crop_hints.py index 2e1e107fee5..3120fe2fbe4 100644 --- a/vision/cloud-client/crop_hints/crop_hints.py +++ b/vision/cloud-client/crop_hints/crop_hints.py @@ -34,7 +34,7 @@ def get_crop_hint(path): # [START get_crop_hint] """Detect crop hints on a single image and return the first result.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index c5abc837384..a38a3afa474 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -45,7 +45,7 @@ def detect_faces(path): likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY') - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -73,7 +73,7 @@ def detect_faces_uri(uri): likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY') - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -94,7 +94,7 @@ def detect_faces_uri(uri): def detect_labels(path): """Detects labels in the file.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -112,7 +112,7 @@ def detect_labels(path): def detect_labels_uri(uri): """Detects labels in the file located in Google Cloud Storage or on the Web.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -126,7 +126,7 @@ def detect_labels_uri(uri): def detect_landmarks(path): """Detects landmarks in the file.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -144,7 +144,7 @@ def detect_landmarks(path): def detect_landmarks_uri(uri): """Detects landmarks in the file located in Google Cloud Storage or on the Web.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -158,7 +158,7 @@ def detect_landmarks_uri(uri): def detect_logos(path): """Detects logos in the file.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -176,7 +176,7 @@ def detect_logos(path): def detect_logos_uri(uri): """Detects logos in the file located in Google Cloud Storage or on the Web. """ - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -194,7 +194,7 @@ def detect_safe_search(path): likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY') - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -217,7 +217,7 @@ def detect_safe_search_uri(uri): likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 'LIKELY', 'VERY_LIKELY') - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -232,7 +232,7 @@ def detect_safe_search_uri(uri): def detect_text(path): """Detects text in the file.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -255,7 +255,7 @@ def detect_text(path): def detect_text_uri(uri): """Detects text in the file located in Google Cloud Storage or on the Web. """ - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -274,7 +274,7 @@ def detect_text_uri(uri): def detect_properties(path): """Detects image properties in the file.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -296,7 +296,7 @@ def detect_properties(path): def detect_properties_uri(uri): """Detects image properties in the file located in Google Cloud Storage or on the Web.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -314,7 +314,7 @@ def detect_properties_uri(uri): def detect_web(path): """Detects web annotations given an image.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -354,7 +354,7 @@ def detect_web(path): def detect_web_uri(uri): """Detects web annotations in the file located in Google Cloud Storage.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -391,7 +391,7 @@ def detect_web_uri(uri): def detect_crop_hints(path): """Detects crop hints in an image.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() image = types.Image(content=content) @@ -413,7 +413,7 @@ def detect_crop_hints(path): def detect_crop_hints_uri(uri): """Detects crop hints in the file located in Google Cloud Storage.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri @@ -434,7 +434,7 @@ def detect_crop_hints_uri(uri): def detect_document(path): """Detects document features in an image.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() with io.open(path, 'rb') as image_file: content = image_file.read() @@ -465,7 +465,7 @@ def detect_document(path): def detect_document_uri(uri): """Detects document features in the file located in Google Cloud Storage.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri diff --git a/vision/cloud-client/document_text/doctext.py b/vision/cloud-client/document_text/doctext.py index 5ce2f7b2c2a..478f2e22731 100644 --- a/vision/cloud-client/document_text/doctext.py +++ b/vision/cloud-client/document_text/doctext.py @@ -57,7 +57,7 @@ def draw_boxes(image, bounds, color): def get_document_bounds(image_file, feature): # [START detect_bounds] """Returns document bounds given an image.""" - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() bounds = [] diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index f18111f6dcb..455b0fffa40 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -35,7 +35,7 @@ def detect_face(face_file, max_results=4): An array of Face objects with information about the picture. """ # [START get_vision_service] - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() # [END get_vision_service] content = face_file.read() diff --git a/vision/cloud-client/quickstart/quickstart.py b/vision/cloud-client/quickstart/quickstart.py index 5d30488291c..beab316ea6a 100644 --- a/vision/cloud-client/quickstart/quickstart.py +++ b/vision/cloud-client/quickstart/quickstart.py @@ -25,7 +25,7 @@ def run_quickstart(): from google.cloud.vision import types # Instantiates a client - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() # The name of the image file to annotate file_name = os.path.join( diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index a1f59e12616..0b3e72f901e 100644 --- a/vision/cloud-client/web/web_detect.py +++ b/vision/cloud-client/web/web_detect.py @@ -34,7 +34,7 @@ def annotate(path): """Returns web annotations given the path to an image.""" # [START get_annotations] - client = ImageAnnotatorClient() + client = vision.ImageAnnotatorClient() if path.startswith('http') or path.startswith('gs:'): image = types.Image() From 7fb9d82fd6b8f96ed9f41f4e31920e91aadcaa19 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Fri, 7 Jul 2017 13:27:41 -0700 Subject: [PATCH 30/36] rename bound to vertex --- vision/cloud-client/detect/detect.py | 24 ++++++++++----------- vision/cloud-client/face_detection/faces.py | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index a38a3afa474..b0f0620ebb3 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -61,8 +61,8 @@ def detect_faces(path): print('joy: {}'.format(likelihood_name[face.joy_likelihood])) print('surprise: {}'.format(likelihood_name[face.surprise_likelihood])) - vertices = (['({},{})'.format(bound.x, bound.y) - for bound in face.bounding_poly.vertices]) + vertices = (['({},{})'.format(vertex.x, vertex.y) + for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) @@ -86,8 +86,8 @@ def detect_faces_uri(uri): print('joy: {}'.format(likelihood_name[face.joy_likelihood])) print('surprise: {}'.format(likelihood_name[face.surprise_likelihood])) - vertices = (['({},{})'.format(bound.x, bound.y) - for bound in face.bounding_poly.vertices]) + vertices = (['({},{})'.format(vertex.x, vertex.y) + for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) @@ -246,8 +246,8 @@ def detect_text(path): for text in texts: print('\n"{}"'.format(text.description)) - vertices = (['({},{})'.format(bound.x, bound.y) - for bound in text.bounding_poly.vertices]) + vertices = (['({},{})'.format(vertex.x, vertex.y) + for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) @@ -266,8 +266,8 @@ def detect_text_uri(uri): for text in texts: print('\n"{}"'.format(text.description)) - vertices = (['({},{})'.format(bound.x, bound.y) - for bound in text.bounding_poly.vertices]) + vertices = (['({},{})'.format(vertex.x, vertex.y) + for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) @@ -405,8 +405,8 @@ def detect_crop_hints(path): for n, hint in enumerate(hints): print('\nCrop Hint: {}'.format(n)) - vertices = (['({},{})'.format(bound.x, bound.y) - for bound in hint.bounding_poly.vertices]) + vertices = (['({},{})'.format(vertex.x, vertex.y) + for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) @@ -426,8 +426,8 @@ def detect_crop_hints_uri(uri): for n, hint in enumerate(hints): print('\nCrop Hint: {}'.format(n)) - vertices = (['({},{})'.format(bound.x, bound.y) - for bound in hint.bounding_poly.vertices]) + vertices = (['({},{})'.format(vertex.x, vertex.y) + for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 455b0fffa40..fb43d16391a 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -58,8 +58,8 @@ def highlight_faces(image, faces, output_filename): draw = ImageDraw.Draw(im) for face in faces: - box = [(bound.x, bound.y) - for bound in face.bounding_poly.vertices] + box = [(vertex.x, vertex.y) + for vertex in face.bounding_poly.vertices] draw.line(box + [box[0]], width=5, fill='#00ff00') im.save(output_filename) From eb4ef647f0721a8d2e1b1ab4ec6002de55a108ca Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Mon, 17 Jul 2017 15:57:50 -0700 Subject: [PATCH 31/36] add region tags --- vision/cloud-client/detect/detect.py | 107 +++++++++++++++---- vision/cloud-client/face_detection/faces.py | 6 ++ vision/cloud-client/quickstart/quickstart.py | 7 +- 3 files changed, 99 insertions(+), 21 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index b0f0620ebb3..1e89ea9845c 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -34,26 +34,26 @@ from google.cloud import vision from google.cloud.vision import types -# Names of likelihood from google.cloud.vision.enums -likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') - +# [START def_detect_faces] def detect_faces(path): """Detects faces in an image.""" - # Names of likelihood from google.cloud.vision.enums - likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') - client = vision.ImageAnnotatorClient() + # [START migration_face_detection] + # [START migration_image_file] with io.open(path, 'rb') as image_file: content = image_file.read() image = types.Image(content=content) + # [END migration_image_file] response = client.face_detection(image=image) faces = response.face_annotations + + # Names of likelihood from google.cloud.vision.enums + likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') print('Faces:') for face in faces: @@ -65,20 +65,25 @@ def detect_faces(path): for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) + # [END migration_face_detection] +# [END def_detect_faces] +# [START def_detect_faces_uri] def detect_faces_uri(uri): """Detects faces in the file located in Google Cloud Storage or the web.""" - # Names of likelihood from google.cloud.vision.enums - likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') - client = vision.ImageAnnotatorClient() + # [START migration_image_uri] image = types.Image() image.source.image_uri = uri + # [END migration_image_uri] response = client.face_detection(image=image) faces = response.face_annotations + + # Names of likelihood from google.cloud.vision.enums + likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') print('Faces:') for face in faces: @@ -90,12 +95,15 @@ def detect_faces_uri(uri): for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) +# [END def_detect_faces_uri] +# [START def_detect_labels] def detect_labels(path): """Detects labels in the file.""" client = vision.ImageAnnotatorClient() + # [START migration_label_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -107,8 +115,11 @@ def detect_labels(path): for label in labels: print(label.description) + # [END migration_label_detection] +# [END def_detect_labels] +# [START def_detect_labels_uri] def detect_labels_uri(uri): """Detects labels in the file located in Google Cloud Storage or on the Web.""" @@ -122,12 +133,15 @@ def detect_labels_uri(uri): for label in labels: print(label.description) +# [END def_detect_labels_uri] +# [START def_detect_landmarks] def detect_landmarks(path): """Detects landmarks in the file.""" client = vision.ImageAnnotatorClient() + # [START migration_landmark_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -139,8 +153,15 @@ def detect_landmarks(path): for landmark in landmarks: print(landmark.description) + for location in landmark.locations: + lat_lng = location.lat_lng + print('Latitude'.format(lat_lng.latitude)) + print('Longitude'.format(lat_lng.longitude)) + # [END migration_landmark_detection] +# [END def_detect_landmarks] +# [START def_detect_landmarks_uri] def detect_landmarks_uri(uri): """Detects landmarks in the file located in Google Cloud Storage or on the Web.""" @@ -154,12 +175,15 @@ def detect_landmarks_uri(uri): for landmark in landmarks: print(landmark.description) +# [END def_detect_landmarks_uri] +# [START def_detect_logos] def detect_logos(path): """Detects logos in the file.""" client = vision.ImageAnnotatorClient() + # [START migration_logo_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -171,8 +195,11 @@ def detect_logos(path): for logo in logos: print(logo.description) + # [END migration_logo_detection] +# [END def_detect_logos] +# [START def_detect_logos_uri] def detect_logos_uri(uri): """Detects logos in the file located in Google Cloud Storage or on the Web. """ @@ -186,16 +213,15 @@ def detect_logos_uri(uri): for logo in logos: print(logo.description) +# [END def_detect_logos_uri] +# [START def_detect_safe_search] def detect_safe_search(path): """Detects unsafe features in the file.""" - # Names of likelihood from google.cloud.vision.enums - likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') - client = vision.ImageAnnotatorClient() + # [START migration_safe_search_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -203,37 +229,49 @@ def detect_safe_search(path): response = client.safe_search_detection(image=image) safe = response.safe_search_annotation + + # Names of likelihood from google.cloud.vision.enums + likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') print('Safe search:') + print('adult: {}'.format(likelihood_name[safe.adult])) print('medical: {}'.format(likelihood_name[safe.medical])) print('spoofed: {}'.format(likelihood_name[safe.spoof])) print('violence: {}'.format(likelihood_name[safe.violence])) + # [END migration_safe_search_detection] +# [END def_detect_safe_search] +# [START def_detect_safe_search_uri] def detect_safe_search_uri(uri): """Detects unsafe features in the file located in Google Cloud Storage or on the Web.""" - # Names of likelihood from google.cloud.vision.enums - likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', - 'LIKELY', 'VERY_LIKELY') - client = vision.ImageAnnotatorClient() image = types.Image() image.source.image_uri = uri response = client.safe_search_detection(image=image) safe = response.safe_search_annotation + + # Names of likelihood from google.cloud.vision.enums + likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', + 'LIKELY', 'VERY_LIKELY') print('Safe search:') + print('adult: {}'.format(likelihood_name[safe.adult])) print('medical: {}'.format(likelihood_name[safe.medical])) print('spoofed: {}'.format(likelihood_name[safe.spoof])) print('violence: {}'.format(likelihood_name[safe.violence])) +# [END def_detect_safe_search_uri] +# [START def_detect_text] def detect_text(path): """Detects text in the file.""" client = vision.ImageAnnotatorClient() + # [START migration_text_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -250,8 +288,11 @@ def detect_text(path): for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) + # [END migration_text_detection] +# [END def_detect_text] +# [START def_detect_text_uri] def detect_text_uri(uri): """Detects text in the file located in Google Cloud Storage or on the Web. """ @@ -270,12 +311,15 @@ def detect_text_uri(uri): for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) +# [END def_detect_text_uri] +# [START def_detect_properties] def detect_properties(path): """Detects image properties in the file.""" client = vision.ImageAnnotatorClient() + # [START migration_image_properties] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -291,8 +335,11 @@ def detect_properties(path): print('\tg: {}'.format(color.color.green)) print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) + # [END migration_image_properties] +# [END def_detect_properties] +# [START def_detect_properties_uri] def detect_properties_uri(uri): """Detects image properties in the file located in Google Cloud Storage or on the Web.""" @@ -310,12 +357,15 @@ def detect_properties_uri(uri): print('\tg: {}'.format(color.color.green)) print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) +# [END def_detect_properties_uri] +# [START def_detect_web] def detect_web(path): """Detects web annotations given an image.""" client = vision.ImageAnnotatorClient() + # [START migration_web_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -350,8 +400,11 @@ def detect_web(path): for entity in notes.web_entities: print('Score : {}'.format(entity.score)) print('Description: {}'.format(entity.description)) + # [END migration_web_detection] +# [END def_detect_web] +# [START def_detect_web_uri] def detect_web_uri(uri): """Detects web annotations in the file located in Google Cloud Storage.""" client = vision.ImageAnnotatorClient() @@ -387,11 +440,15 @@ def detect_web_uri(uri): for entity in notes.web_entities: print('Score : {}'.format(entity.score)) print('Description: {}'.format(entity.description)) +# [END def_detect_web_uri] +# [START def_detect_crop_hints] def detect_crop_hints(path): """Detects crop hints in an image.""" client = vision.ImageAnnotatorClient() + + # [START migration_crop_hints] with io.open(path, 'rb') as image_file: content = image_file.read() image = types.Image(content=content) @@ -409,8 +466,11 @@ def detect_crop_hints(path): for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) + # [END migration_crop_hints] +# [END def_detect_crop_hints] +# [START def_detect_crop_hints_uri] def detect_crop_hints_uri(uri): """Detects crop hints in the file located in Google Cloud Storage.""" client = vision.ImageAnnotatorClient() @@ -430,12 +490,15 @@ def detect_crop_hints_uri(uri): for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) +# [END def_detect_crop_hints_uri] +# [START def_detect_document] def detect_document(path): """Detects document features in an image.""" client = vision.ImageAnnotatorClient() + # [START migration_document_text_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -460,8 +523,11 @@ def detect_document(path): print('Block Content: {}'.format(block_text)) print('Block Bounds:\n {}'.format(block.bounding_box)) + # [END migration_document_text_detection] +# [END def_detect_document] +# [START def_detect_document_uri] def detect_document_uri(uri): """Detects document features in the file located in Google Cloud Storage.""" @@ -488,6 +554,7 @@ def detect_document_uri(uri): print('Block Content: {}'.format(block_text)) print('Block Bounds:\n {}'.format(block.bounding_box)) +# [END def_detect_document_uri] def run_local(args): diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index fb43d16391a..25a40763b33 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -25,6 +25,7 @@ from PIL import Image, ImageDraw +# [START def_detect_face] def detect_face(face_file, max_results=4): """Uses the Vision API to detect faces in the given file. @@ -42,8 +43,10 @@ def detect_face(face_file, max_results=4): image = types.Image(content=content) return client.face_detection(image=image).face_annotations +# [END def_detect_face] +# [START def_highlight_faces] def highlight_faces(image, faces, output_filename): """Draws a polygon around the faces, then saves to output_filename. @@ -63,8 +66,10 @@ def highlight_faces(image, faces, output_filename): draw.line(box + [box[0]], width=5, fill='#00ff00') im.save(output_filename) +# [END def_highlight_faces] +# [START def_main] def main(input_filename, output_filename, max_results): with open(input_filename, 'rb') as image: faces = detect_face(image, max_results) @@ -75,6 +80,7 @@ def main(input_filename, output_filename, max_results): # Reset the file pointer, so we can read the file again image.seek(0) highlight_faces(image, faces, output_filename) +# [END def_main] if __name__ == '__main__': diff --git a/vision/cloud-client/quickstart/quickstart.py b/vision/cloud-client/quickstart/quickstart.py index beab316ea6a..4eb2b303612 100644 --- a/vision/cloud-client/quickstart/quickstart.py +++ b/vision/cloud-client/quickstart/quickstart.py @@ -21,11 +21,15 @@ def run_quickstart(): import os # Imports the Google Cloud client library + # [START migration_import] from google.cloud import vision from google.cloud.vision import types + # [END migration_import] # Instantiates a client + # [START migration_client] client = vision.ImageAnnotatorClient() + # [END migration_client] # The name of the image file to annotate file_name = os.path.join( @@ -35,7 +39,8 @@ def run_quickstart(): # Loads the image into memory with io.open(file_name, 'rb') as image_file: content = image_file.read() - image = types.Image(content=content) + + image = types.Image(content=content) # Performs label detection on the image file response = client.label_detection(image=image) From 1d7abbda7b53f7a429f5aa224cef9406b84bd6bb Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 18 Jul 2017 11:58:24 -0700 Subject: [PATCH 32/36] increment client library version --- vision/cloud-client/crop_hints/requirements.txt | 2 +- vision/cloud-client/detect/requirements.txt | 2 +- vision/cloud-client/document_text/requirements.txt | 2 +- vision/cloud-client/face_detection/requirements.txt | 2 +- vision/cloud-client/quickstart/requirements.txt | 2 +- vision/cloud-client/web/requirements.txt | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vision/cloud-client/crop_hints/requirements.txt b/vision/cloud-client/crop_hints/requirements.txt index 47a870ee71b..a31d4427b8b 100644 --- a/vision/cloud-client/crop_hints/requirements.txt +++ b/vision/cloud-client/crop_hints/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==0.25.0 +google-cloud-vision==0.26.0 pillow==4.2.1 diff --git a/vision/cloud-client/detect/requirements.txt b/vision/cloud-client/detect/requirements.txt index 704448d6c4f..1991be8b964 100644 --- a/vision/cloud-client/detect/requirements.txt +++ b/vision/cloud-client/detect/requirements.txt @@ -1 +1 @@ -google-cloud-vision==0.25.0 +google-cloud-vision==0.26.0 diff --git a/vision/cloud-client/document_text/requirements.txt b/vision/cloud-client/document_text/requirements.txt index 47a870ee71b..a31d4427b8b 100644 --- a/vision/cloud-client/document_text/requirements.txt +++ b/vision/cloud-client/document_text/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==0.25.0 +google-cloud-vision==0.26.0 pillow==4.2.1 diff --git a/vision/cloud-client/face_detection/requirements.txt b/vision/cloud-client/face_detection/requirements.txt index 0174b4fb8b7..fb17f8c2491 100644 --- a/vision/cloud-client/face_detection/requirements.txt +++ b/vision/cloud-client/face_detection/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==0.25.0 +google-cloud-vision==0.26.0 Pillow==4.2.1 diff --git a/vision/cloud-client/quickstart/requirements.txt b/vision/cloud-client/quickstart/requirements.txt index 704448d6c4f..1991be8b964 100644 --- a/vision/cloud-client/quickstart/requirements.txt +++ b/vision/cloud-client/quickstart/requirements.txt @@ -1 +1 @@ -google-cloud-vision==0.25.0 +google-cloud-vision==0.26.0 diff --git a/vision/cloud-client/web/requirements.txt b/vision/cloud-client/web/requirements.txt index 704448d6c4f..1991be8b964 100644 --- a/vision/cloud-client/web/requirements.txt +++ b/vision/cloud-client/web/requirements.txt @@ -1 +1 @@ -google-cloud-vision==0.25.0 +google-cloud-vision==0.26.0 From 1b2caee1cad82a5cdd8af6f24db4fc17e668c9d9 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Tue, 18 Jul 2017 14:58:25 -0700 Subject: [PATCH 33/36] update README to include link to the migration guide --- vision/cloud-client/crop_hints/README.rst | 6 +++++- vision/cloud-client/crop_hints/README.rst.in | 8 +++++++- vision/cloud-client/detect/README.rst | 6 +++++- vision/cloud-client/detect/README.rst.in | 8 +++++++- vision/cloud-client/document_text/README.rst | 4 ++++ vision/cloud-client/document_text/README.rst.in | 6 ++++++ vision/cloud-client/face_detection/README.rst | 6 +++++- vision/cloud-client/face_detection/README.rst.in | 8 +++++++- vision/cloud-client/quickstart/README.rst | 11 +++++++---- vision/cloud-client/quickstart/README.rst.in | 8 +++++++- vision/cloud-client/web/README.rst | 6 +++++- vision/cloud-client/web/README.rst.in | 8 +++++++- 12 files changed, 72 insertions(+), 13 deletions(-) diff --git a/vision/cloud-client/crop_hints/README.rst b/vision/cloud-client/crop_hints/README.rst index 2f21627020c..cd603359bdf 100644 --- a/vision/cloud-client/crop_hints/README.rst +++ b/vision/cloud-client/crop_hints/README.rst @@ -3,7 +3,11 @@ Google Cloud Vision API Python Samples =============================================================================== -This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content +This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. + +- See the `migration guide`_ for information about migrating to Python client library v0.27. + +.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/crop_hints/README.rst.in b/vision/cloud-client/crop_hints/README.rst.in index 5e9e7412b2c..a25b6b53302 100644 --- a/vision/cloud-client/crop_hints/README.rst.in +++ b/vision/cloud-client/crop_hints/README.rst.in @@ -8,7 +8,13 @@ product: `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of - explicit content + explicit content. + + + - See the `migration guide`_ for information about migrating to Python client library v0.27. + + + .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration setup: - auth diff --git a/vision/cloud-client/detect/README.rst b/vision/cloud-client/detect/README.rst index bb8bf95c20f..78d05a86672 100644 --- a/vision/cloud-client/detect/README.rst +++ b/vision/cloud-client/detect/README.rst @@ -3,7 +3,11 @@ Google Cloud Vision API Python Samples =============================================================================== -This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content +This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. + +- See the `migration guide`_ for information about migrating to Python client library v0.27. + +.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/detect/README.rst.in b/vision/cloud-client/detect/README.rst.in index dd9ce852759..6623fbb2be3 100644 --- a/vision/cloud-client/detect/README.rst.in +++ b/vision/cloud-client/detect/README.rst.in @@ -8,7 +8,13 @@ product: `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of - explicit content + explicit content. + + + - See the `migration guide`_ for information about migrating to Python client library v0.27. + + + .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration setup: - auth diff --git a/vision/cloud-client/document_text/README.rst b/vision/cloud-client/document_text/README.rst index 9f312d15a08..67fadc09464 100644 --- a/vision/cloud-client/document_text/README.rst +++ b/vision/cloud-client/document_text/README.rst @@ -5,6 +5,10 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. +- See the `migration guide`_ for information about migrating to Python client library v0.27. + +.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration + diff --git a/vision/cloud-client/document_text/README.rst.in b/vision/cloud-client/document_text/README.rst.in index 72117cdc7ae..da9232e1de6 100644 --- a/vision/cloud-client/document_text/README.rst.in +++ b/vision/cloud-client/document_text/README.rst.in @@ -10,6 +10,12 @@ product: landmark detection, optical character recognition (OCR), and tagging of explicit content. + + - See the `migration guide`_ for information about migrating to Python client library v0.27. + + + .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration + setup: - auth - install_deps diff --git a/vision/cloud-client/face_detection/README.rst b/vision/cloud-client/face_detection/README.rst index a80adb4a1de..b9c139bfa4d 100644 --- a/vision/cloud-client/face_detection/README.rst +++ b/vision/cloud-client/face_detection/README.rst @@ -3,7 +3,11 @@ Google Cloud Vision API Python Samples =============================================================================== -This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content +This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. + +- See the `migration guide`_ for information about migrating to Python client library v0.27. + +.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration This sample demonstrates how to use the Cloud Vision API to do face detection. diff --git a/vision/cloud-client/face_detection/README.rst.in b/vision/cloud-client/face_detection/README.rst.in index a3cb277409a..fa240b32958 100644 --- a/vision/cloud-client/face_detection/README.rst.in +++ b/vision/cloud-client/face_detection/README.rst.in @@ -8,7 +8,13 @@ product: `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of - explicit content + explicit content. + + + - See the `migration guide`_ for information about migrating to Python client library v0.27. + + + .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration description: > This sample demonstrates how to use the Cloud Vision API to do face detection. diff --git a/vision/cloud-client/quickstart/README.rst b/vision/cloud-client/quickstart/README.rst index e6c5c8ff8ad..1f31f98e51c 100644 --- a/vision/cloud-client/quickstart/README.rst +++ b/vision/cloud-client/quickstart/README.rst @@ -3,7 +3,11 @@ Google Cloud Vision API Python Samples =============================================================================== -This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content +This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. + +- See the `migration guide`_ for information about migrating to Python client library v0.27. + +.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration @@ -83,11 +87,10 @@ To run this sample: Labels: cat - mammal - whiskers + photo caption small to medium sized cats cat like mammal - animal shelter + whiskers diff --git a/vision/cloud-client/quickstart/README.rst.in b/vision/cloud-client/quickstart/README.rst.in index 4a02c8634bd..3f71571d3f2 100644 --- a/vision/cloud-client/quickstart/README.rst.in +++ b/vision/cloud-client/quickstart/README.rst.in @@ -8,7 +8,13 @@ product: `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of - explicit content + explicit content. + + + - See the `migration guide`_ for information about migrating to Python client library v0.27. + + + .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration setup: - auth diff --git a/vision/cloud-client/web/README.rst b/vision/cloud-client/web/README.rst index 0e2c54178e0..1f5a19428a1 100644 --- a/vision/cloud-client/web/README.rst +++ b/vision/cloud-client/web/README.rst @@ -3,7 +3,11 @@ Google Cloud Vision API Python Samples =============================================================================== -This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content +This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. + +- See the `migration guide`_ for information about migrating to Python client library v0.27. + +.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/web/README.rst.in b/vision/cloud-client/web/README.rst.in index abcdec01dc9..2f3e273eee4 100644 --- a/vision/cloud-client/web/README.rst.in +++ b/vision/cloud-client/web/README.rst.in @@ -8,7 +8,13 @@ product: `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of - explicit content + explicit content. + + + - See the `migration guide`_ for information about migrating to Python client library v0.27. + + + .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration setup: - auth From e74441a6e10c9fe2714a8bbbc69c062b2afd71bb Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 19 Jul 2017 09:29:54 -0700 Subject: [PATCH 34/36] correct version number --- vision/cloud-client/crop_hints/README.rst.in | 2 +- vision/cloud-client/detect/README.rst.in | 2 +- vision/cloud-client/document_text/README.rst.in | 2 +- vision/cloud-client/face_detection/README.rst.in | 2 +- vision/cloud-client/quickstart/README.rst.in | 2 +- vision/cloud-client/web/README.rst.in | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vision/cloud-client/crop_hints/README.rst.in b/vision/cloud-client/crop_hints/README.rst.in index a25b6b53302..3077586de93 100644 --- a/vision/cloud-client/crop_hints/README.rst.in +++ b/vision/cloud-client/crop_hints/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.27. + - See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/detect/README.rst.in b/vision/cloud-client/detect/README.rst.in index 6623fbb2be3..5a25d106179 100644 --- a/vision/cloud-client/detect/README.rst.in +++ b/vision/cloud-client/detect/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.27. + - See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/document_text/README.rst.in b/vision/cloud-client/document_text/README.rst.in index da9232e1de6..80021630d7a 100644 --- a/vision/cloud-client/document_text/README.rst.in +++ b/vision/cloud-client/document_text/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.27. + - See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/face_detection/README.rst.in b/vision/cloud-client/face_detection/README.rst.in index fa240b32958..46afd0d0e7e 100644 --- a/vision/cloud-client/face_detection/README.rst.in +++ b/vision/cloud-client/face_detection/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.27. + - See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/quickstart/README.rst.in b/vision/cloud-client/quickstart/README.rst.in index 3f71571d3f2..7390f3ba051 100644 --- a/vision/cloud-client/quickstart/README.rst.in +++ b/vision/cloud-client/quickstart/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.27. + - See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/web/README.rst.in b/vision/cloud-client/web/README.rst.in index 2f3e273eee4..2e48ca60dca 100644 --- a/vision/cloud-client/web/README.rst.in +++ b/vision/cloud-client/web/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.27. + - See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration From 17d68e44492025c277d8292755d14db0df827b07 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 19 Jul 2017 09:34:26 -0700 Subject: [PATCH 35/36] update readme --- vision/cloud-client/crop_hints/README.rst | 2 +- vision/cloud-client/detect/README.rst | 2 +- vision/cloud-client/document_text/README.rst | 2 +- vision/cloud-client/face_detection/README.rst | 2 +- vision/cloud-client/quickstart/README.rst | 2 +- vision/cloud-client/web/README.rst | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vision/cloud-client/crop_hints/README.rst b/vision/cloud-client/crop_hints/README.rst index cd603359bdf..b44f9317b3e 100644 --- a/vision/cloud-client/crop_hints/README.rst +++ b/vision/cloud-client/crop_hints/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.27. +- See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/detect/README.rst b/vision/cloud-client/detect/README.rst index 78d05a86672..a247817b8de 100644 --- a/vision/cloud-client/detect/README.rst +++ b/vision/cloud-client/detect/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.27. +- See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/document_text/README.rst b/vision/cloud-client/document_text/README.rst index 67fadc09464..21ada2bd078 100644 --- a/vision/cloud-client/document_text/README.rst +++ b/vision/cloud-client/document_text/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.27. +- See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/face_detection/README.rst b/vision/cloud-client/face_detection/README.rst index b9c139bfa4d..6fe0c4f263c 100644 --- a/vision/cloud-client/face_detection/README.rst +++ b/vision/cloud-client/face_detection/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.27. +- See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/quickstart/README.rst b/vision/cloud-client/quickstart/README.rst index 1f31f98e51c..d2ca239ba4c 100644 --- a/vision/cloud-client/quickstart/README.rst +++ b/vision/cloud-client/quickstart/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.27. +- See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/web/README.rst b/vision/cloud-client/web/README.rst index 1f5a19428a1..c057da05836 100644 --- a/vision/cloud-client/web/README.rst +++ b/vision/cloud-client/web/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.27. +- See the `migration guide`_ for information about migrating to Python client library v0.26. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration From 6bb04a91e9adf357ed4232a9126e0c4033aa9604 Mon Sep 17 00:00:00 2001 From: Yu-Han Liu Date: Wed, 26 Jul 2017 15:13:47 -0700 Subject: [PATCH 36/36] update client library version in requirements and readme --- vision/cloud-client/crop_hints/README.rst | 2 +- vision/cloud-client/crop_hints/README.rst.in | 2 +- vision/cloud-client/crop_hints/requirements.txt | 2 +- vision/cloud-client/detect/README.rst | 2 +- vision/cloud-client/detect/README.rst.in | 2 +- vision/cloud-client/detect/requirements.txt | 2 +- vision/cloud-client/document_text/README.rst | 2 +- vision/cloud-client/document_text/README.rst.in | 2 +- vision/cloud-client/document_text/requirements.txt | 2 +- vision/cloud-client/face_detection/README.rst | 2 +- vision/cloud-client/face_detection/README.rst.in | 2 +- vision/cloud-client/face_detection/requirements.txt | 2 +- vision/cloud-client/quickstart/README.rst | 2 +- vision/cloud-client/quickstart/README.rst.in | 2 +- vision/cloud-client/quickstart/requirements.txt | 2 +- vision/cloud-client/web/README.rst | 2 +- vision/cloud-client/web/README.rst.in | 2 +- vision/cloud-client/web/requirements.txt | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) diff --git a/vision/cloud-client/crop_hints/README.rst b/vision/cloud-client/crop_hints/README.rst index b44f9317b3e..7c70174a67b 100644 --- a/vision/cloud-client/crop_hints/README.rst +++ b/vision/cloud-client/crop_hints/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.26. +- See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/crop_hints/README.rst.in b/vision/cloud-client/crop_hints/README.rst.in index 3077586de93..80ce77589d1 100644 --- a/vision/cloud-client/crop_hints/README.rst.in +++ b/vision/cloud-client/crop_hints/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.26. + - See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/crop_hints/requirements.txt b/vision/cloud-client/crop_hints/requirements.txt index a31d4427b8b..55061efd011 100644 --- a/vision/cloud-client/crop_hints/requirements.txt +++ b/vision/cloud-client/crop_hints/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==0.26.0 +google-cloud-vision==0.25.1 pillow==4.2.1 diff --git a/vision/cloud-client/detect/README.rst b/vision/cloud-client/detect/README.rst index a247817b8de..87e9fdffe0a 100644 --- a/vision/cloud-client/detect/README.rst +++ b/vision/cloud-client/detect/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.26. +- See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/detect/README.rst.in b/vision/cloud-client/detect/README.rst.in index 5a25d106179..5ffe212923c 100644 --- a/vision/cloud-client/detect/README.rst.in +++ b/vision/cloud-client/detect/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.26. + - See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/detect/requirements.txt b/vision/cloud-client/detect/requirements.txt index 1991be8b964..c6e92fdce97 100644 --- a/vision/cloud-client/detect/requirements.txt +++ b/vision/cloud-client/detect/requirements.txt @@ -1 +1 @@ -google-cloud-vision==0.26.0 +google-cloud-vision==0.25.1 diff --git a/vision/cloud-client/document_text/README.rst b/vision/cloud-client/document_text/README.rst index 21ada2bd078..2a279890cef 100644 --- a/vision/cloud-client/document_text/README.rst +++ b/vision/cloud-client/document_text/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.26. +- See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/document_text/README.rst.in b/vision/cloud-client/document_text/README.rst.in index 80021630d7a..d4353ca0389 100644 --- a/vision/cloud-client/document_text/README.rst.in +++ b/vision/cloud-client/document_text/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.26. + - See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/document_text/requirements.txt b/vision/cloud-client/document_text/requirements.txt index a31d4427b8b..55061efd011 100644 --- a/vision/cloud-client/document_text/requirements.txt +++ b/vision/cloud-client/document_text/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==0.26.0 +google-cloud-vision==0.25.1 pillow==4.2.1 diff --git a/vision/cloud-client/face_detection/README.rst b/vision/cloud-client/face_detection/README.rst index 6fe0c4f263c..5ae062f409d 100644 --- a/vision/cloud-client/face_detection/README.rst +++ b/vision/cloud-client/face_detection/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.26. +- See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/face_detection/README.rst.in b/vision/cloud-client/face_detection/README.rst.in index 46afd0d0e7e..deb0a87b21b 100644 --- a/vision/cloud-client/face_detection/README.rst.in +++ b/vision/cloud-client/face_detection/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.26. + - See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/face_detection/requirements.txt b/vision/cloud-client/face_detection/requirements.txt index fb17f8c2491..6870b644723 100644 --- a/vision/cloud-client/face_detection/requirements.txt +++ b/vision/cloud-client/face_detection/requirements.txt @@ -1,2 +1,2 @@ -google-cloud-vision==0.26.0 +google-cloud-vision==0.25.1 Pillow==4.2.1 diff --git a/vision/cloud-client/quickstart/README.rst b/vision/cloud-client/quickstart/README.rst index d2ca239ba4c..b6e4b7484ae 100644 --- a/vision/cloud-client/quickstart/README.rst +++ b/vision/cloud-client/quickstart/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.26. +- See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/quickstart/README.rst.in b/vision/cloud-client/quickstart/README.rst.in index 7390f3ba051..10a76f1fd70 100644 --- a/vision/cloud-client/quickstart/README.rst.in +++ b/vision/cloud-client/quickstart/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.26. + - See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/quickstart/requirements.txt b/vision/cloud-client/quickstart/requirements.txt index 1991be8b964..c6e92fdce97 100644 --- a/vision/cloud-client/quickstart/requirements.txt +++ b/vision/cloud-client/quickstart/requirements.txt @@ -1 +1 @@ -google-cloud-vision==0.26.0 +google-cloud-vision==0.25.1 diff --git a/vision/cloud-client/web/README.rst b/vision/cloud-client/web/README.rst index c057da05836..52526346243 100644 --- a/vision/cloud-client/web/README.rst +++ b/vision/cloud-client/web/README.rst @@ -5,7 +5,7 @@ Google Cloud Vision API Python Samples This directory contains samples for Google Cloud Vision API. `Google Cloud Vision API`_ allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content. -- See the `migration guide`_ for information about migrating to Python client library v0.26. +- See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/web/README.rst.in b/vision/cloud-client/web/README.rst.in index 2e48ca60dca..0f4cf78487a 100644 --- a/vision/cloud-client/web/README.rst.in +++ b/vision/cloud-client/web/README.rst.in @@ -11,7 +11,7 @@ product: explicit content. - - See the `migration guide`_ for information about migrating to Python client library v0.26. + - See the `migration guide`_ for information about migrating to Python client library v0.25.1. .. _migration guide: https://cloud.google.com/vision/docs/python-client-migration diff --git a/vision/cloud-client/web/requirements.txt b/vision/cloud-client/web/requirements.txt index 1991be8b964..c6e92fdce97 100644 --- a/vision/cloud-client/web/requirements.txt +++ b/vision/cloud-client/web/requirements.txt @@ -1 +1 @@ -google-cloud-vision==0.26.0 +google-cloud-vision==0.25.1