Skip to content

Commit

Permalink
Improvess consistency in docs and fixes links in restructured text (#839
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gguuss authored and Jon Wayne Parrott committed Mar 2, 2017
1 parent 776cef0 commit e6ad76c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 88 deletions.
36 changes: 18 additions & 18 deletions vision/cloud-client/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This directory contains samples for Google Cloud Vision API. `Google Cloud Visio



.. _Google Cloud Vision API: https://cloud.google.com/vision/docs
.. _Google Cloud Vision API: https://cloud.google.com/vision/docs

Setup
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -94,24 +94,24 @@ To run this sample:
$ python detect.py
usage: detect.py [-h]
{faces,faces-uri,labels,labels-uri,landmarks,landmarks-uri,text,text-uri,logos,logos-uri,safe-search,safe-search-uri,properties,properties-uri,web,web-uri,crophints,crophints-uri,fulltext,fulltext-uri}
{faces,faces-uri,labels,labels-uri,landmarks,landmarks-uri,text,text-uri,logos,logos-uri,safe-search,safe-search-uri,properties,properties-uri,web,web-uri,crophints,crophints-uri,document,document-uri}
...
This application demonstrates how to perform basic operations with the
Google Cloud Vision API.
Example Usage:
python detect.py text ./resources/wakeupcat.jpg
python detect.py labels ./resources/landmark.jpg
python detect.py web ./resources/landmark.jpg
python detect.py web-uri http://wheresgus.com/dog.JPG
python detect.py faces-uri gs://your-bucket/file.jpg
For more information, the documentation at
https://cloud.google.com/vision/docs.
positional arguments:
{faces,faces-uri,labels,labels-uri,landmarks,landmarks-uri,text,text-uri,logos,logos-uri,safe-search,safe-search-uri,properties,properties-uri,web,web-uri,crophints,crophints-uri,fulltext,fulltext-uri}
{faces,faces-uri,labels,labels-uri,landmarks,landmarks-uri,text,text-uri,logos,logos-uri,safe-search,safe-search-uri,properties,properties-uri,web,web-uri,crophints,crophints-uri,document,document-uri}
faces Detects faces in an image.
faces-uri Detects faces in the file located in Google Cloud
Storage or the web.
Expand All @@ -133,16 +133,16 @@ To run this sample:
properties Detects image properties in the file.
properties-uri Detects image properties in the file located in Google
Cloud Storage or on the Web.
web detects web annotations given an image.
web-uri detects web annotations in the file located in google
cloud storage.
crophints detects crop hints in an image.
crophints-uri detects crop hints in the file located in google cloud
storage.
fulltext extracts full text from an image.
fulltext-uri extracts full text in the file located in google cloud
storage.
web Detects web annotations given an image.
web-uri Detects web annotations in the file located in Google
Cloud Storage.
crophints Detects crop hints in an image.
crophints-uri Detects crop hints in the file located in Google Cloud
Storage.
document Detects document features in an image.
document-uri Detects document features in the file located in
Google Cloud Storage.
optional arguments:
-h, --help show this help message and exit
Expand All @@ -164,4 +164,4 @@ to `browse the source`_ and `report issues`_.
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
.. _Google Cloud SDK: https://cloud.google.com/sdk/
.. _Google Cloud SDK: https://cloud.google.com/sdk/
99 changes: 61 additions & 38 deletions vision/cloud-client/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def detect_properties_uri(uri):


def detect_web(path):
"""detects web annotations given an image."""
"""Detects web annotations given an image."""
vision_client = vision.Client()

with io.open(path, 'rb') as image_file:
Expand Down Expand Up @@ -312,7 +312,7 @@ def detect_web(path):


def detect_web_uri(uri):
"""detects web annotations in the file located in google cloud storage."""
"""Detects web annotations in the file located in Google Cloud Storage."""
vision_client = vision.Client()
image = vision_client.image(source_uri=uri)

Expand Down Expand Up @@ -350,7 +350,7 @@ def detect_web_uri(uri):


def detect_crop_hints(path):
"""detects crop hints in an image."""
"""Detects crop hints in an image."""
vision_client = vision.Client()
with io.open(path, 'rb') as image_file:
content = image_file.read()
Expand All @@ -368,7 +368,7 @@ def detect_crop_hints(path):


def detect_crop_hints_uri(uri):
"""detects crop hints in the file located in google cloud storage."""
"""Detects crop hints in the file located in Google Cloud Storage."""
vision_client = vision.Client()
image = vision_client.image(source_uri=uri)

Expand All @@ -382,54 +382,77 @@ def detect_crop_hints_uri(uri):
print('bounds: {}'.format(','.join(vertices)))


def detect_fulltext(path):
"""extracts full text from an image."""
def detect_document(path):
"""Detects document features in an image."""
vision_client = vision.Client()

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

image = vision_client.image(content=content)

fulltext = image.detect_full_text()
document = image.detect_full_text()

for b, page in enumerate(document.pages):
page_text = ''

for b, page in enumerate(fulltext.pages):
print(page.width)
for bb, block in enumerate(page.blocks):
print('Block: {}'.format(block.bounding_box))
print('Type: {}'.format(dir(block)))
print('Type: {}'.format(block.block_type))
block_text = ''

for p, paragraph in enumerate(block.paragraphs):
print('\tParagraph: ({})'.format(paragraph.bounding_box))
print('\twords: ({})'.format((paragraph.words)))
para_text = ''

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

for s, symbol in enumerate(word.symbols):
print('\t\t\t$:{}'.format(symbol.text))
word_text = word_text + symbol.text

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

print(fulltext.text)
print('Page Content:\n{}'.format(page_text))
print('Page Dimensions: w: {} h: {}'.format(page.width, page.height))


def detect_fulltext_uri(uri):
"""extracts full text in the file located in google cloud storage."""
def detect_document_uri(uri):
"""Detects document features in the file located in Google Cloud
Storage."""
vision_client = vision.Client()
image = vision_client.image(source_uri=uri)

fulltext = image.detect_full_text()
document = image.detect_full_text()

for b, page in enumerate(document.pages):
page_text = ''

for b, page in enumerate(fulltext.pages):
print(page.width)
for bb, block in enumerate(page.blocks):
print('Block: {}'.format(block.bounding_box))
print('Type: {}'.format(dir(block)))
print('Type: {}'.format(block.block_type))
block_text = ''

for p, paragraph in enumerate(block.paragraphs):
print('\tParagraph: ({})'.format(paragraph.bounding_box))
print('\twords: ({})'.format((paragraph.words)))
para_text = ''

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

for s, symbol in enumerate(word.symbols):
print('\t\t\t$:{}'.format(symbol.text))
word_text = word_text + symbol.text

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

print(fulltext.text)
print('Page Content:\n{}'.format(page_text))
print('Page Dimensions: w: {} h: {}'.format(page.width, page.height))


def run_local(args):
Expand All @@ -451,8 +474,8 @@ def run_local(args):
detect_web(args.path)
elif args.command == 'crophints':
detect_crop_hints(args.path)
elif args.command == 'fulltext':
detect_fulltext(args.path)
elif args.command == 'document':
detect_document(args.path)


def run_uri(args):
Expand All @@ -474,8 +497,8 @@ def run_uri(args):
detect_web_uri(args.uri)
elif args.command == 'crophints-uri':
detect_crop_hints_uri(args.uri)
elif args.command == 'fulltext-uri':
detect_fulltext_uri(args.uri)
elif args.command == 'document-uri':
detect_document_uri(args.uri)


if __name__ == '__main__':
Expand Down Expand Up @@ -560,13 +583,13 @@ def run_uri(args):
'crophints-uri', help=detect_crop_hints_uri.__doc__)
crop_hints_uri_parser.add_argument('uri')

fulltext_parser = subparsers.add_parser(
'fulltext', help=detect_fulltext.__doc__)
fulltext_parser.add_argument('path')
document_parser = subparsers.add_parser(
'document', help=detect_document.__doc__)
document_parser.add_argument('path')

fulltext_uri_parser = subparsers.add_parser(
'fulltext-uri', help=detect_fulltext_uri.__doc__)
fulltext_uri_parser.add_argument('uri')
document_uri_parser = subparsers.add_parser(
'document-uri', help=detect_document_uri.__doc__)
document_uri_parser.add_argument('uri')

args = parser.parse_args()

Expand Down
Loading

0 comments on commit e6ad76c

Please sign in to comment.