2626
2727from google .cloud import vision
2828from PIL import Image , ImageDraw
29+
2930# [END vision_document_text_tutorial_imports]
3031
3132
@@ -38,7 +39,16 @@ class FeatureType(Enum):
3839
3940
4041def draw_boxes (image , bounds , color ):
41- """Draw a border around the image using the hints in the vector list."""
42+ """Draws a border around the image using the hints in the vector list.
43+
44+ Args:
45+ image: the input image object.
46+ bounds: list of coordinates for the boxes.
47+ color: the color of the box.
48+
49+ Returns:
50+ An image with colored bounds added.
51+ """
4252 draw = ImageDraw .Draw (image )
4353
4454 for bound in bounds :
@@ -61,7 +71,15 @@ def draw_boxes(image, bounds, color):
6171
6272# [START vision_document_text_tutorial_detect_bounds]
6373def get_document_bounds (image_file , feature ):
64- """Returns document bounds given an image."""
74+ """Finds the document bounds given an image and feature type.
75+
76+ Args:
77+ image_file: path to the image file.
78+ feature: feature type to detect.
79+
80+ Returns:
81+ List of coordinates for the corresponding feature type.
82+ """
6583 client = vision .ImageAnnotatorClient ()
6684
6785 bounds = []
@@ -94,10 +112,18 @@ def get_document_bounds(image_file, feature):
94112
95113 # The list `bounds` contains the coordinates of the bounding boxes.
96114 return bounds
115+
116+
97117# [END vision_document_text_tutorial_detect_bounds]
98118
99119
100120def render_doc_text (filein , fileout ):
121+ """Outlines document features (blocks, paragraphs and words) given an image.
122+
123+ Args:
124+ filein: path to the input image.
125+ fileout: path to the output image.
126+ """
101127 image = Image .open (filein )
102128 bounds = get_document_bounds (filein , FeatureType .BLOCK )
103129 draw_boxes (image , bounds , "blue" )
0 commit comments