-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmile-detection
55 lines (47 loc) · 1.26 KB
/
smile-detection
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import numpy as np
import cv2
import sys
facePath = 'haarcascade_frontalface_default.xml'
smilePath = 'haarcascade_smile.xml'
face_cascade = cv2.CascadeClassifier(facePath)
smile_cascade = cv2.CascadeClassifier(smilePath)
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
sF=1.05
a=0
while True:
if a==1:
img_name = "opencv_frame_complete.png"
cv2.imwrite(img_name, img)
break
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(
gray,
scaleFactor=sF,
minNeighbors=8,
minSize=(55, 55),
flags=cv2.CASCADE_SCALE_IMAGE
)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x,y), (x+w, y+h), (255, 0, 0), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
smile=smile_cascade.detectMultiScale(
roi_gray,
scaleFactor=1.7,
minNeighbors=22,
minSize=(25, 25),
flags=cv2.CASCADE_SCALE_IMAGE
)
for (x, y, w, h) in smile:
print ("Found"), len(smile), ("smiles")
cv2.rectangle(roi_color, (x, y), (x+w, y+h), (0, 0, 255), 1)
a=1
cv2.imshow('Face', img)
k=cv2.waitKey(30) & 0xff
if k==27:
break
cap.release()
cv2.destroyAllWindows()