Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1acc945

Browse filesBrowse files
committed
Merge branch 'tmp-generated-samples' of https://github.com/GoogleCloudPlatform/python-docs-samples into tmp-generated-samples
2 parents 39ac99c + 1f8db68 commit 1acc945
Copy full SHA for 1acc945

File tree

Expand file treeCollapse file tree

3 files changed

+33
-17
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+33
-17
lines changed

‎vision/cloud-client/detect/vision_async_batch_annotate_images.py

Copy file name to clipboardExpand all lines: vision/cloud-client/detect/vision_async_batch_annotate_images.py
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
# To install the latest published package dependency, execute the following:
2020
# pip install google-cloud-vision
2121

22+
# sample-metadata
23+
# title: Async Batch Image Annotation
24+
# description: Perform async batch image annotation
25+
# usage: python3 samples/v1/vision_async_batch_annotate_images.py [--input_image_uri "gs://cloud-samples-data/vision/label/wakeupcat.jpg"] [--output_uri "gs://your-bucket/prefix/"]
2226
import sys
2327

2428
# [START vision_async_batch_annotate_images]
@@ -33,7 +37,7 @@ def sample_async_batch_annotate_images(input_image_uri, output_uri):
3337

3438
client = vision_v1.ImageAnnotatorClient()
3539

36-
# input_image_uri = 'gs://cloud-samples-data/vision/label/woman.jpg'
40+
# input_image_uri = 'gs://cloud-samples-data/vision/label/wakeupcat.jpg'
3741
# output_uri = 'gs://your-bucket/prefix/'
3842

3943
if isinstance(input_image_uri, six.binary_type):
@@ -44,11 +48,9 @@ def sample_async_batch_annotate_images(input_image_uri, output_uri):
4448
image = {'source': source}
4549
type_ = enums.Feature.Type.LABEL_DETECTION
4650
features_element = {'type': type_}
47-
type_2 = enums.Feature.Type.TEXT_DETECTION
51+
type_2 = enums.Feature.Type.IMAGE_PROPERTIES
4852
features_element_2 = {'type': type_2}
49-
type_3 = enums.Feature.Type.IMAGE_PROPERTIES
50-
features_element_3 = {'type': type_3}
51-
features = [features_element, features_element_2, features_element_3]
53+
features = [features_element, features_element_2]
5254
requests_element = {'image': image, 'features': features}
5355
requests = [requests_element]
5456
gcs_destination = {'uri': output_uri}
@@ -73,7 +75,7 @@ def main():
7375
import argparse
7476

7577
parser = argparse.ArgumentParser()
76-
parser.add_argument('--input_image_uri', type=str, default='gs://cloud-samples-data/vision/label/woman.jpg')
78+
parser.add_argument('--input_image_uri', type=str, default='gs://cloud-samples-data/vision/label/wakeupcat.jpg')
7779
parser.add_argument('--output_uri', type=str, default='gs://your-bucket/prefix/')
7880
args = parser.parse_args()
7981

‎vision/cloud-client/detect/vision_batch_annotate_files.py

Copy file name to clipboardExpand all lines: vision/cloud-client/detect/vision_batch_annotate_files.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
# To install the latest published package dependency, execute the following:
2020
# pip install google-cloud-vision
2121

22+
# sample-metadata
23+
# title:
24+
# description: Perform batch file annotation
25+
# usage: python3 samples/v1/vision_batch_annotate_files.py [--file_path "resources/kafka.pdf"]
2226
import sys
2327

2428
# [START vision_batch_annotate_files]

‎vision/cloud-client/detect/vision_batch_annotate_files_gcs.py

Copy file name to clipboardExpand all lines: vision/cloud-client/detect/vision_batch_annotate_files_gcs.py
+21-11Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
# To install the latest published package dependency, execute the following:
2020
# pip install google-cloud-vision
2121

22+
# sample-metadata
23+
# title:
24+
# description: Perform batch file annotation
25+
# usage: python3 samples/v1/vision_batch_annotate_files_gcs.py [--storage_uri "gs://cloud-samples-data/vision/document_understanding/kafka.pdf"]
2226
import sys
2327

2428
# [START vision_batch_annotate_files_gcs]
@@ -27,24 +31,31 @@
2731
from google.cloud.vision_v1 import enums
2832
import six
2933

30-
def sample_batch_annotate_files(gcs_uri):
31-
"""Perform batch file annotation"""
34+
def sample_batch_annotate_files(storage_uri):
35+
"""
36+
Perform batch file annotation
37+
38+
Args:
39+
storage_uri Cloud Storage URI to source image in the format gs://[bucket]/
40+
[file]
41+
"""
3242
# [START vision_batch_annotate_files_gcs_core]
3343

3444
client = vision_v1.ImageAnnotatorClient()
3545

36-
# gcs_uri = 'gs://cloud-samples-data/vision/document_understanding/kafka.pdf'
46+
# storage_uri = 'gs://cloud-samples-data/vision/document_understanding/kafka.pdf'
3747

38-
if isinstance(gcs_uri, six.binary_type):
39-
gcs_uri = gcs_uri.decode('utf-8')
40-
gcs_source = {'uri': gcs_uri}
48+
if isinstance(storage_uri, six.binary_type):
49+
storage_uri = storage_uri.decode('utf-8')
50+
gcs_source = {'uri': storage_uri}
4151
input_config = {'gcs_source': gcs_source}
4252
type_ = enums.Feature.Type.DOCUMENT_TEXT_DETECTION
4353
features_element = {'type': type_}
4454
features = [features_element]
4555

46-
# The service can process up to 5 pages per document file. Here we specify the
47-
# first, second, and last page of the document to be processed.
56+
# The service can process up to 5 pages per document file.
57+
# Here we specify the first, second, and last page of the document to be
58+
# processed.
4859
pages_element = 1
4960
pages_element_2 = 2
5061
pages_element_3 = -1
@@ -57,7 +68,6 @@ def sample_batch_annotate_files(gcs_uri):
5768
print('Full text: {}'.format(image_response.full_text_annotation.text))
5869
for page in image_response.full_text_annotation.pages:
5970
for block in page.blocks:
60-
# The service also returns the bounding boxes for blocks, paragraphs, words, and symbols.
6171
print('\nBlock confidence: {}'.format(block.confidence))
6272
for par in block.paragraphs:
6373
print('\tParagraph confidence: {}'.format(par.confidence))
@@ -73,10 +83,10 @@ def main():
7383
import argparse
7484

7585
parser = argparse.ArgumentParser()
76-
parser.add_argument('--gcs_uri', type=str, default='gs://cloud-samples-data/vision/document_understanding/kafka.pdf')
86+
parser.add_argument('--storage_uri', type=str, default='gs://cloud-samples-data/vision/document_understanding/kafka.pdf')
7787
args = parser.parse_args()
7888

79-
sample_batch_annotate_files(args.gcs_uri)
89+
sample_batch_annotate_files(args.storage_uri)
8090

8191
if __name__ == '__main__':
8292
main()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.