Skip to content

Instantly share code, notes, and snippets.

@daspecster
Created March 28, 2017 19:52
Show Gist options
  • Save daspecster/ef07af75de71f3694282f7b020962f00 to your computer and use it in GitHub Desktop.
Save daspecster/ef07af75de71f3694282f7b020962f00 to your computer and use it in GitHub Desktop.
Vision Snippets Results
from google.cloud import vision
# client = vision.Client()
# image = client.image(
# source_uri='gs://ferrous-arena-my-test-bucket/landmark2.jpg')
# image = client.image(filename='landmark2.jpg')
#
#
# with open('./landmark2.jpg', 'rb') as image_file:
# bytes_image = client.image(content=image_file.read())
#
#
# from google.cloud import vision
# from google.cloud.vision.feature import Feature
# from google.cloud.vision.feature import FeatureTypes
# client = vision.Client()
# image = client.image(
# source_uri='gs://ferrous-arena-my-test-bucket/logos.png')
# features = [Feature(FeatureTypes.FACE_DETECTION, 5),
# Feature(FeatureTypes.LOGO_DETECTION, 3)]
# annotations = image.detect(features)
# len(annotations)
#
# for face in annotations[0].faces:
# print(face.joy)
#
# for logo in annotations[0].logos:
# print(logo.description)
"""
Output:
Likelihood.VERY_LIKELY
Likelihood.VERY_LIKELY
Likelihood.VERY_LIKELY
Likelihood.LIKELY
Likelihood.VERY_LIKELY
Nokia
GNU/Linux
"""
# client = vision.Client()
# image = client.image(
# source_uri='gs://ferrous-arena-my-test-bucket/logos.png')
# crop_hints = image.detect_crop_hints(aspect_ratios=[1.3333], limit=2)
# first_hint = crop_hints[0]
# print(first_hint.bounds.vertices[0].x_coordinate)
# print(first_hint.bounds.vertices[0].y_coordinate)
# print(first_hint.confidence)
# print(first_hint.importance_fraction)
"""
Output:
41
0
0.799999952316
0.949999988079
"""
# client = vision.Client()
# image = client.image(
# source_uri='gs://ferrous-arena-my-test-bucket/people.jpg')
# faces = image.detect_faces(limit=10)
# first_face = faces[0]
# print(first_face.landmarks.left_eye.landmark_type)
# print(first_face.landmarks.left_eye.position.x_coordinate)
# print(first_face.detection_confidence)
# print(first_face.joy)
# print(first_face.anger)
"""
Output:
LandmarkTypes.LEFT_EYE
1004.80029297
0.986368298531
Likelihood.VERY_LIKELY
Likelihood.VERY_UNLIKELY
"""
# client = vision.Client()
# image = client.image(
# source_uri='gs://ferrous-arena-my-test-bucket/people.jpg')
# labels = image.detect_labels(limit=3)
# print(labels[0].description)
# print(labels[0].score)
"""
Output:
person
0.91097253561
"""
# client = vision.Client()
# with open('./landmark2.jpg', 'rb') as image_file:
# image = client.image(content=image_file.read())
# landmarks = image.detect_landmarks()
# print(landmarks[0].description)
# print(landmarks[0].locations[0].latitude)
# print(landmarks[0].locations[0].longitude)
# print(landmarks[0].bounds.vertices[0].x_coordinate)
# print(landmarks[0].bounds.vertices[0].y_coordinate)
"""
Output:
Statue of Liberty
40.689261
-74.044482
82
242
"""
# client = vision.Client()
# with open('./logos.png', 'rb') as image_file:
# image = client.image(content=image_file.read())
# logos = image.detect_logos(limit=3)
# print(len(logos))
# first_logo = logos[0]
# print(first_logo.description)
# print(first_logo.score)
# print(len(first_logo.bounds.vertices))
# print(first_logo.bounds.vertices[0].x_coordinate)
# print(first_logo.bounds.vertices[0].y_coordinate)
"""
Output:
2
Nokia
0.631921768188
4
78
162
"""
# client = vision.Client()
# with open('./logos.png', 'rb') as image_file:
# image = client.image(content=image_file.read())
# safe_search = image.detect_safe_search()
# print(safe_search.adult)
# print(safe_search.spoof)
# print(safe_search.medical)
# print(safe_search.violence)
"""
Output:
Likelihood.VERY_UNLIKELY
Likelihood.VERY_UNLIKELY
Likelihood.UNLIKELY
Likelihood.UNLIKELY
"""
# client = vision.Client()
# with open('./text.jpg', 'rb') as image_file:
# image = client.image(content=image_file.read())
# texts = image.detect_text()
# print(texts[0].locale)
# print(texts[0].description)
# print(texts[1].description)
"""
Output:
en
Do what is
right, not
what is easy
Do
"""
# client = vision.Client()
# with open('./logos.png', 'rb') as image_file:
# image = client.image(content=image_file.read())
# properties = image.detect_properties()
# colors = properties.colors
# first_color = colors[0]
# print(first_color.color.red)
# print(first_color.color.blue)
# print(first_color.score)
# print(first_color.pixel_fraction)
"""
Output:
217.0
32.0
0.215387970209
0.0329939685762
"""
# from google.cloud.vision.feature import Feature
# from google.cloud.vision.feature import FeatureTypes
#
# client = vision.Client()
# batch = client.batch()
# image_one = client.image(
# source_uri='gs://ferrous-arena-my-test-bucket/people.jpg')
# image_two = client.image(
# source_uri='gs://ferrous-arena-my-test-bucket/logos.png')
# face_feature = Feature(FeatureTypes.FACE_DETECTION, 2)
# logo_feature = Feature(FeatureTypes.LOGO_DETECTION, 2)
# batch.add_image(image_one, [face_feature, logo_feature])
# batch.add_image(image_two, [logo_feature])
# results = batch.detect()
# for image in results:
# for face in image.faces:
# print('=' * 40)
# print(face.joy)
"""
Output:
========================================
Likelihood.VERY_LIKELY
========================================
Likelihood.VERY_LIKELY
"""
# client = vision.Client()
# with open('./logos.png', 'rb') as image_file:
# image = client.image(content=image_file.read())
# web_images = image.detect_web(limit=2)
# for full_matching_image in web_images.full_matching_images:
# print('=' * 20)
# print(full_matching_image.url)
#
# for partial_matching_image in web_images.partial_matching_images:
# print('=' * 20)
# print(partial_matching_image.url)
#
# for page_with_matching_images in web_images.pages_with_matching_images:
# print('=' * 20)
# print(page_with_matching_images.url)
#
# for entity in web_images.web_entities:
# print('=' * 20)
# print(entity.description)
"""
Output:
====================
http://inews.gtimg.com/newsapp_match/0/60949563/0
====================
http://img.hutufan.com/hutufanimgbiz/m7ceJicSZzpUibySW3w4A4BOggMLXlAeAh5AVmGpsLK2yW28x1x3DoLjxvACicGoBBykrI9VGUokeoRWN9l9iawUnw.jpg
====================
http://dogeya.com/wp-content/uploads/2014/05/159.png
====================
https://revistadelconsumidor.files.wordpress.com/2010/12/marcas.jpg?w=1400
====================
https://twentynext.com/nokia-connecting-people-once-again/
====================
http://techliveinfo.com/connecting-people-once-more-nokia-mobile-is-back/
====================
Nokia
====================
Nokia N86 8MP
"""
client = vision.Client()
with open('./text.jpg', 'rb') as image_file:
image = client.image(content=image_file.read())
logos = image.detect_logos(limit=3)
print(logos)
"""
Output:
[]
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment