-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimported_test.py
90 lines (38 loc) · 1.43 KB
/
imported_test.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
from PIL import Image
import face_recognition
image = face_recognition.load_image_file("family.jpeg")
# Find all the faces in the image using the default HOG-based model.
# This method is fairly accurate, but not as accurate as the CNN model and not GPU accelerated.
# See also: find_faces_in_picture_cnn.py
face_locations = face_recognition.face_locations(image)
faces = []
isize = []
print("I found {} face(s) in this photograph.".format(len(face_locations)))
for face_location in face_locations:
# Print the location of each face in this image
top, right, bottom, left = face_location
print(
"A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(
top, left, bottom, right
)
)
face_size = (bottom - top) * (right - left)
isize.append(face_size)
# You can access the actual face itself like this:
face_image = image[top:bottom, left:right]
pil_image = Image.fromarray(face_image)
faces.append(pil_image)
largest = 0
i = 0
for item in isize:
if item > largest:
largest = item
indexing_num = i
i += 1
print(str(largest))
faces[i-1].save("tmp.jpg")
prelim = face_recognition.load_image_file("tmp.jpg")
my_face_encoding = face_recognition.face_encodings(prelim)[0]
pil_image.show(faces[i-1])
print("The size of the face is: " + str(largest) + " pixels")
print("The encoding is: " + str(my_face_encoding))