Skip to content

Instantly share code, notes, and snippets.

@DataSolveProblems
Last active October 24, 2020 17:27
Show Gist options
  • Save DataSolveProblems/3dc99d82a39b5e472c867f1767654658 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/3dc99d82a39b5e472c867f1767654658 to your computer and use it in GitHub Desktop.
import os
import io
from google.cloud import vision_v1
import pandas as pd
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'ServiceAccountToken.json'
client = vision_v1.ImageAnnotatorClient()
def detect_landmark(file_path):
try:
with io.open(file_path, 'rb') as image_file:
content = image_file.read()
image = vision_v1.types.Image(content=content)
response = client.landmark_detection(image=image)
landmarks = response.landmark_annotations
df = pd.DataFrame(columns=['description', 'locations', 'score'])
for landmark in landmarks:
df = df.append(
dict(
description=landmark.description,
locations=landmark.locations,
score=landmark.score
),
ignore_index=True
)
return df
except Exception as e:
print(e)
file_name = 't2.jpg'
image_path = f'.\Images\{file_name}'
print(detect_landmark(image_path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment