-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFace.py
27 lines (24 loc) · 1023 Bytes
/
getFace.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
from SimpleCV import Camera, Display, VideoStream, VirtualCamera, Color
from time import sleep
import numpy
cam = Camera(prop_set={'width':320, 'height':240})
dis = Display(resolution=(320,240))
lastCoordinates = (0,0)
vidStream = VideoStream("test.mov", 25, True)
while not dis.isDone():
frame = cam.getImage()
faces = frame.findHaarFeatures('face')
if faces:
for face in faces:
# Checks to see if the (x,y) is greater than or less than the last (x,y). Then we have motion.
if face.coordinates()[0] > lastCoordinates[0]+3 or face.coordinates()[1] > lastCoordinates[1]+3 or face.coordinates()[0] < lastCoordinates[0]-3 or face.coordinates()[1] < lastCoordinates[1]-3:
lastCoordinates = face.coordinates()
face.draw()
frame.save(vidStream)
# Show the image
frame.show()
# My attempt to get around 30 frames per second.. though I haven't checked this.
sleep(1./30.)
if dis.IsDone():
cam.close()
dis.close()