-
Notifications
You must be signed in to change notification settings - Fork 0
/
recognize.py
49 lines (40 loc) · 1.03 KB
/
recognize.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
import numpy as np
import os
from alttraining import Faces
class Eigenfaces:
def __init__(self):
self.faces = Faces()
self.faces.main2()
self.distances = []
def normalize (self, video_frame):
im_matrix = self.faces.get_frame_vector(video_frame).T
return im_matrix - self.faces.meanface
def projection (self, face):
return self.faces.eigenfaces.T * face
def findface(self, a):
diff = self.faces.weights - a
for i in diff.T:
self.distances.append(np.linalg.norm(i-a.T))
if min(self.distances) > 10000:
print "Not recognized as a face"
else:
index = self.distances.index(min(self.distances))
# print self.distances
if index < 50:
print "not smiling"
elif index < 100:
print "smiling"
elif index < 150:
print "George's face"
else:
print "JN's face"
def main (self):
images = os.listdir(os.getcwd()+"/negative")
images.pop(0)
for i in images:
self.distances = []
a = self.normalize("negative/" + i)
b = self.projection(a)
self.findface(b)
test = Eigenfaces()
test.main()