Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vision GAPIC client library #1015

Merged
merged 36 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4ca8a84
Migrate quickstart to gapic
dizcology Jun 27, 2017
91b07c0
formatting
dizcology Jun 27, 2017
3cd44bb
updating detect_faces, failing tests
dizcology Jun 27, 2017
1ec2eef
Migrate detect_faces to gapic
dizcology Jun 27, 2017
b776c64
Migrate detect_labels to gapic
dizcology Jun 27, 2017
5b27f6d
Migrate detect_landmarks to gapic
dizcology Jun 27, 2017
1439545
Migrate detect_logos to gapic
dizcology Jun 27, 2017
27238f1
remove "Likelihood" from test outputs
dizcology Jun 27, 2017
ceb206b
Migrate detect_safe_search to gapic
dizcology Jun 27, 2017
073f8b6
Migrate detect_text to gapic
dizcology Jun 27, 2017
aa03a59
Migrate detect_properties to gapic
dizcology Jun 27, 2017
7f96de3
Migrate detect_web to gapic
dizcology Jun 27, 2017
0d100db
Migrate crophints to gapic
dizcology Jun 28, 2017
af855ee
Migrate detect_document to gapic;
dizcology Jun 28, 2017
6498113
Migrate crop_hints.py to gapic
dizcology Jun 28, 2017
328390b
hard code the likelihood names
dizcology Jun 28, 2017
54021a3
Make code snippets more self-contained
dizcology Jun 28, 2017
05c48df
Migrate doctext.py to gapic
dizcology Jun 28, 2017
f6595f6
Migrate web_detect.py to gapic
dizcology Jun 28, 2017
fe57c07
Migrate faces.py to gapic
dizcology Jun 28, 2017
4977de9
flake8
dizcology Jun 28, 2017
e43c090
fix missing string format
dizcology Jun 29, 2017
389251e
remove url scores from sample output
dizcology Jun 29, 2017
d150fe1
region tags update
dizcology Jul 5, 2017
ecc5ea8
region tag correction
dizcology Jul 5, 2017
b70b687
move region tag in get crop hints
dizcology Jul 5, 2017
1f41a32
move region tags
dizcology Jul 5, 2017
3265d50
import style
dizcology Jul 7, 2017
4edd3af
client creation
dizcology Jul 7, 2017
7fb9d82
rename bound to vertex
dizcology Jul 7, 2017
eb4ef64
add region tags
dizcology Jul 17, 2017
1d7abbd
increment client library version
dizcology Jul 18, 2017
1b2caee
update README to include link to the migration guide
dizcology Jul 18, 2017
e74441a
correct version number
dizcology Jul 19, 2017
17d68e4
update readme
dizcology Jul 19, 2017
6bb04a9
update client library version in requirements and readme
dizcology Jul 26, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion vision/cloud-client/crop_hints/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.25.1.

.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration



Expand Down
8 changes: 7 additions & 1 deletion vision/cloud-client/crop_hints/README.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.25.1.


.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration

setup:
- auth
Expand Down
29 changes: 19 additions & 10 deletions vision/cloud-client/crop_hints/crop_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,33 @@
import io

from google.cloud import vision
from google.cloud.vision import types
from PIL import Image, ImageDraw
# [END imports]


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 = vision.ImageAnnotatorClient()

with io.open(path, 'rb') as image_file:
content = image_file.read()

image = vision_client.image(content=content)
image = types.Image(content=content)

# Return bounds for the first crop hint using an aspect ratio of 1.77.
return image.detect_crop_hints({1.77})[0].bounds.vertices
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

# 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."""
Expand All @@ -53,10 +62,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]

Expand All @@ -67,8 +76,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]

Expand Down
2 changes: 1 addition & 1 deletion vision/cloud-client/crop_hints/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
google-cloud-vision==0.25.0
google-cloud-vision==0.25.1
pillow==4.2.1
6 changes: 5 additions & 1 deletion vision/cloud-client/detect/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.25.1.

.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration



Expand Down
8 changes: 7 additions & 1 deletion vision/cloud-client/detect/README.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.25.1.


.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration

setup:
- auth
Expand Down
Loading