-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
73 lines (57 loc) · 2.12 KB
/
Copy pathtest.py
File metadata and controls
73 lines (57 loc) · 2.12 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Can you tell me if this works? I had this working with a random number generator spanning numbers one through five, so hopefully this works with our real data.
import io
import os
import pygame.camera
import time
from matplotlib import pyplot as plt
from matplotlib import style
# Imports the Google Cloud client library
from google.cloud import vision
z = time.time()
def take_picture():
image = cam.get_image()
pygame.image.save(image, "01.jpg")
if __name__ == '__main__':
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/home/matthew/Documents/My First Project-b5e1e25e8952.json"
pygame.init()
pygame.camera.init()
pygame.camera.list_cameras()
cam = pygame.camera.Camera("/dev/video0", (1280, 720))
cam.start()
# Instantiates a client
client = vision.ImageAnnotatorClient()
count = 0
while count < 10:
time.sleep(1)
take_picture()
# The name of the image file to annotate
file_name = os.path.join(
os.path.dirname(__file__),
'01.jpg')
# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.face_detection(image=image)
faces = response.face_annotations
# Names of likelihood from google.cloud.vision.enums
likelihood_name = (-1, 0, 1, 2, 3, 4)
print('Faces:')
avg = 0
temp = 0
num_faces = 0
for face in faces:
temp = max(likelihood_name[face.anger_likelihood], likelihood_name[face.joy_likelihood], likelihood_name[face.surprise_likelihood])
num_faces += 1
avg = ((num_faces - 1) * (avg) + temp) / num_faces
print(temp)
# Prints average of facial data
style.use('ggplot')
x = avg
y = time.time()-z
plt.scatter(y,x)
plt.title("Performance over Time")
plt.ylabel("Average Engagement")
plt.xlabel("Time Elapsed")
count += 1
plt.show()