-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
44 lines (37 loc) · 1.3 KB
/
test.py
File metadata and controls
44 lines (37 loc) · 1.3 KB
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
import cv2
import os
import numpy as np
import argparse as ap
parser = ap.ArgumentParser()
parser.add_argument('-i', "--image", help="Path to the test image", required=True)
parser.add_argument('-c', "--classes", help="Path to the classes", required=True)
parser.add_argument('-w', '--width', help="width to resize",default=100,type=int)
parser.add_argument('-e', '--height', help="height to resize",default=100,type=int)
parser.add_argument('-a', '--algorithm', help="1-LBPH, 2-Eigenfaces",default=1,type=int)
args = vars(parser.parse_args())
test_img = cv2.imread(args["image"],0)
test_img=cv2.resize(test_img,(args["width"],args["height"]))
if args["algorithm"]==1:
face_recognizer = cv2.face.LBPHFaceRecognizer_create()
elif args["algorithm"]==2:
face_recognizer = cv2.face.EigenFaceRecognizer_create()
else:
print("Error, not valid")
exit(0)
face_recognizer.read('trainingData.yml')
name = {}
file = open(args["classes"], "r")
for i,line in enumerate(file):
name[i+1]=line.strip()
file.close()
print(name)
label, confidence = face_recognizer.predict(test_img)
print("label: ", label)
print("confidence: ", confidence)
predicted_name = name[label]
if confidence > 50:
predicted_name = "unknown, "
predicted_name += str(confidence)
print(predicted_name)
cv2.waitKey(0)
cv2.destroyAllWindows()