from typing import Sequence
from google.cloud import vision
def analyze_image_from_uri(
str,
image_uri:
feature_types: Sequence,-> vision.AnnotateImageResponse:
) = vision.ImageAnnotatorClient()
client
= vision.Image()
image = image_uri
image.source.image_uri = [vision.Feature(type_=feature_type) for feature_type in feature_types]
features = vision.AnnotateImageRequest(image=image, features=features)
request
= client.annotate_image(request=request)
response
return response
def print_text(response: vision.AnnotateImageResponse):
print("=" * 80)
for annotation in response.text_annotations:
= [f"({v.x},{v.y})" for v in annotation.bounding_poly.vertices]
vertices print(
f"{repr(annotation.description):42}",
",".join(vertices),
=" | ",
sep
)