forked from IOkal/HackWestern7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visionapi.py
36 lines (26 loc) · 1.1 KB
/
visionapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os, io
from google.cloud import vision
# from google.cloud.vision import types
import pandas as pd
import json
os.environ['GOOGLE_APPLICATION_CREDENTIALS']= r'../hackwestern7.json'
client = vision.ImageAnnotatorClient()
FILE_NAME = 'rbc-denysHappy.png'
FOLDER_PATH = r'C:\Users\Iyad\Desktop\4th Year\HackWestern\HackWestern7\testImages'
with io.open(os.path.join(FOLDER_PATH, FILE_NAME), 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
response = client.face_detection(image=image)
# print(reponse.)
# df = pd.DataFrame(columns=['locale','description'])
for face in response.face_annotations:
joy = vision.Likelihood(face.joy_likelihood)
anger = vision.Likelihood(face.anger_likelihood)
sorrow = vision.Likelihood(face.sorrow_likelihood)
surprise = vision.Likelihood(face.surprise_likelihood)
vertices = ['(%s,%s)' % (v.x, v.y) for v in face.bounding_poly.vertices]
print('Happy?:', joy.name)
print('Angry?:', anger.name)
print('Sorrow?:', sorrow.name)
print('Surprised?:', surprise.name)
print('Face bounds:', ",".join(vertices))