-
Notifications
You must be signed in to change notification settings - Fork 0
/
teste_yale.py
40 lines (31 loc) · 1.25 KB
/
teste_yale.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
import os
import cv2
import numpy as np
from PIL import Image
#recognizer = cv2.face.EigenFaceRecognizer_create()
#recognizer = cv2.face.FisherFaceRecognizer_create()
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("model/LBPH.yml")
path = "yalefaces/teste"
detectorface = cv2.CascadeClassifier('Haar/haarcascade_frontalface_default.xml')
totalhits = 0.0
percentCorrect = 0.0
entireConfidence = 0.0
imagePaths = [os.path.join(path,f) for f in os.listdir(path)]
for imagePath in imagePaths:
faceImg = Image.open(imagePath).convert('L')
faceNp = np.array(faceImg,'uint8')
#equalized = cv2.equalizeHist(faceNp)
detectFaces = detectorface.detectMultiScale(faceNp)
for (x,y,w,h) in detectFaces:
PrevID, Confidence = recognizer.predict(faceNp)
AtID = int(os.path.split(imagePath)[1].split(".")[0].replace("subject",""))
print(str(AtID) + " foi classificado como " + str(PrevID) + " - " + str(Confidence))
if PrevID == AtID:
totalhits += 1
entireConfidence += Confidence
print(totalhits)
percentCorrect = (totalhits / 30) * 100
totalConfidence = entireConfidence / totalhits
print("Total de acertos: " + str(percentCorrect))
print('Total de confiança: ' + str(totalConfidence))