-
Notifications
You must be signed in to change notification settings - Fork 0
/
reconhecedor_fisherfaces.py
33 lines (29 loc) · 1.23 KB
/
reconhecedor_fisherfaces.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
import cv2
detectorFace = cv2.CascadeClassifier("resources/haarcascade_frontalface_default.xml")
reconhecedor = cv2.face.FisherFaceRecognizer_create()
reconhecedor.read("resources/classificadorFisher.yml")
largura, altura = 220, 220
font = cv2.FONT_HERSHEY_COMPLEX_SMALL
camera = cv2.VideoCapture(0)
while (True):
conectado, imagem = camera.read()
imagemCinza = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY)
facesDetectadas = detectorFace.detectMultiScale(imagemCinza,
scaleFactor=1.5,
minSize=(30,30))
for (x, y, l, a) in facesDetectadas:
imagemFace = cv2.resize(imagemCinza[y:y + a, x:x + l], (largura, altura))
cv2.rectangle(imagem, (x, y), (x + l, y + a), (0,0,255), 2)
id, confianca = reconhecedor.predict(imagemFace)
nome = ""
if id == 1:
nome = 'Vanderson'
elif id == 2:
nome = 'Ludmila'
cv2.putText(imagem, nome, (x,y +(a+30)), font, 2, (0,0,255))
cv2.putText(imagem, str(confianca), (x,y + (a+50)), font, 1, (0,0,255))
cv2.imshow("Face", imagem)
if cv2.waitKey(1) == ord('q'):
break
camera.release()
cv2.destroyAllWindows()