diff --git a/vision/cloud-client/crop_hints/crop_hints.py b/vision/cloud-client/crop_hints/crop_hints.py index 3120fe2fbe4..22ca7dbf460 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] diff --git a/vision/cloud-client/detect/beta_snippets.py b/vision/cloud-client/detect/beta_snippets.py index 0668b377c20..ed7ef6ca7fd 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__': diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 7a15430d625..d4033d6ba3b 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -40,18 +40,18 @@ 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() - # [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,18 +70,18 @@ def detect_faces(path): for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) - # [END migration_face_detection] -# [END def_detect_faces] + # [END vision_python_migration_face_detection] +# [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() - # [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 @@ -100,15 +100,15 @@ 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] +# [START vision_label_detection] 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,11 +120,11 @@ def detect_labels(path): for label in labels: print(label.description) - # [END migration_label_detection] -# [END def_detect_labels] + # [END vision_python_migration_label_detection] +# [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,15 +138,15 @@ 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] +# [START vision_landmark_detection] 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,11 +162,11 @@ 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 def_detect_landmarks] + # [END vision_python_migration_landmark_detection] +# [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,15 +180,15 @@ 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] +# [START vision_logo_detection] 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,11 +200,11 @@ def detect_logos(path): for logo in logos: print(logo.description) - # [END migration_logo_detection] -# [END def_detect_logos] + # [END vision_python_migration_logo_detection] +# [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,15 +218,15 @@ 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] +# [START vision_safe_search_detection] 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,11 +245,11 @@ 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 def_detect_safe_search] + # [END vision_python_migration_safe_search_detection] +# [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,15 +270,15 @@ 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] +# [START vision_text_detection] 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,11 +295,11 @@ def detect_text(path): for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) - # [END migration_text_detection] -# [END def_detect_text] + # [END vision_python_migration_text_detection] +# [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,15 +318,15 @@ 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 def_detect_properties] +# [START vision_image_property_detection] 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,11 +342,11 @@ 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 def_detect_properties] + # [END vision_python_migration_image_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,15 +364,15 @@ 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] +# [START vision_web_detection] 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,11 +420,11 @@ 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_python_migration_web_detection] +# [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,15 +520,15 @@ 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 def_detect_crop_hints] +# [START vision_crop_hint_detection] 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,11 +547,11 @@ def detect_crop_hints(path): for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) - # [END migration_crop_hints] -# [END def_detect_crop_hints] + # [END vision_python_migration_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,15 +572,15 @@ 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] +# [START vision_fulltext_detection] 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,11 +606,11 @@ def detect_document(path): for symbol in word.symbols: print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) - # [END migration_document_text_detection] -# [END def_detect_document] + # [END vision_python_migration_document_text_detection] +# [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,10 +638,10 @@ 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] +# [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 a728d0522a5..f7e8abed42d 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__': diff --git a/vision/cloud-client/document_text/doctext.py b/vision/cloud-client/document_text/doctext.py index 478f2e22731..097878afc8e 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] diff --git a/vision/cloud-client/face_detection/faces.py b/vision/cloud-client/face_detection/faces.py index 25a40763b33..df44462ea1f 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_imports] 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_imports] -# [START def_detect_face] +# [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. @@ -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_tutorial_send_request] -# [START def_highlight_faces] +# [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 def_highlight_faces] +# [END vision_face_detection_tutorial_process_response] -# [START def_main] +# [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 def_main] +# [END vision_face_detection_tutorial_run_application] if __name__ == '__main__': diff --git a/vision/cloud-client/product_search/import_product_sets.py b/vision/cloud-client/product_search/import_product_sets.py index e3c3f758842..d08c15c5ec3 100755 --- a/vision/cloud-client/product_search/import_product_sets.py +++ b/vision/cloud-client/product_search/import_product_sets.py @@ -21,14 +21,14 @@ 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 +68,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 a126478176b..e9bfad9bdd9 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,17 @@ 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 +56,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 +86,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 +114,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 5bb25839173..4b187e98235 100755 --- a/vision/cloud-client/product_search/product_management.py +++ b/vision/cloud-client/product_search/product_management.py @@ -21,14 +21,23 @@ 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 +68,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 +94,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 +121,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 +158,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 +178,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 8ae8c1293a9..05f19ea3e96 100755 --- a/vision/cloud-client/product_search/product_search.py +++ b/vision/cloud-client/product_search/product_search.py @@ -22,14 +22,17 @@ 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] +# [END 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 +94,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 +156,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 2f4906d7c3b..941f59fa954 100755 --- a/vision/cloud-client/product_search/product_set_management.py +++ b/vision/cloud-client/product_search/product_set_management.py @@ -21,14 +21,21 @@ 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 +63,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 +90,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 +118,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 +139,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 dac2ddeb157..a5392783955 100755 --- a/vision/cloud-client/product_search/reference_image_management.py +++ b/vision/cloud-client/product_search/reference_image_management.py @@ -21,14 +21,21 @@ 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 +64,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 +92,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 +120,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 +143,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__': diff --git a/vision/cloud-client/quickstart/quickstart.py b/vision/cloud-client/quickstart/quickstart.py index 4eb2b303612..8bb674eb118 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( diff --git a/vision/cloud-client/web/web_detect.py b/vision/cloud-client/web/web_detect.py index 0b3e72f901e..6cdfa25643e 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))) @@ -63,31 +63,31 @@ 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)) 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]