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

An attempt at flattening the detect example #873

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Changes from all commits
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
70 changes: 26 additions & 44 deletions vision/cloud-client/detect/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,31 +393,22 @@ def detect_document(path):

document = image.detect_full_text()

for b, page in enumerate(document.pages):
page_text = ''
for page in document.pages:
for block in page.blocks:
block_words = []
for paragraph in block.paragraphs:
block_words.extend(paragraph.words)

for bb, block in enumerate(page.blocks):
block_text = ''

for p, paragraph in enumerate(block.paragraphs):
para_text = ''

for w, word in enumerate(paragraph.words):
word_text = ''

for s, symbol in enumerate(word.symbols):
word_text = word_text + symbol.text
block_symbols = []
for word in block_words:
block_symbols.extend(word.symbols)

para_text = para_text + word_text

block_text = block_text + para_text
print('\n--\nContent Block: {}'.format(block_text))
print('Block Bounding Box:\n{}'.format(block.bounding_box))

page_text = page_text + block_text
block_text = ''
for symbol in block_symbols:
block_text = block_text + symbol.text

print('Page Content:\n{}'.format(page_text))
print('Page Dimensions: w: {} h: {}'.format(page.width, page.height))
print('Block Content: {}'.format(block_text))
print('Block Bounds:\n {}'.format(block.bounding_box))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would this be better if written similar to:

        vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate)
                    for bound in face.bounds.vertices])

Copy link
Contributor

Choose a reason for hiding this comment

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

What does the repr look like right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Block Content: Back
Block Bounds:
 vertices {
  x: 134
  y: 852
}
vertices {
  x: 191
  y: 857
}
vertices {
  x: 189
  y: 873
}
vertices {
  x: 132
  y: 868
}

Block Content: 37%
Block Bounds:
 vertices {
  x: 712
  y: 699
}
vertices {
  x: 758
  y: 702
}
vertices {
  x: 757
  y: 718
}
vertices {
  x: 711
  y: 715
}

Copy link
Contributor

Choose a reason for hiding this comment

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

It's fine as-is.



def detect_document_uri(uri):
Expand All @@ -428,31 +419,22 @@ def detect_document_uri(uri):

document = image.detect_full_text()

for b, page in enumerate(document.pages):
page_text = ''
for page in document.pages:
for block in page.blocks:
block_words = []
for paragraph in block.paragraphs:
block_words.extend(paragraph.words)

for bb, block in enumerate(page.blocks):
block_text = ''

for p, paragraph in enumerate(block.paragraphs):
para_text = ''

for w, word in enumerate(paragraph.words):
word_text = ''

for s, symbol in enumerate(word.symbols):
word_text = word_text + symbol.text
block_symbols = []
for word in block_words:
block_symbols.extend(word.symbols)

para_text = para_text + word_text

block_text = block_text + para_text
print('\n--\nContent Block: {}'.format(block_text))
print('Block Bounding Box:\n{}'.format(block.bounding_box))

page_text = page_text + block_text
block_text = ''
for symbol in block_symbols:
block_text = block_text + symbol.text

print('Page Content:\n{}'.format(page_text))
print('Page Dimensions: w: {} h: {}'.format(page.width, page.height))
print('Block Content: {}'.format(block_text))
print('Block Bounds:\n {}'.format(block.bounding_box))


def run_local(args):
Expand Down