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

Adds document text detection tutorial. #868

Merged
merged 3 commits into from
Mar 22, 2017
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Less whitespace and fewer hanging indents
gguuss committed Mar 22, 2017
commit d3694a02af63e37289153d379ddbc1c8269f160a
16 changes: 6 additions & 10 deletions vision/cloud-client/document_text/doctext.py
Original file line number Diff line number Diff line change
@@ -44,10 +44,11 @@ def draw_boxes(image, blocks, color):
draw = ImageDraw.Draw(image)

for block in blocks:
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh nice! For the boundaries here the objects might just work too because they're x,y tuples.

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)
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)
return image
# [END draw_blocks]

@@ -65,17 +66,12 @@ def get_document_bounds(image_file, feature):
image = vision_client.image(content=content)
document = image.detect_full_text()

# Append specified feature bounds by enumerating all document features
# Collect specified feature bounds by enumerating all document features
for page in document.pages:

for block in page.blocks:

for paragraph in block.paragraphs:

for word in paragraph.words:

for symbol in word.symbols:

if (feature == FeatureType.SYMBOL):
bounds.append(symbol.bounding_box)