Skip to content

Commit 202c6a0

Browse files
dizcologyJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
Vision GAPIC client library (#1015)
* 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
1 parent 6c20ef3 commit 202c6a0

19 files changed

+364
-154
lines changed

vision/cloud-client/crop_hints/README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
Google Cloud Vision API Python Samples
44
===============================================================================
55

6-
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
6+
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.
7+
8+
- See the `migration guide`_ for information about migrating to Python client library v0.25.1.
9+
10+
.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration
711

812

913

vision/cloud-client/crop_hints/README.rst.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ product:
88
`Google Cloud Vision API`_ allows developers to easily integrate vision
99
detection features within applications, including image labeling, face and
1010
landmark detection, optical character recognition (OCR), and tagging of
11-
explicit content
11+
explicit content.
12+
13+
14+
- See the `migration guide`_ for information about migrating to Python client library v0.25.1.
15+
16+
17+
.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration
1218

1319
setup:
1420
- auth

vision/cloud-client/crop_hints/crop_hints.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,33 @@
2626
import io
2727

2828
from google.cloud import vision
29+
from google.cloud.vision import types
2930
from PIL import Image, ImageDraw
3031
# [END imports]
3132

3233

3334
def get_crop_hint(path):
3435
# [START get_crop_hint]
3536
"""Detect crop hints on a single image and return the first result."""
36-
vision_client = vision.Client()
37+
client = vision.ImageAnnotatorClient()
3738

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

41-
image = vision_client.image(content=content)
42+
image = types.Image(content=content)
4243

43-
# Return bounds for the first crop hint using an aspect ratio of 1.77.
44-
return image.detect_crop_hints({1.77})[0].bounds.vertices
44+
crop_hints_params = types.CropHintsParams(aspect_ratios=[1.77])
45+
image_context = types.ImageContext(crop_hints_params=crop_hints_params)
46+
47+
response = client.crop_hints(image=image, image_context=image_context)
48+
hints = response.crop_hints_annotation.crop_hints
49+
50+
# Get bounds for the first crop hint using an aspect ratio of 1.77.
51+
vertices = hints[0].bounding_poly.vertices
4552
# [END get_crop_hint]
4653

54+
return vertices
55+
4756

4857
def draw_hint(image_file):
4958
"""Draw a border around the image using the hints in the vector list."""
@@ -53,10 +62,10 @@ def draw_hint(image_file):
5362
im = Image.open(image_file)
5463
draw = ImageDraw.Draw(im)
5564
draw.polygon([
56-
vects[0].x_coordinate, vects[0].y_coordinate,
57-
vects[1].x_coordinate, vects[1].y_coordinate,
58-
vects[2].x_coordinate, vects[2].y_coordinate,
59-
vects[3].x_coordinate, vects[3].y_coordinate], None, 'red')
65+
vects[0].x, vects[0].y,
66+
vects[1].x, vects[1].y,
67+
vects[2].x, vects[2].y,
68+
vects[3].x, vects[3].y], None, 'red')
6069
im.save('output-hint.jpg', 'JPEG')
6170
# [END draw_hint]
6271

@@ -67,8 +76,8 @@ def crop_to_hint(image_file):
6776
vects = get_crop_hint(image_file)
6877

6978
im = Image.open(image_file)
70-
im2 = im.crop([vects[0].x_coordinate, vects[0].y_coordinate,
71-
vects[2].x_coordinate - 1, vects[2].y_coordinate - 1])
79+
im2 = im.crop([vects[0].x, vects[0].y,
80+
vects[2].x - 1, vects[2].y - 1])
7281
im2.save('output-crop.jpg', 'JPEG')
7382
# [END crop_to_hint]
7483

vision/cloud-client/detect/README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
Google Cloud Vision API Python Samples
44
===============================================================================
55

6-
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
6+
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.
7+
8+
- See the `migration guide`_ for information about migrating to Python client library v0.25.1.
9+
10+
.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration
711

812

913

vision/cloud-client/detect/README.rst.in

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ product:
88
`Google Cloud Vision API`_ allows developers to easily integrate vision
99
detection features within applications, including image labeling, face and
1010
landmark detection, optical character recognition (OCR), and tagging of
11-
explicit content
11+
explicit content.
12+
13+
14+
- See the `migration guide`_ for information about migrating to Python client library v0.25.1.
15+
16+
17+
.. _migration guide: https://cloud.google.com/vision/docs/python-client-migration
1218

1319
setup:
1420
- auth

0 commit comments

Comments
 (0)