Last active
July 15, 2019 04:54
-
-
Save DataSolveProblems/a97b1f623d4d8ae8cdf160a7d8162ee7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, io | |
from google.cloud import vision | |
import pandas as pd | |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r"ServiceAccountToken.json" | |
client = vision.ImageAnnotatorClient() | |
file_name = 'cable car.jpg' | |
image_path = f'.\VisionAPI\Images\{file_name}' | |
with io.open(image_path, 'rb') as image_file: | |
content = image_file.read() | |
# construct an iamge instance | |
image = vision.types.Image(content=content) | |
""" | |
# or we can pass the image url | |
image = vision.types.Image() | |
image.source.image_uri = 'https://edu.pngfacts.com/uploads/1/1/3/2/11320972/grade-10-english_orig.png' | |
""" | |
# annotate Image Response | |
response = client.text_detection(image=image) # returns TextAnnotation | |
df = pd.DataFrame(columns=['locale', 'description']) | |
texts = response.text_annotations | |
for text in texts: | |
df = df.append( | |
dict( | |
locale=text.locale, | |
description=text.description | |
), | |
ignore_index=True | |
) | |
print(df['description'][0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment