-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimageClassifier.py
More file actions
27 lines (25 loc) · 847 Bytes
/
imageClassifier.py
File metadata and controls
27 lines (25 loc) · 847 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
#!/usr/bin/env python3
import os, sys
#stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import face_recognition as fr
#sys.stderr = stderr
class Rekognize:
def __init__(self):
self.database = "Database/"
self.known = []
for img in os.listdir(self.database):
self.known.append(fr.face_encodings(fr.load_image_file(self.database + img))[0])
self.images = "Images/"
print("Successfully started the imageClassifier")
def classify(self, filename):
print("Classifying filename")
img = fr.load_image_file(filename)
try:
results = fr.compare_faces(self.known, fr.face_encodings(img)[0], tolerance=0.5)
sys.stdout.flush()
return os.listdir(self.database)[results.index(True)].split(".")[0]
except IndexError:
return None
# nothing was returned. Default: return NoneType
return None