-
Notifications
You must be signed in to change notification settings - Fork 0
/
face.py
54 lines (30 loc) · 1.05 KB
/
face.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
import cv2
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(18,GPIO.OUT)
face_cascade = cv2.CascadeClassifier('/home/pi/opencv-2.4.11/data/haarcascades/haarcascade_frontalface_alt.xml')
cap=cv2.VideoCapture(0)
while(1):
ret, img = cap.read()
GPIO.output(18,GPIO.HIGH)
if ret:
height, width, channels = img.shape
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
res = cv2.resize(gray,(width/4, height/4), interpolation = cv2.INTER_LINEAR)
gray2 = cv2.equalizeHist(res)
face = face_cascade.detectMultiScale(gray2, scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
for (x,y,w,h) in face:
#cv2.rectangle(img,(x*4,y*4),((x+w)*4,(y+h)*4),(255,0,0),0)
print 1
#GPIO.output(18,GPIO.HIGH)
#cv2.imshow('img',img)
#GPIO.output(18,GPIO.LOW)
if(cv2.waitKey(1)=='q'):
cap.release()
cv2.destroyAllWindows()
break