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 region tag update #1635

Merged
merged 23 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4eb12bd
updates region tags for face detection tutorial
alixhami Aug 10, 2018
f385d28
updates region tags for crop hints tutorial
alixhami Aug 10, 2018
86c1ca6
updates region tags for detecting-crop-hints page
alixhami Aug 10, 2018
ab42e85
updates region tags for detecting-faces page
alixhami Aug 10, 2018
52d4541
updates region tags for detecting-fulltext page
alixhami Aug 10, 2018
bcb2505
updates region tags for detecting-labels page
alixhami Aug 10, 2018
57937db
updates region tags for detecting-landmarks page
alixhami Aug 10, 2018
e4948ec
update region tags for detect-logos page
alixhami Aug 10, 2018
6f66348
update region tags for detecting-properties page
alixhami Aug 10, 2018
1c32f28
update region tags for detecting-safe-search page
alixhami Aug 10, 2018
b0b4cb0
update region tags for detecting-text page
alixhami Aug 10, 2018
969ea41
update region tags for detecting-web page
alixhami Aug 10, 2018
d2546a9
updates region tags for document text detection tutorial
alixhami Aug 10, 2018
462e422
updates region tags for web detection tutorial
alixhami Aug 10, 2018
02f8931
update beta snippet tags to standard
alixhami Aug 13, 2018
dcbbe35
update PDF detection region tags to standard
alixhami Aug 13, 2018
a21c39d
updates python migration region tags to standard
alixhami Aug 13, 2018
215a1a3
Updates product search region tags to standard
alixhami Aug 14, 2018
d51ec85
fixes region tags for face detection tutorial
alixhami Aug 14, 2018
846f067
adds import tag to face detection tutorial
alixhami Aug 14, 2018
525e3bc
fix region tags
alixhami Aug 14, 2018
4f6052c
fixes lint
alixhami Aug 15, 2018
07be308
fixes import lint
alixhami Aug 15, 2018
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
24 changes: 12 additions & 12 deletions vision/cloud-client/crop_hints/crop_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
python crop_hints.py resources/cropme.jpg draw
python crop_hints.py resources/cropme.jpg crop
"""
# [START full_tutorial]
# [START imports]
# [START vision_crop_hints_tutorial]
# [START vision_crop_hints_tutorial_imports]
import argparse
import io

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


def get_crop_hint(path):
# [START get_crop_hint]
# [START vision_crop_hints_tutorial_get_crop_hints]
"""Detect crop hints on a single image and return the first result."""
client = vision.ImageAnnotatorClient()

Expand All @@ -49,14 +49,14 @@ def get_crop_hint(path):

# Get bounds for the first crop hint using an aspect ratio of 1.77.
vertices = hints[0].bounding_poly.vertices
# [END get_crop_hint]
# [END vision_crop_hints_tutorial_get_crop_hints]

return vertices


def draw_hint(image_file):
"""Draw a border around the image using the hints in the vector list."""
# [START draw_hint]
# [START vision_crop_hints_tutorial_draw_crop_hints]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the region tag need to be consistent with the function name? here the tag says ...draw_crop_hints while the function's name is draw_hint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The region tag does not need to have the same name as the function

vects = get_crop_hint(image_file)

im = Image.open(image_file)
Expand All @@ -67,23 +67,23 @@ def draw_hint(image_file):
vects[2].x, vects[2].y,
vects[3].x, vects[3].y], None, 'red')
im.save('output-hint.jpg', 'JPEG')
# [END draw_hint]
# [END vision_crop_hints_tutorial_draw_crop_hints]


def crop_to_hint(image_file):
"""Crop the image using the hints in the vector list."""
# [START crop_to_hint]
# [START vision_crop_hints_tutorial_crop_to_hints]
vects = get_crop_hint(image_file)

im = Image.open(image_file)
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]
# [END vision_crop_hints_tutorial_crop_to_hints]


if __name__ == '__main__':
# [START run_crop]
# [START vision_crop_hints_tutorial_run_application]
parser = argparse.ArgumentParser()
parser.add_argument('image_file', help='The image you\'d like to crop.')
parser.add_argument('mode', help='Set to "crop" or "draw".')
Expand All @@ -95,5 +95,5 @@ def crop_to_hint(image_file):
crop_to_hint(args.image_file)
elif args.mode == 'draw':
draw_hint(args.image_file)
# [END run_crop]
# [END full_tutorial]
# [END vision_crop_hints_tutorial_run_application]
# [END vision_crop_hints_tutorial]
8 changes: 4 additions & 4 deletions vision/cloud-client/detect/beta_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def localize_objects(path):
# [END vision_localize_objects]


# [START vision_localize_objects_uri]
# [START vision_localize_objects_gcs]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i remember correctly the API accepts both GCS URI and HTTP URI, in this case the gcs suffix might not be appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_gcs and _uri were previously inconsistently used across languages and samples. I standardized to choose _gcs when it was a GCS URI. I will keep in mind to change if it is an HTTP URI.

def localize_objects_uri(uri):
"""Localize objects in the image on Google Cloud Storage

Expand All @@ -81,7 +81,7 @@ def localize_objects_uri(uri):
print('Normalized bounding polygon vertices: ')
for vertex in object_.bounding_poly.normalized_vertices:
print(' - ({}, {})'.format(vertex.x, vertex.y))
# [END vision_localize_objects_uri]
# [END vision_localize_objects_gcs]


# [START vision_handwritten_ocr]
Expand Down Expand Up @@ -130,7 +130,7 @@ def detect_handwritten_ocr(path):
# [END vision_handwritten_ocr]


# [START vision_handwritten_ocr_uri]
# [START vision_handwritten_ocr_gcs]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the other hand here i think the uri must be a GCS uri.

def detect_handwritten_ocr_uri(uri):
"""Detects handwritten characters in the file located in Google Cloud
Storage.
Expand Down Expand Up @@ -171,7 +171,7 @@ def detect_handwritten_ocr_uri(uri):
for symbol in word.symbols:
print('\tSymbol: {} (confidence: {})'.format(
symbol.text, symbol.confidence))
# [END vision_handwritten_ocr_uri]
# [END vision_handwritten_ocr_gcs]


if __name__ == '__main__':
Expand Down
Loading