Skip to content

Commit

Permalink
Vision GAPIC client library (#1015)
Browse files Browse the repository at this point in the history
* Migrate quickstart to gapic

* formatting

* updating detect_faces, failing tests

* Migrate detect_faces to gapic

* Migrate detect_labels to gapic

* Migrate detect_landmarks to gapic

* Migrate detect_logos to gapic

* remove "Likelihood" from test outputs

* Migrate detect_safe_search to gapic

* Migrate detect_text to gapic

* Migrate detect_properties to gapic

* Migrate detect_web to gapic

* Migrate crophints to gapic

* Migrate detect_document to gapic;

* Migrate crop_hints.py to gapic

* hard code the likelihood names

* Make code snippets more self-contained

* Migrate doctext.py to gapic

* Migrate web_detect.py to gapic

* Migrate faces.py to gapic

* flake8

* fix missing string format

* remove url scores from sample output

* region tags update

* region tag correction

* move region tag in get crop hints

* move region tags

* import style

* client creation

* rename bound to vertex

* add region tags

* increment client library version

* update README to include link to the migration guide

* correct version number

* update readme

* update client library version in requirements and readme
  • Loading branch information
dizcology authored and Jon Wayne Parrott committed Jul 27, 2017
1 parent 6c20ef3 commit 202c6a0
Show file tree
Hide file tree
Showing 19 changed files with 364 additions and 154 deletions.
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
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

0 comments on commit 202c6a0

Please sign in to comment.