-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebcamCapture.py
40 lines (32 loc) · 912 Bytes
/
webcamCapture.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
import cv2
from faceDetect import faceDetect
cv2.namedWindow("preview",flags=cv2.WINDOW_NORMAL)
vc = cv2.VideoCapture(0)
faceDetector = faceDetect()
class CurFrame:
def __init__(self):
self.frame = None
def getFrame(self):
return self.frame
def updateFrame(self, newFrame):
self.frame = newFrame
if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False
cf = CurFrame()
cf.updateFrame(frame)
faceDetector.checkForFace(cf)
facesSeen = 0
while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
cf.updateFrame(frame)
allFaces = faceDetector.allFaces()
for face in allFaces:
cv2.rectangle(frame, (face[0],face[1]), (face[0]+face[2],face[1]+face[3]),(0, 255, 0))
key = cv2.waitKey(20)
if key == 27: # exit on ESC
faceDetector.stopLoop()
break
cv2.destroyWindow("preview")