-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexemplo2.py
More file actions
68 lines (48 loc) · 2.06 KB
/
exemplo2.py
File metadata and controls
68 lines (48 loc) · 2.06 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
# import lib of openCV
import cv2
#import the haarcascade frontl face
classifier =cv2.CascadeClassifier('cascades\haarcascade_frontalface_default.xml')
#import the haarcascade eye face
eyeClassifier= cv2.CascadeClassifier('cascades\haarcascade_eye.xml')
#import the haarcascede smile face
smileClassifier = cv2.CascadeClassifier('cascades\haarcascade_smile.xml')
#import photo for analyse
imagem = cv2.imread('pessoas\\pessoas2.jpg')
#transform the photo in grayscale
imagemCinza = cv2.cvtColor(imagem,cv2.COLOR_BGR2GRAY)
#detect the frontal face
faceDetectadas = classifier.detectMultiScale(imagemCinza)
#print the matrix of localization of image data
#print(faceDetectadas)
#loop to go through face
for(x, y, l , a ) in faceDetectadas:
#print(x, y, l , a )
# rectangle of information of frontal face
cv2.rectangle(imagem,(x,y),(x + l, y +a),(0,0,255),2)
#region of capture eye in frontal face
regionEye = imagem[y:y+a, x:x+l]
#region of capture smile in frontal face
regionSmile = imagem[y:y+a, x:x+l]
#print(regiao)
#transform to eye place in grayscale
regioGrayEye = cv2.cvtColor(regionEye,cv2.COLOR_BGR2GRAY)
#transform the image in grayscale to capture smile by face
regionGraySmile = cv2.cvtColor(regionSmile, cv2.COLOR_BGR2GRAY)
#detected the eye in image
detectedEye = eyeClassifier.detectMultiScale(regioGrayEye, scaleFactor = 1.01, minNeighbors = 1)
#print(detectedEye)
#test of smile capture
smileDetected = smileClassifier.detectMultiScale(regionGraySmile, scaleFactor= 1.11, minNeighbors=8)
#print(len(smileDetected))
#loop to go through eye face
for(ox, oy, ol, oa) in detectedEye:
#print(ox, oy, ol , oa )
cv2.rectangle(regionEye, (ox,oy),(ox + ol, oy + oa), (0,255,0),2)
#loop to go through smile face
for(sx, sy , sl ,sa) in smileDetected:
#print(sx, sy, sl, sa)
cv2.rectangle(regionSmile, (sx,sy),(sx + sl, sy + sa), (0,255,0),2)
#window show the colect data
cv2.imshow("Faces, Eyes and Smile", imagem)
#wait the key to close window
cv2.waitKey()