-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpyfaces.py~
104 lines (83 loc) · 3.2 KB
/
pyfaces.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import sys, optparse, Image,os
from eigenfaces import find_matching_image, parse_folder
from utils import merge_images
FACES = None
THRESHOLD = 10
class PyFaces(object):
"""
Detect if the face in `image` is similar to any face at `directory`,
applies EigenFaces method with `threshold` as minum distance. Images
on `directory` should be of the same size as `image`.
"""
def __init__(self, image, directory, faces=FACES, threshold=THRESHOLD,
resize=True):
""" Init method
Parameters:
@image: Image with a face
@directory: Directory containing probe images
@faces: Number of faces to compare (defaults to all images
in derectory)
@threshold: Minimun distance between two images to accept them
as similar
@resize: Resize image if it's bigger or smaller than comparision
images
"""
self.image = image
self.directory = directory
self.faces = faces
self.threshold = threshold
self.resize = resize
def match(self):
""" Returns the match image and the distance between them, if any. """
return find_matching_image(self.image, self.directory, self.threshold,
self.faces, self.resize)
def show(self):
""" Shows the matching images joined """
dist, match = self.match()
if match is not None:
merge_images([self.image, match]).show()
return dist, match
def pronounce(match): #ADD VOICE
op,out="None"
if(match=='pl1.png'or match=='pl2.png'or match=='pl3.png'):
op='please'
out='PLEASE'
elif(match=='ty1.png'or match=='ty2.png'or match=='ty3.png'):
op='thank__you'
out='THANK YOU'
f=open('output.txt','w')
f.write(out+"\n")
f.close()
os.system("espeak "+op) #Espeak
if __name__ == '__main__':
parser = optparse.OptionParser()
parser.add_option('-i', '--image', dest='image')
parser.add_option('-d', '--directory', dest='directory')
parser.add_option('-f', '--faces', type='int', default=FACES, dest='faces')
parser.add_option('-t', '--threshold', type='float', default=THRESHOLD,
dest='threshold')
parser.add_option('-s', '--show', default=False, action='store_true',
dest='show')
parser.add_option('-r', '--resize', default=True, action='store_true',
dest='resize')
(options, args) = parser.parse_args()
if not options.image or not options.directory:
parser.print_help()
sys.exit(2)
pyfaces = PyFaces(options.image, options.directory,
options.faces, options.threshold,
options.resize)
if options.show:
dist, match = pyfaces.show()
else:
dist, match = pyfaces.match()
if match is not None:
print 'The input matches "%s" with a distance of "%s"' % \
(match, dist)
pronounce(match)
else:
o='** please contact administrator'
f=open('output.txt','w')
f.write(o+"\n")
f.close()
os.system('espeak please__contact__administrator')