Created
July 28, 2019 13:50
-
-
Save DataSolveProblems/5da0a6063143ca48a3172e05e92495fb to your computer and use it in GitHub Desktop.
This file contains 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 google.cloud import vision | |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r"ServiceAcct_Token.json" | |
client = vision.ImageAnnotatorClient() | |
file_name = 'image file' | |
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.web_detection(image=image) | |
web_detection = response.web_detection | |
web_detection.best_guess_labels | |
web_detection.full_matching_images | |
web_detection.visually_similar_images | |
web_detection.pages_with_matching_images | |
web_detection.partial_matching_images | |
# recommend tags for the image based on data collected from the web | |
for entity in web_detection.web_entities: | |
print(entity.description) | |
print(entity.score) | |
print('-'*50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment