-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathface recognition.py
More file actions
34 lines (18 loc) · 980 Bytes
/
face recognition.py
File metadata and controls
34 lines (18 loc) · 980 Bytes
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
import face_recognition
import numpy as np
from PIL import Image, ImageDraw
known_image = face_recognition.load_image_file("aditya.jpg")
encoding = face_recognition.face_encodings(known_image)[0]
unknown_image = face_recognition.load_image_file("pic.jpg")
face_locations = face_recognition.face_locations(unknown_image)
face_encodings = face_recognition.face_encodings(unknown_image, face_locations)
pil_image = Image.fromarray(unknown_image)
draw = ImageDraw.Draw(pil_image)
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
matches = face_recognition.compare_faces([encoding], face_encoding)
face_distances = face_recognition.face_distance([encoding], face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:
draw.rectangle(((left - 20, top - 20), (right + 20, bottom + 20)), outline=(0, 255, 0), width=20)
del draw
pil_image.show()