-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmile_detection.py
More file actions
25 lines (21 loc) · 845 Bytes
/
smile_detection.py
File metadata and controls
25 lines (21 loc) · 845 Bytes
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
import cv2
face_cascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
smile_cascade=cv2.CascadeClassifier('haarcascade_smile.xml')
cap=cv2.VideoCapture(0)
# img=cv2.imread('messi5.jpg')
while cap.isOpened():
_,img=cap.read()
gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces=face_cascade.detectMultiScale(gray, 1.1,4)
for (x,y,w,h) in faces:
cv2.rectangle(img, (x,y), (x+w,y+h), (255,255,0), 3)
region_of_interest=gray[y:y+h, x:x+w]
region_of_interest_color=img[y:y+h, x:x+w]
smile=smile_cascade.detectMultiScale(region_of_interest)
for (sx, sy, sw, sh) in smile:
cv2.rectangle(region_of_interest_color, (sx,sy), (sx+sw,sy+sh), (0,255,0),5)
cv2.imshow('img',img)
if cv2.waitKey(1) & 0xFF==ord('q'):
break
cap.release()
cv2.destroyAllWindows()