From 4eb12bd8546523e07c0c1bf60bc0192554fca369 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 12:08:59 -0700 Subject: [PATCH 01/23] updates region tags for face detection tutorial --- vision/cloud-client/face_detection/faces.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 25a40763b338..2fc2daf2b20c 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -18,14 +18,14 @@ import argparse -# [START import_client_library] +# [START vision_face_detection_tutorial_client] from google.cloud import vision -# [END import_client_library] from google.cloud.vision import types from PIL import Image, ImageDraw +# [END vision_face_detection_tutorial_client] -# [START def_detect_face] +# [START vision_face_detection_send_request] def detect_face(face_file, max_results=4): """Uses the Vision API to detect faces in the given file. @@ -35,18 +35,18 @@ def detect_face(face_file, max_results=4): Returns: An array of Face objects with information about the picture. """ - # [START get_vision_service] + # [START vision_face_detection_tutorial_client] client = vision.ImageAnnotatorClient() - # [END get_vision_service] + # [END vision_face_detection_tutorial_client] content = face_file.read() image = types.Image(content=content) return client.face_detection(image=image).face_annotations -# [END def_detect_face] +# [END vision_face_detection_send_request] -# [START def_highlight_faces] +# [START vision_face_detection_process_response] def highlight_faces(image, faces, output_filename): """Draws a polygon around the faces, then saves to output_filename. @@ -66,10 +66,10 @@ def highlight_faces(image, faces, output_filename): draw.line(box + [box[0]], width=5, fill='#00ff00') im.save(output_filename) -# [END def_highlight_faces] +# [END vision_face_detection_process_response] -# [START def_main] +# [START vision_face_detection_run_application] def main(input_filename, output_filename, max_results): with open(input_filename, 'rb') as image: faces = detect_face(image, max_results) @@ -80,7 +80,7 @@ def main(input_filename, output_filename, max_results): # Reset the file pointer, so we can read the file again image.seek(0) highlight_faces(image, faces, output_filename) -# [END def_main] +# [END vision_face_detection_run_application] if __name__ == '__main__': From f385d28596266e94a01381f17c9b3f3d8a566eb0 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 12:32:50 -0700 Subject: [PATCH 02/23] updates region tags for crop hints tutorial --- vision/cloud-client/crop_hints/crop_hints.py | 24 ++++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/vision/cloud-client/crop_hints/crop_hints.py b/vision/cloud-client/crop_hints/crop_hints.py index 3120fe2fbe4b..22ca7dbf460e 100644 --- a/vision/cloud-client/crop_hints/crop_hints.py +++ b/vision/cloud-client/crop_hints/crop_hints.py @@ -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() @@ -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] vects = get_crop_hint(image_file) im = Image.open(image_file) @@ -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".') @@ -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] From 86c1ca62151a7d11ee080ff9ddd486719f7a3a7f Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 13:04:14 -0700 Subject: [PATCH 03/23] updates region tags for detecting-crop-hints page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 7a15430d625f..934acaa73efb 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -523,7 +523,7 @@ def web_entities_include_geo_results_uri(uri): # [END vision_web_entities_include_geo_results_uri] -# [START def_detect_crop_hints] +# [START vision_crop_hint_detection] def detect_crop_hints(path): """Detects crop hints in an image.""" client = vision.ImageAnnotatorClient() @@ -548,10 +548,10 @@ def detect_crop_hints(path): print('bounds: {}'.format(','.join(vertices))) # [END migration_crop_hints] -# [END def_detect_crop_hints] +# [END vision_crop_hint_detection] -# [START def_detect_crop_hints_uri] +# [START vision_crop_hint_detection_gcs] def detect_crop_hints_uri(uri): """Detects crop hints in the file located in Google Cloud Storage.""" client = vision.ImageAnnotatorClient() @@ -572,7 +572,7 @@ def detect_crop_hints_uri(uri): for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) -# [END def_detect_crop_hints_uri] +# [END vision_crop_hint_detection_gcs] # [START def_detect_document] From ab42e8512989a2e5446587b5e36867ef872cc4b0 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 13:20:21 -0700 Subject: [PATCH 04/23] updates region tags for detecting-faces page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 934acaa73efb..7ffd52a422ac 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -40,7 +40,7 @@ from google.protobuf import json_format -# [START def_detect_faces] +# [START vision_face_detection] def detect_faces(path): """Detects faces in an image.""" client = vision.ImageAnnotatorClient() @@ -71,10 +71,10 @@ def detect_faces(path): print('face bounds: {}'.format(','.join(vertices))) # [END migration_face_detection] -# [END def_detect_faces] +# [END vision_face_detection] -# [START def_detect_faces_uri] +# [START vision_face_detection_gcs] def detect_faces_uri(uri): """Detects faces in the file located in Google Cloud Storage or the web.""" client = vision.ImageAnnotatorClient() @@ -100,7 +100,7 @@ def detect_faces_uri(uri): for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) -# [END def_detect_faces_uri] +# [END vision_face_detection_gcs] # [START def_detect_labels] From 52d4541adc5c081ae46df9e518807f6dbbcd2d75 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 13:36:13 -0700 Subject: [PATCH 05/23] updates region tags for detecting-fulltext page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 7ffd52a422ac..e7dfc6459ee6 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -575,7 +575,7 @@ def detect_crop_hints_uri(uri): # [END vision_crop_hint_detection_gcs] -# [START def_detect_document] +# [START vision_fulltext_detection] def detect_document(path): """Detects document features in an image.""" client = vision.ImageAnnotatorClient() @@ -607,10 +607,10 @@ def detect_document(path): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) # [END migration_document_text_detection] -# [END def_detect_document] +# [END vision_fulltext_detection] -# [START def_detect_document_uri] +# [START vision_fulltext_detection_gcs] def detect_document_uri(uri): """Detects document features in the file located in Google Cloud Storage.""" @@ -638,7 +638,7 @@ def detect_document_uri(uri): for symbol in word.symbols: print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) -# [END def_detect_document_uri] +# [END vision_fulltext_detection_gcs] # [START vision_async_detect_document_ocr] From bcb2505d6fbac62cd604e7e8187d28a1d6a8379e Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 13:54:41 -0700 Subject: [PATCH 06/23] updates region tags for detecting-labels page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index e7dfc6459ee6..f58ff5b3d345 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -103,7 +103,7 @@ def detect_faces_uri(uri): # [END vision_face_detection_gcs] -# [START def_detect_labels] +# [START vision_label_detection] def detect_labels(path): """Detects labels in the file.""" client = vision.ImageAnnotatorClient() @@ -121,10 +121,10 @@ def detect_labels(path): for label in labels: print(label.description) # [END migration_label_detection] -# [END def_detect_labels] +# [END vision_label_detection] -# [START def_detect_labels_uri] +# [START vision_label_detection_gcs] def detect_labels_uri(uri): """Detects labels in the file located in Google Cloud Storage or on the Web.""" @@ -138,7 +138,7 @@ def detect_labels_uri(uri): for label in labels: print(label.description) -# [END def_detect_labels_uri] +# [END vision_label_detection_gcs] # [START def_detect_landmarks] From 57937db8f3add248493afd3c2bc04adb820659fb Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 14:04:02 -0700 Subject: [PATCH 07/23] updates region tags for detecting-landmarks page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index f58ff5b3d345..a42fe52dd440 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -141,7 +141,7 @@ def detect_labels_uri(uri): # [END vision_label_detection_gcs] -# [START def_detect_landmarks] +# [START vision_landmark_detection] def detect_landmarks(path): """Detects landmarks in the file.""" client = vision.ImageAnnotatorClient() @@ -163,10 +163,10 @@ def detect_landmarks(path): print('Latitude {}'.format(lat_lng.latitude)) print('Longitude {}'.format(lat_lng.longitude)) # [END migration_landmark_detection] -# [END def_detect_landmarks] +# [END vision_landmark_detection] -# [START def_detect_landmarks_uri] +# [START vision_landmark_detection_gcs] def detect_landmarks_uri(uri): """Detects landmarks in the file located in Google Cloud Storage or on the Web.""" @@ -180,7 +180,7 @@ def detect_landmarks_uri(uri): for landmark in landmarks: print(landmark.description) -# [END def_detect_landmarks_uri] +# [END vision_landmark_detection_gcs] # [START def_detect_logos] From e4948ec8cc7809b004d24d7fffbbc11f651fa6d6 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 14:11:21 -0700 Subject: [PATCH 08/23] update region tags for detect-logos page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index a42fe52dd440..f77cc2a43680 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -183,7 +183,7 @@ def detect_landmarks_uri(uri): # [END vision_landmark_detection_gcs] -# [START def_detect_logos] +# [START vision_logo_detection] def detect_logos(path): """Detects logos in the file.""" client = vision.ImageAnnotatorClient() @@ -201,10 +201,10 @@ def detect_logos(path): for logo in logos: print(logo.description) # [END migration_logo_detection] -# [END def_detect_logos] +# [END vision_logo_detection] -# [START def_detect_logos_uri] +# [START vision_logo_detection_gcs] def detect_logos_uri(uri): """Detects logos in the file located in Google Cloud Storage or on the Web. """ @@ -218,7 +218,7 @@ def detect_logos_uri(uri): for logo in logos: print(logo.description) -# [END def_detect_logos_uri] +# [END vision_logo_detection_gcs] # [START def_detect_safe_search] From 6f66348ab77e9eb20412ea358449d83cdb012889 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 14:20:13 -0700 Subject: [PATCH 09/23] update region tags for detecting-properties page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index f77cc2a43680..7131b479f9c3 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -321,7 +321,7 @@ def detect_text_uri(uri): # [END def_detect_text_uri] -# [START def_detect_properties] +# [START vision_image_property_detection] def detect_properties(path): """Detects image properties in the file.""" client = vision.ImageAnnotatorClient() @@ -343,10 +343,10 @@ def detect_properties(path): print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) # [END migration_image_properties] -# [END def_detect_properties] +# [END vision_image_property_detection] -# [START def_detect_properties_uri] +# [START vision_image_property_detection_gcs] def detect_properties_uri(uri): """Detects image properties in the file located in Google Cloud Storage or on the Web.""" @@ -364,7 +364,7 @@ def detect_properties_uri(uri): print('\tg: {}'.format(color.color.green)) print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) -# [END def_detect_properties_uri] +# [END vision_image_property_detection_gcs] # [START def_detect_web] From 1c32f28b21da5cb7c797fc35ff133f5521e473e6 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 15:13:55 -0700 Subject: [PATCH 10/23] update region tags for detecting-safe-search page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 7131b479f9c3..83f07d62f70f 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -221,7 +221,7 @@ def detect_logos_uri(uri): # [END vision_logo_detection_gcs] -# [START def_detect_safe_search] +# [START vision_safe_search_detection] def detect_safe_search(path): """Detects unsafe features in the file.""" client = vision.ImageAnnotatorClient() @@ -246,10 +246,10 @@ def detect_safe_search(path): print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) # [END migration_safe_search_detection] -# [END def_detect_safe_search] +# [END vision_safe_search_detection] -# [START def_detect_safe_search_uri] +# [START vision_safe_search_detection_gcs] def detect_safe_search_uri(uri): """Detects unsafe features in the file located in Google Cloud Storage or on the Web.""" @@ -270,7 +270,7 @@ def detect_safe_search_uri(uri): print('spoofed: {}'.format(likelihood_name[safe.spoof])) print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) -# [END def_detect_safe_search_uri] +# [END vision_safe_search_detection_gcs] # [START def_detect_text] From b0b4cb083e94742f7e5dc4797db4cee711245255 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 15:22:08 -0700 Subject: [PATCH 11/23] update region tags for detecting-text page --- vision/cloud-client/detect/detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 83f07d62f70f..8bdb78918130 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -273,7 +273,7 @@ def detect_safe_search_uri(uri): # [END vision_safe_search_detection_gcs] -# [START def_detect_text] +# [START vision_text_detection] def detect_text(path): """Detects text in the file.""" client = vision.ImageAnnotatorClient() @@ -296,10 +296,10 @@ def detect_text(path): print('bounds: {}'.format(','.join(vertices))) # [END migration_text_detection] -# [END def_detect_text] +# [END vision_text_detection] -# [START def_detect_text_uri] +# [START vision_text_detection_gcs] def detect_text_uri(uri): """Detects text in the file located in Google Cloud Storage or on the Web. """ @@ -318,7 +318,7 @@ def detect_text_uri(uri): for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) -# [END def_detect_text_uri] +# [END vision_text_detection_gcs] # [START vision_image_property_detection] From 969ea41fd6f2dd92c1daed753433c4bc8d141ee9 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 15:30:52 -0700 Subject: [PATCH 12/23] update region tags for detecting-web page --- vision/cloud-client/detect/detect.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 8bdb78918130..eccbb24bc819 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -367,7 +367,7 @@ def detect_properties_uri(uri): # [END vision_image_property_detection_gcs] -# [START def_detect_web] +# [START vision_web_detection] def detect_web(path): """Detects web annotations given an image.""" client = vision.ImageAnnotatorClient() @@ -421,10 +421,10 @@ def detect_web(path): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) # [END migration_web_detection] -# [END def_detect_web] +# [END vision_web_detection] -# [START def_detect_web_uri] +# [START vision_web_detection_gcs] def detect_web_uri(uri): """Detects web annotations in the file located in Google Cloud Storage.""" client = vision.ImageAnnotatorClient() @@ -473,10 +473,10 @@ def detect_web_uri(uri): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) -# [END def_detect_web_uri] +# [END vision_web_detection_gcs] -# [START vision_web_entities_include_geo_results] +# [START vision_web_detection_include_geo] def web_entities_include_geo_results(path): """Detects web annotations given an image, using the geotag metadata in the iamge to detect web entities.""" @@ -497,10 +497,10 @@ def web_entities_include_geo_results(path): for entity in response.web_detection.web_entities: print('\n\tScore : {}'.format(entity.score)) print(u'\tDescription: {}'.format(entity.description)) -# [END vision_web_entities_include_geo_results] +# [END vision_web_detection_include_geo] -# [START vision_web_entities_include_geo_results_uri] +# [START vision_web_detection_include_geo_gcs] def web_entities_include_geo_results_uri(uri): """Detects web annotations given an image in the file located in Google Cloud Storage., using the geotag metadata in the iamge to @@ -520,7 +520,7 @@ def web_entities_include_geo_results_uri(uri): for entity in response.web_detection.web_entities: print('\n\tScore : {}'.format(entity.score)) print(u'\tDescription: {}'.format(entity.description)) -# [END vision_web_entities_include_geo_results_uri] +# [END vision_web_detection_include_geo_gcs] # [START vision_crop_hint_detection] From d2546a9a91fad22c23f758b1d0d6f989fe053d84 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 16:07:47 -0700 Subject: [PATCH 13/23] updates region tags for document text detection tutorial --- vision/cloud-client/document_text/doctext.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/vision/cloud-client/document_text/doctext.py b/vision/cloud-client/document_text/doctext.py index 478f2e22731a..097878afc8e1 100644 --- a/vision/cloud-client/document_text/doctext.py +++ b/vision/cloud-client/document_text/doctext.py @@ -19,8 +19,8 @@ Example: python doctext.py resources/text_menu.jpg """ -# [START full_tutorial] -# [START imports] +# [START vision_document_text_tutorial] +# [START vision_document_text_tutorial_imports] import argparse from enum import Enum import io @@ -28,7 +28,7 @@ from google.cloud import vision from google.cloud.vision import types from PIL import Image, ImageDraw -# [END imports] +# [END vision_document_text_tutorial_imports] class FeatureType(Enum): @@ -41,7 +41,6 @@ class FeatureType(Enum): def draw_boxes(image, bounds, color): """Draw a border around the image using the hints in the vector list.""" - # [START draw_blocks] draw = ImageDraw.Draw(image) for bound in bounds: @@ -51,11 +50,10 @@ def draw_boxes(image, bounds, color): bound.vertices[2].x, bound.vertices[2].y, bound.vertices[3].x, bound.vertices[3].y], None, color) return image - # [END draw_blocks] def get_document_bounds(image_file, feature): - # [START detect_bounds] + # [START vision_document_text_tutorial_detect_bounds] """Returns document bounds given an image.""" client = vision.ImageAnnotatorClient() @@ -91,12 +89,11 @@ def get_document_bounds(image_file, feature): bounds.append(block.bounding_box) # The list `bounds` contains the coordinates of the bounding boxes. - # [END detect_bounds] + # [END vision_document_text_tutorial_detect_bounds] return bounds def render_doc_text(filein, fileout): - # [START render_doc_text] image = Image.open(filein) bounds = get_document_bounds(filein, FeatureType.PAGE) draw_boxes(image, bounds, 'blue') @@ -109,11 +106,10 @@ def render_doc_text(filein, fileout): image.save(fileout) else: image.show() - # [END render_doc_text] if __name__ == '__main__': - # [START run_doc_text] + # [START vision_document_text_tutorial_run_application] parser = argparse.ArgumentParser() parser.add_argument('detect_file', help='The image for text detection.') parser.add_argument('-out_file', help='Optional output file', default=0) @@ -121,5 +117,5 @@ def render_doc_text(filein, fileout): parser = argparse.ArgumentParser() render_doc_text(args.detect_file, args.out_file) - # [END run_doc_text] -# [END full_tutorial] + # [END vision_document_text_tutorial_run_application] +# [END vision_document_text_tutorial] From 462e42273bd53de512a1041defc2b5a277e34e43 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Fri, 10 Aug 2018 16:13:44 -0700 Subject: [PATCH 14/23] updates region tags for web detection tutorial --- vision/cloud-client/web/web_detect.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index 0b3e72f901e0..a6e0915dc037 100644 --- a/vision/cloud-client/web/web_detect.py +++ b/vision/cloud-client/web/web_detect.py @@ -21,19 +21,19 @@ python web_detect.py ../detect/resources/landmark.jpg python web_detect.py gs://your-bucket/image.png """ -# [START full_tutorial] -# [START imports] +# [START vision_web_detection_tutorial] +# [START vision_web_detection_tutorial_imports] import argparse import io from google.cloud import vision from google.cloud.vision import types -# [END imports] +# [END vision_web_detection_tutorial_imports] def annotate(path): """Returns web annotations given the path to an image.""" - # [START get_annotations] + # [START vision_web_detection_tutorial_annotate] client = vision.ImageAnnotatorClient() if path.startswith('http') or path.startswith('gs:'): @@ -47,14 +47,14 @@ def annotate(path): image = types.Image(content=content) web_detection = client.web_detection(image=image).web_detection - # [END get_annotations] + # [END vision_web_detection_tutorial_annotate] return web_detection def report(annotations): """Prints detected features in the provided web annotations.""" - # [START print_annotations] + # [START vision_web_detection_tutorial_print_annotations] if annotations.pages_with_matching_images: print('\n{} Pages with matching images retrieved'.format( len(annotations.pages_with_matching_images))) @@ -83,11 +83,11 @@ def report(annotations): for entity in annotations.web_entities: print('Score : {}'.format(entity.score)) print('Description: {}'.format(entity.description)) - # [END print_annotations] + # [END vision_web_detection_tutorial_print_annotations] if __name__ == '__main__': - # [START run_web] + # [START vision_web_detection_tutorial_run_application] parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) @@ -97,5 +97,5 @@ def report(annotations): args = parser.parse_args() report(annotate(args.image_url)) - # [END run_web] -# [END full_tutorial] + # [END vision_web_detection_tutorial_run_application] +# [END vision_web_detection_tutorial] From 02f8931ed6bb974c2e45c9094ee251aba063b563 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Mon, 13 Aug 2018 10:49:03 -0700 Subject: [PATCH 15/23] update beta snippet tags to standard --- vision/cloud-client/detect/beta_snippets.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/beta_snippets.py b/vision/cloud-client/detect/beta_snippets.py index 0668b377c20b..ed7ef6ca7fd8 100644 --- a/vision/cloud-client/detect/beta_snippets.py +++ b/vision/cloud-client/detect/beta_snippets.py @@ -59,7 +59,7 @@ def localize_objects(path): # [END vision_localize_objects] -# [START vision_localize_objects_uri] +# [START vision_localize_objects_gcs] def localize_objects_uri(uri): """Localize objects in the image on Google Cloud Storage @@ -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] @@ -130,7 +130,7 @@ def detect_handwritten_ocr(path): # [END vision_handwritten_ocr] -# [START vision_handwritten_ocr_uri] +# [START vision_handwritten_ocr_gcs] def detect_handwritten_ocr_uri(uri): """Detects handwritten characters in the file located in Google Cloud Storage. @@ -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__': From dcbbe351724bbf3049832b4dab531329e78d1a2e Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Mon, 13 Aug 2018 14:16:15 -0700 Subject: [PATCH 16/23] update PDF detection region tags to standard --- vision/cloud-client/detect/detect.py | 4 ++-- vision/cloud-client/detect/detect_pdf.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index eccbb24bc819..75eb095d1ff3 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -641,7 +641,7 @@ def detect_document_uri(uri): # [END vision_fulltext_detection_gcs] -# [START vision_async_detect_document_ocr] +# [START vision_text_detection_pdf_gcs] def async_detect_document(gcs_source_uri, gcs_destination_uri): """OCR with PDF/TIFF as source files on GCS""" # Supported mime_types are: 'application/pdf' and 'image/tiff' @@ -708,7 +708,7 @@ def async_detect_document(gcs_source_uri, gcs_destination_uri): # including confidence scores and bounding boxes print(u'Full text:\n{}'.format( annotation.text)) -# [END vision_async_detect_document_ocr] +# [END vision_text_detection_pdf_gcs] def run_local(args): diff --git a/vision/cloud-client/detect/detect_pdf.py b/vision/cloud-client/detect/detect_pdf.py index a728d0522a58..f7e8abed42d2 100644 --- a/vision/cloud-client/detect/detect_pdf.py +++ b/vision/cloud-client/detect/detect_pdf.py @@ -31,7 +31,7 @@ from google.protobuf import json_format -# [START vision_async_detect_document_ocr] +# [START vision_text_detection_pdf_gcs] def async_detect_document(gcs_source_uri, gcs_destination_uri): # Supported mime_types are: 'application/pdf' and 'image/tiff' mime_type = 'application/pdf' @@ -98,7 +98,7 @@ def async_detect_document(gcs_source_uri, gcs_destination_uri): # including confidence scores and bounding boxes print(u'Full text:\n{}'.format( annotation.text)) -# [END vision_async_detect_document_ocr] +# [END vision_text_detection_pdf_gcs] if __name__ == '__main__': From a21c39d91d8b39c3ddc86502573056115fc392d7 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Mon, 13 Aug 2018 14:45:34 -0700 Subject: [PATCH 17/23] updates python migration region tags to standard --- vision/cloud-client/detect/detect.py | 48 ++++++++++---------- vision/cloud-client/quickstart/quickstart.py | 8 ++-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 75eb095d1ff3..d4033d6ba3b0 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -45,13 +45,13 @@ def detect_faces(path): """Detects faces in an image.""" client = vision.ImageAnnotatorClient() - # [START migration_face_detection] - # [START migration_image_file] + # [START vision_python_migration_face_detection] + # [START vision_python_migration_image_file] with io.open(path, 'rb') as image_file: content = image_file.read() image = vision.types.Image(content=content) - # [END migration_image_file] + # [END vision_python_migration_image_file] response = client.face_detection(image=image) faces = response.face_annotations @@ -70,7 +70,7 @@ def detect_faces(path): for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) - # [END migration_face_detection] + # [END vision_python_migration_face_detection] # [END vision_face_detection] @@ -78,10 +78,10 @@ def detect_faces(path): def detect_faces_uri(uri): """Detects faces in the file located in Google Cloud Storage or the web.""" client = vision.ImageAnnotatorClient() - # [START migration_image_uri] + # [START vision_python_migration_image_uri] image = vision.types.Image() image.source.image_uri = uri - # [END migration_image_uri] + # [END vision_python_migration_image_uri] response = client.face_detection(image=image) faces = response.face_annotations @@ -108,7 +108,7 @@ def detect_labels(path): """Detects labels in the file.""" client = vision.ImageAnnotatorClient() - # [START migration_label_detection] + # [START vision_python_migration_label_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -120,7 +120,7 @@ def detect_labels(path): for label in labels: print(label.description) - # [END migration_label_detection] + # [END vision_python_migration_label_detection] # [END vision_label_detection] @@ -146,7 +146,7 @@ def detect_landmarks(path): """Detects landmarks in the file.""" client = vision.ImageAnnotatorClient() - # [START migration_landmark_detection] + # [START vision_python_migration_landmark_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -162,7 +162,7 @@ def detect_landmarks(path): lat_lng = location.lat_lng print('Latitude {}'.format(lat_lng.latitude)) print('Longitude {}'.format(lat_lng.longitude)) - # [END migration_landmark_detection] + # [END vision_python_migration_landmark_detection] # [END vision_landmark_detection] @@ -188,7 +188,7 @@ def detect_logos(path): """Detects logos in the file.""" client = vision.ImageAnnotatorClient() - # [START migration_logo_detection] + # [START vision_python_migration_logo_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -200,7 +200,7 @@ def detect_logos(path): for logo in logos: print(logo.description) - # [END migration_logo_detection] + # [END vision_python_migration_logo_detection] # [END vision_logo_detection] @@ -226,7 +226,7 @@ def detect_safe_search(path): """Detects unsafe features in the file.""" client = vision.ImageAnnotatorClient() - # [START migration_safe_search_detection] + # [START vision_python_migration_safe_search_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -245,7 +245,7 @@ def detect_safe_search(path): print('spoofed: {}'.format(likelihood_name[safe.spoof])) print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) - # [END migration_safe_search_detection] + # [END vision_python_migration_safe_search_detection] # [END vision_safe_search_detection] @@ -278,7 +278,7 @@ def detect_text(path): """Detects text in the file.""" client = vision.ImageAnnotatorClient() - # [START migration_text_detection] + # [START vision_python_migration_text_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -295,7 +295,7 @@ def detect_text(path): for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) - # [END migration_text_detection] + # [END vision_python_migration_text_detection] # [END vision_text_detection] @@ -326,7 +326,7 @@ def detect_properties(path): """Detects image properties in the file.""" client = vision.ImageAnnotatorClient() - # [START migration_image_properties] + # [START vision_python_migration_image_properties] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -342,7 +342,7 @@ def detect_properties(path): print('\tg: {}'.format(color.color.green)) print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) - # [END migration_image_properties] + # [END vision_python_migration_image_properties] # [END vision_image_property_detection] @@ -372,7 +372,7 @@ def detect_web(path): """Detects web annotations given an image.""" client = vision.ImageAnnotatorClient() - # [START migration_web_detection] + # [START vision_python_migration_web_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -420,7 +420,7 @@ def detect_web(path): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) - # [END migration_web_detection] + # [END vision_python_migration_web_detection] # [END vision_web_detection] @@ -528,7 +528,7 @@ def detect_crop_hints(path): """Detects crop hints in an image.""" client = vision.ImageAnnotatorClient() - # [START migration_crop_hints] + # [START vision_python_migration_crop_hints] with io.open(path, 'rb') as image_file: content = image_file.read() image = vision.types.Image(content=content) @@ -547,7 +547,7 @@ def detect_crop_hints(path): for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) - # [END migration_crop_hints] + # [END vision_python_migration_crop_hints] # [END vision_crop_hint_detection] @@ -580,7 +580,7 @@ def detect_document(path): """Detects document features in an image.""" client = vision.ImageAnnotatorClient() - # [START migration_document_text_detection] + # [START vision_python_migration_document_text_detection] with io.open(path, 'rb') as image_file: content = image_file.read() @@ -606,7 +606,7 @@ def detect_document(path): for symbol in word.symbols: print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) - # [END migration_document_text_detection] + # [END vision_python_migration_document_text_detection] # [END vision_fulltext_detection] diff --git a/vision/cloud-client/quickstart/quickstart.py b/vision/cloud-client/quickstart/quickstart.py index 4eb2b303612b..8bb674eb118c 100644 --- a/vision/cloud-client/quickstart/quickstart.py +++ b/vision/cloud-client/quickstart/quickstart.py @@ -21,15 +21,15 @@ def run_quickstart(): import os # Imports the Google Cloud client library - # [START migration_import] + # [START vision_python_migration_import] from google.cloud import vision from google.cloud.vision import types - # [END migration_import] + # [END vision_python_migration_import] # Instantiates a client - # [START migration_client] + # [START vision_python_migration_client] client = vision.ImageAnnotatorClient() - # [END migration_client] + # [END vision_python_migration_client] # The name of the image file to annotate file_name = os.path.join( From 215a1a359d476f7917b5dd6dedfb10041782bdbf Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Tue, 14 Aug 2018 11:54:45 -0700 Subject: [PATCH 18/23] Updates product search region tags to standard --- .../product_search/import_product_sets.py | 9 +++-- .../product_in_product_set_management.py | 20 ++++++----- .../product_search/product_management.py | 34 ++++++++++++------- .../product_search/product_search.py | 16 +++++---- .../product_search/product_set_management.py | 28 +++++++++------ .../reference_image_management.py | 28 +++++++++------ 6 files changed, 79 insertions(+), 56 deletions(-) diff --git a/vision/cloud-client/product_search/import_product_sets.py b/vision/cloud-client/product_search/import_product_sets.py index e3c3f758842d..35385cb254f2 100755 --- a/vision/cloud-client/product_search/import_product_sets.py +++ b/vision/cloud-client/product_search/import_product_sets.py @@ -21,14 +21,13 @@ https://cloud.google.com/vision/product-search/docs/ """ -# [START product_search_import] import argparse - +# [START vision_product_search_tutorial_import] from google.cloud import vision_v1p3beta1 as vision -# [END product_search_import] +# [END vision_product_search_tutorial_import] -# [START product_search_import_product_sets] +# [START vision_product_search_import_product_images] def import_product_sets(project_id, location, gcs_uri): """Import images of different products in the product set. Args: @@ -68,7 +67,7 @@ def import_product_sets(project_id, location, gcs_uri): print(reference_image) else: print('Status code not OK: {}'.format(status.message)) -# [END product_search_import_product_sets] +# [END vision_product_search_import_product_images] if __name__ == '__main__': diff --git a/vision/cloud-client/product_search/product_in_product_set_management.py b/vision/cloud-client/product_search/product_in_product_set_management.py index a126478176b1..ccee1ed97056 100755 --- a/vision/cloud-client/product_search/product_in_product_set_management.py +++ b/vision/cloud-client/product_search/product_in_product_set_management.py @@ -21,14 +21,16 @@ https://cloud.google.com/vision/product-search/docs/ """ -# [START product_search_import] import argparse - +# [START vision_product_search_add_product_to_product_set] +# [START vision_product_search_remove_product_from_product_set] from google.cloud import vision_v1p3beta1 as vision -# [END product_search_import] + +# [END vision_product_search_add_product_to_product_set] +# [END vision_product_search_remove_product_from_product_set] -# [START product_search_add_product_to_product_set] +# [START vision_product_search_add_product_to_product_set] def add_product_to_product_set( project_id, location, product_id, product_set_id): """Add a product to a product set. @@ -53,10 +55,10 @@ def add_product_to_product_set( client.add_product_to_product_set( name=product_set_path, product=product_path) print('Product added to product set.') -# [END product_search_add_product_to_product_set] +# [END vision_product_search_add_product_to_product_set] -# [START product_search_list_products_in_product_set] +# [START vision_product_search_list_products_in_product_set] def list_products_in_product_set( project_id, location, product_set_id): """List all products in a product set. @@ -83,10 +85,10 @@ def list_products_in_product_set( print('Product description: {}'.format(product.description)) print('Product category: {}'.format(product.product_category)) print('Product labels: {}'.format(product.product_labels)) -# [END product_search_list_products_in_product_set] +# [END vision_product_search_list_products_in_product_set] -# [START product_search_remove_product_from_product_set] +# [START vision_product_search_remove_product_from_product_set] def remove_product_from_product_set( project_id, location, product_id, product_set_id): """Remove a product from a product set. @@ -111,7 +113,7 @@ def remove_product_from_product_set( client.remove_product_from_product_set( name=product_set_path, product=product_path) print('Product removed from product set.') -# [END product_search_remove_product_from_product_set] +# [END vision_product_search_remove_product_from_product_set] if __name__ == '__main__': diff --git a/vision/cloud-client/product_search/product_management.py b/vision/cloud-client/product_search/product_management.py index 5bb258391735..d6186c8bb7bc 100755 --- a/vision/cloud-client/product_search/product_management.py +++ b/vision/cloud-client/product_search/product_management.py @@ -21,14 +21,22 @@ https://cloud.google.com/vision/product-search/docs/ """ -# [START product_search_import] import argparse - +# [START vision_product_search_create_product] +# [START vision_product_search_delete_product] +# [START vision_product_search_list_products] +# [START vision_product_search_get_product] +# [START vision_product_search_update_product_labels] from google.cloud import vision_v1p3beta1 as vision -# [END product_search_import] + +# [END vision_product_search_create_product] +# [END vision_product_search_delete_product] +# [END vision_product_search_list_products] +# [END vision_product_search_get_product] +# [END vision_product_search_update_product_labels] -# [START product_search_create_product] +# [START vision_product_search_create_product] def create_product( project_id, location, product_id, product_display_name, product_category): @@ -59,10 +67,10 @@ def create_product( # Display the product information. print('Product name: {}'.format(response.name)) -# [END product_search_create_product] +# [END vision_product_search_create_product] -# [START product_search_list_products] +# [START vision_product_search_list_products] def list_products(project_id, location): """List all products. Args: @@ -85,10 +93,10 @@ def list_products(project_id, location): print('Product description: {}'.format(product.description)) print('Product category: {}'.format(product.product_category)) print('Product labels: {}\n'.format(product.product_labels)) -# [END product_search_list_products] +# [END vision_product_search_list_products] -# [START product_search_get_product] +# [START vision_product_search_get_product] def get_product(project_id, location, product_id): """Get information about a product. Args: @@ -112,10 +120,10 @@ def get_product(project_id, location, product_id): print('Product description: {}'.format(product.description)) print('Product category: {}'.format(product.product_category)) print('Product labels: {}'.format(product.product_labels)) -# [END product_search_get_product] +# [END vision_product_search_get_product] -# [START product_search_update_product_labels] +# [START vision_product_search_update_product_labels] def update_product_labels( project_id, location, product_id, key, value): """Update the product labels. @@ -149,10 +157,10 @@ def update_product_labels( # Display the updated product information. print('Product name: {}'.format(updated_product.name)) print('Updated product labels: {}'.format(product.product_labels)) -# [END product_search_update_product_labels] +# [END vision_product_search_update_product_labels] -# [START product_search_delete_product] +# [START vision_product_search_delete_product] def delete_product(project_id, location, product_id): """Delete the product and all its reference images. Args: @@ -169,7 +177,7 @@ def delete_product(project_id, location, product_id): # Delete a product. client.delete_product(name=product_path) print('Product deleted.') -# [END product_search_delete_product] +# [END vision_product_search_delete_product] if __name__ == '__main__': diff --git a/vision/cloud-client/product_search/product_search.py b/vision/cloud-client/product_search/product_search.py index 8ae8c1293a90..55a2b2562df5 100755 --- a/vision/cloud-client/product_search/product_search.py +++ b/vision/cloud-client/product_search/product_search.py @@ -22,14 +22,16 @@ https://cloud.google.com/vision/product-search/docs/ """ -# [START product_search_import] import argparse - +# [START vision_product_search_get_similar_products] +# [START vision_product_search_get_similar_products_gcs] from google.cloud import vision_v1p3beta1 as vision -# [END product_search_import] + +# [END vision_product_search_get_similar_products] +# [START vision_product_search_get_similar_products_gcs] -# [START product_search_get_similar_products_file] +# [START vision_product_search_get_similar_products] def get_similar_products_file( project_id, location, product_set_id, product_category, file_path, filter): @@ -91,10 +93,10 @@ def get_similar_products_file( product.display_name)) print('Product description: {}\n'.format(product.description)) print('Product labels: {}\n'.format(product.product_labels)) -# [END product_search_get_similar_products_file] +# [END vision_product_search_get_similar_products] -# [START product_search_get_similar_products_uri] +# [START vision_product_search_get_similar_products_gcs] def get_similar_products_uri( project_id, location, product_set_id, product_category, image_uri, filter): @@ -153,7 +155,7 @@ def get_similar_products_uri( product.display_name)) print('Product description: {}\n'.format(product.description)) print('Product labels: {}\n'.format(product.product_labels)) -# [END product_search_get_similar_products_uri] +# [END vision_product_search_get_similar_products_gcs] if __name__ == '__main__': diff --git a/vision/cloud-client/product_search/product_set_management.py b/vision/cloud-client/product_search/product_set_management.py index 2f4906d7c3b9..7d3dcd1e262d 100755 --- a/vision/cloud-client/product_search/product_set_management.py +++ b/vision/cloud-client/product_search/product_set_management.py @@ -21,14 +21,20 @@ https://cloud.google.com/vision/product-search/docs/ """ -# [START product_search_import] import argparse - +# [START vision_product_search_delete_product_set] +# [START vision_product_search_list_product_sets] +# [START vision_product_search_get_product_set] +# [START vision_product_search_create_product_set] from google.cloud import vision_v1p3beta1 as vision -# [END product_search_import] + +# [END vision_product_search_delete_product_set] +# [END vision_product_search_list_product_sets] +# [END vision_product_search_get_product_set] +# [END vision_product_search_create_product_set] -# [START product_search_create_product_set] +# [START vision_product_search_create_product_set] def create_product_set( project_id, location, product_set_id, product_set_display_name): """Create a product set. @@ -56,10 +62,10 @@ def create_product_set( # Display the product set information. print('Product set name: {}'.format(response.name)) -# [END product_search_create_product_set] +# [END vision_product_search_create_product_set] -# [START product_search_list_product_sets] +# [START vision_product_search_list_product_sets] def list_product_sets(project_id, location): """List all product sets. Args: @@ -83,10 +89,10 @@ def list_product_sets(project_id, location): print('Product set index time:') print(' seconds: {}'.format(product_set.index_time.seconds)) print(' nanos: {}\n'.format(product_set.index_time.nanos)) -# [END product_search_list_product_sets] +# [END vision_product_search_list_product_sets] -# [START product_search_get_product_set] +# [START vision_product_search_get_product_set] def get_product_set(project_id, location, product_set_id): """Get info about the product set. Args: @@ -111,10 +117,10 @@ def get_product_set(project_id, location, product_set_id): print('Product set index time:') print(' seconds: {}'.format(product_set.index_time.seconds)) print(' nanos: {}'.format(product_set.index_time.nanos)) -# [END product_search_get_product_set] +# [END vision_product_search_get_product_set] -# [START product_search_delete_product_set] +# [START vision_product_search_delete_product_set] def delete_product_set(project_id, location, product_set_id): """Delete a product set. Args: @@ -132,7 +138,7 @@ def delete_product_set(project_id, location, product_set_id): # Delete the product set. client.delete_product_set(name=product_set_path) print('Product set deleted.') -# [END product_search_delete_product_set] +# [END vision_product_search_delete_product_set] if __name__ == '__main__': diff --git a/vision/cloud-client/product_search/reference_image_management.py b/vision/cloud-client/product_search/reference_image_management.py index dac2ddeb1576..8ab5c2575b4c 100755 --- a/vision/cloud-client/product_search/reference_image_management.py +++ b/vision/cloud-client/product_search/reference_image_management.py @@ -21,14 +21,20 @@ https://cloud.google.com/vision/product-search/docs/ """ -# [START product_search_import] import argparse - +# [START vision_product_search_create_reference_image] +# [START vision_product_search_delete_reference_image] +# [START vision_product_search_list_reference_images] +# [START vision_product_search_get_reference_image] from google.cloud import vision_v1p3beta1 as vision -# [END product_search_import] + +# [END vision_product_search_create_reference_image] +# [END vision_product_search_delete_reference_image] +# [END vision_product_search_list_reference_images] +# [END vision_product_search_get_reference_image] -# [START product_search_create_reference_image] +# [START vision_product_search_create_reference_image] def create_reference_image( project_id, location, product_id, reference_image_id, gcs_uri): """Create a reference image. @@ -57,10 +63,10 @@ def create_reference_image( # Display the reference image information. print('Reference image name: {}'.format(image.name)) print('Reference image uri: {}'.format(image.uri)) -# [END product_search_create_reference_image] +# [END vision_product_search_create_reference_image] -# [START product_search_list_reference_images] +# [START vision_product_search_list_reference_images] def list_reference_images( project_id, location, product_id): """List all images in a product. @@ -85,10 +91,10 @@ def list_reference_images( print('Reference image uri: {}'.format(image.uri)) print('Reference image bounding polygons: {}'.format( image.bounding_polys)) -# [END product_search_list_reference_images] +# [END vision_product_search_list_reference_images] -# [START product_search_get_reference_image] +# [START vision_product_search_get_reference_image] def get_reference_image( project_id, location, product_id, reference_image_id): """Get info about a reference image. @@ -113,10 +119,10 @@ def get_reference_image( print('Reference image id: {}'.format(image.name.split('/')[-1])) print('Reference image uri: {}'.format(image.uri)) print('Reference image bounding polygons: {}'.format(image.bounding_polys)) -# [END product_search_get_reference_image] +# [END vision_product_search_get_reference_image] -# [START product_search_delete_reference_image] +# [START vision_product_search_delete_reference_image] def delete_reference_image( project_id, location, product_id, reference_image_id): """Delete a reference image. @@ -136,7 +142,7 @@ def delete_reference_image( # Delete the reference image. client.delete_reference_image(name=reference_image_path) print('Reference image deleted from product.') -# [END product_search_delete_reference_image] +# [END vision_product_search_delete_reference_image] if __name__ == '__main__': From d51ec85456168d7c920c05f5eac504e042f5d389 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Tue, 14 Aug 2018 12:00:34 -0700 Subject: [PATCH 19/23] fixes region tags for face detection tutorial --- vision/cloud-client/face_detection/faces.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 2fc2daf2b20c..994dbdd2414a 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -25,7 +25,7 @@ # [END vision_face_detection_tutorial_client] -# [START vision_face_detection_send_request] +# [START vision_face_detection_tutorial_send_request] def detect_face(face_file, max_results=4): """Uses the Vision API to detect faces in the given file. @@ -43,10 +43,10 @@ def detect_face(face_file, max_results=4): image = types.Image(content=content) return client.face_detection(image=image).face_annotations -# [END vision_face_detection_send_request] +# [END vision_face_detection_tutorial_send_request] -# [START vision_face_detection_process_response] +# [START vision_face_detection_tutorial_process_response] def highlight_faces(image, faces, output_filename): """Draws a polygon around the faces, then saves to output_filename. @@ -66,10 +66,10 @@ def highlight_faces(image, faces, output_filename): draw.line(box + [box[0]], width=5, fill='#00ff00') im.save(output_filename) -# [END vision_face_detection_process_response] +# [END vision_face_detection_tutorial_process_response] -# [START vision_face_detection_run_application] +# [START vision_face_detection_tutorial_run_application] def main(input_filename, output_filename, max_results): with open(input_filename, 'rb') as image: faces = detect_face(image, max_results) @@ -80,7 +80,7 @@ def main(input_filename, output_filename, max_results): # Reset the file pointer, so we can read the file again image.seek(0) highlight_faces(image, faces, output_filename) -# [END vision_face_detection_run_application] +# [END vision_face_detection_tutorial_run_application] if __name__ == '__main__': From 846f067620a178f00f2151d3068c96b341c57712 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Tue, 14 Aug 2018 16:35:29 -0700 Subject: [PATCH 20/23] adds import tag to face detection tutorial --- vision/cloud-client/face_detection/faces.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 994dbdd2414a..74d60d83571f 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -18,12 +18,11 @@ import argparse -# [START vision_face_detection_tutorial_client] +# [START vision_face_detection_tutorial_imports] from google.cloud import vision from google.cloud.vision import types from PIL import Image, ImageDraw - -# [END vision_face_detection_tutorial_client] +# [END vision_face_detection_tutorial_imports] # [START vision_face_detection_tutorial_send_request] def detect_face(face_file, max_results=4): From 525e3bc9f9b17bf3d6088e04ab242e99d0f5163d Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Tue, 14 Aug 2018 16:52:57 -0700 Subject: [PATCH 21/23] fix region tags --- vision/cloud-client/product_search/product_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vision/cloud-client/product_search/product_search.py b/vision/cloud-client/product_search/product_search.py index 55a2b2562df5..ae9bffef8239 100755 --- a/vision/cloud-client/product_search/product_search.py +++ b/vision/cloud-client/product_search/product_search.py @@ -28,7 +28,7 @@ from google.cloud import vision_v1p3beta1 as vision # [END vision_product_search_get_similar_products] -# [START vision_product_search_get_similar_products_gcs] +# [END vision_product_search_get_similar_products_gcs] # [START vision_product_search_get_similar_products] From 4f6052cb9ef92dca4e8479be914b08b302da23a2 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Wed, 15 Aug 2018 12:32:28 -0700 Subject: [PATCH 22/23] fixes lint --- vision/cloud-client/face_detection/faces.py | 1 + vision/cloud-client/web/web_detect.py | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 74d60d83571f..df44462ea1fb 100755 --- a/vision/cloud-client/face_detection/faces.py +++ b/vision/cloud-client/face_detection/faces.py @@ -24,6 +24,7 @@ from PIL import Image, ImageDraw # [END vision_face_detection_tutorial_imports] + # [START vision_face_detection_tutorial_send_request] def detect_face(face_file, max_results=4): """Uses the Vision API to detect faces in the given file. diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index a6e0915dc037..6cdfa25643ed 100644 --- a/vision/cloud-client/web/web_detect.py +++ b/vision/cloud-client/web/web_detect.py @@ -63,22 +63,22 @@ def report(annotations): print('Url : {}'.format(page.url)) if annotations.full_matching_images: - print ('\n{} Full Matches found: '.format( - len(annotations.full_matching_images))) + print('\n{} Full Matches found: '.format( + len(annotations.full_matching_images))) for image in annotations.full_matching_images: print('Url : {}'.format(image.url)) if annotations.partial_matching_images: - print ('\n{} Partial Matches found: '.format( - len(annotations.partial_matching_images))) + print('\n{} Partial Matches found: '.format( + len(annotations.partial_matching_images))) for image in annotations.partial_matching_images: print('Url : {}'.format(image.url)) if annotations.web_entities: - print ('\n{} Web entities found: '.format( - len(annotations.web_entities))) + print('\n{} Web entities found: '.format( + len(annotations.web_entities))) for entity in annotations.web_entities: print('Score : {}'.format(entity.score)) From 07be3085c162f6fb43e9acf40e1119c23fca63f2 Mon Sep 17 00:00:00 2001 From: Alix Hamilton Date: Wed, 15 Aug 2018 16:14:36 -0700 Subject: [PATCH 23/23] fixes import lint --- vision/cloud-client/product_search/import_product_sets.py | 1 + .../product_search/product_in_product_set_management.py | 1 + vision/cloud-client/product_search/product_management.py | 1 + vision/cloud-client/product_search/product_search.py | 1 + vision/cloud-client/product_search/product_set_management.py | 1 + vision/cloud-client/product_search/reference_image_management.py | 1 + 6 files changed, 6 insertions(+) diff --git a/vision/cloud-client/product_search/import_product_sets.py b/vision/cloud-client/product_search/import_product_sets.py index 35385cb254f2..d08c15c5ec30 100755 --- a/vision/cloud-client/product_search/import_product_sets.py +++ b/vision/cloud-client/product_search/import_product_sets.py @@ -22,6 +22,7 @@ """ import argparse + # [START vision_product_search_tutorial_import] from google.cloud import vision_v1p3beta1 as vision # [END vision_product_search_tutorial_import] diff --git a/vision/cloud-client/product_search/product_in_product_set_management.py b/vision/cloud-client/product_search/product_in_product_set_management.py index ccee1ed97056..e9bfad9bdd92 100755 --- a/vision/cloud-client/product_search/product_in_product_set_management.py +++ b/vision/cloud-client/product_search/product_in_product_set_management.py @@ -22,6 +22,7 @@ """ import argparse + # [START vision_product_search_add_product_to_product_set] # [START vision_product_search_remove_product_from_product_set] from google.cloud import vision_v1p3beta1 as vision diff --git a/vision/cloud-client/product_search/product_management.py b/vision/cloud-client/product_search/product_management.py index d6186c8bb7bc..4b187e98235b 100755 --- a/vision/cloud-client/product_search/product_management.py +++ b/vision/cloud-client/product_search/product_management.py @@ -22,6 +22,7 @@ """ import argparse + # [START vision_product_search_create_product] # [START vision_product_search_delete_product] # [START vision_product_search_list_products] diff --git a/vision/cloud-client/product_search/product_search.py b/vision/cloud-client/product_search/product_search.py index ae9bffef8239..05f19ea3e968 100755 --- a/vision/cloud-client/product_search/product_search.py +++ b/vision/cloud-client/product_search/product_search.py @@ -23,6 +23,7 @@ """ import argparse + # [START vision_product_search_get_similar_products] # [START vision_product_search_get_similar_products_gcs] from google.cloud import vision_v1p3beta1 as vision diff --git a/vision/cloud-client/product_search/product_set_management.py b/vision/cloud-client/product_search/product_set_management.py index 7d3dcd1e262d..941f59fa9540 100755 --- a/vision/cloud-client/product_search/product_set_management.py +++ b/vision/cloud-client/product_search/product_set_management.py @@ -22,6 +22,7 @@ """ import argparse + # [START vision_product_search_delete_product_set] # [START vision_product_search_list_product_sets] # [START vision_product_search_get_product_set] diff --git a/vision/cloud-client/product_search/reference_image_management.py b/vision/cloud-client/product_search/reference_image_management.py index 8ab5c2575b4c..a53927839553 100755 --- a/vision/cloud-client/product_search/reference_image_management.py +++ b/vision/cloud-client/product_search/reference_image_management.py @@ -22,6 +22,7 @@ """ import argparse + # [START vision_product_search_create_reference_image] # [START vision_product_search_delete_reference_image] # [START vision_product_search_list_reference_images]