Created
July 24, 2019 03:39
-
-
Save DataSolveProblems/4d683d42c806474ca17adadbe087a3e6 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 io, os | |
from numpy import random | |
from google.cloud import vision | |
from Pillow_Utility import draw_borders, Image | |
import pandas as pd | |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r"GoogleCloudDemo_ServiceAcct_Token.json" | |
client = vision.ImageAnnotatorClient() | |
file_name = 'ikea3.jpg' | |
image_path = os.path.join('.\Images', file_name) | |
with io.open(image_path, 'rb') as image_file: | |
content = image_file.read() | |
image = vision.types.Image(content=content) | |
response = client.object_localization(image=image) | |
localized_object_annotations = response.localized_object_annotations | |
pillow_image = Image.open(image_path) | |
df = pd.DataFrame(columns=['name', 'score']) | |
for obj in localized_object_annotations: | |
df = df.append( | |
dict( | |
name=obj.name, | |
score=obj.score | |
), | |
ignore_index=True) | |
r, g, b = random.randint(150, 255), random.randint( | |
150, 255), random.randint(150, 255) | |
draw_borders(pillow_image, obj.bounding_poly, (r, g, b), | |
pillow_image.size, obj.name, obj.score) | |
print(df) | |
pillow_image.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment