-
Notifications
You must be signed in to change notification settings - Fork 0
/
face_detector.py
37 lines (24 loc) · 957 Bytes
/
face_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
35
36
37
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
profileface_cascade = cv2.CascadeClassifier('haarcascade_profileface.xml')
smile_cascade = cv2.CascadeClassifier('haarcascade_smile.xml')
capture = cv2.VideoCapture(0)
while True :
_, img = capture.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.1, 2)
eye= eye_cascade.detectMultiScale(gray,1.5,2)
profileface = profileface_cascade.detectMultiScale(gray, 1.1, 3)
smile = smile_cascade.detectMultiScale(gray,1.1,30)
for(x,y,w,h) in eye:
cv2.rectangle(img, (x,y) , (x+w, y+h), (38,226,240), 1)
for(x,y,w,h) in faces:
cv2.rectangle(img, (x,y) , (x+w, y+h), (0,255,0), 1)
for(x,y,w,h) in smile:
cv2.rectangle(img, (x,y) , (x+w, y+h), (0,0,255), 1)
cv2.imshow('img',img)
k= cv2.waitKey(30) & 0xff
if k==27:
break
capture.release()