-
Notifications
You must be signed in to change notification settings - Fork 0
/
detector.py
34 lines (33 loc) · 1.23 KB
/
detector.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
import cv2
import numpy as np
recognizer =cv2.face.LBPHFaceRecognizer_create()
recognizer.read('trainner/trainner.yml')
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath)
cam = cv2.VideoCapture(0)
#font = cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 1, 1)
font = cv2.FONT_HERSHEY_SIMPLEX
while True:
ret, im =cam.read()
gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
faces=faceCascade.detectMultiScale(gray,1.2,5)
for(x,y,w,h) in faces:
cv2.rectangle(im,(x,y),(x+w,y+h),(225,0,0),2)
Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
#cv2.cv.PutText(cv2.cv.fromarray(im),str(Id), (x,y+h),font, 255)
#Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
print(conf,Id)
if conf<200 :
if Id==4:
Id="Shubham"
#elif Id==3:
# Id="case"
else:
Id="Dilshad khan"
#cv2.cv.PutText(cv2.cv.fromarray(im),str(Id), (x,y+h),font, 255)
cv2.putText(im, str(Id), (x,y+h), font, 1, (255,255,255), 2, cv2.LINE_AA)
cv2.imshow('im',im)
if cv2.waitKey(1) & 0xFF==ord('q'):
break
cam.release()
cv2.destroyAllWindows()