Skip to content

Commit a2d8d41

Browse files
committed
add face_video.py
1 parent 22a9cf8 commit a2d8d41

File tree

2 files changed

+33351
-0
lines changed

2 files changed

+33351
-0
lines changed

face_video.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import cv2
2+
import sys
3+
import time
4+
5+
cascPath = 'haarcascade_frontalface_default.xml'
6+
faceCascade = cv2.CascadeClassifier(cascPath)
7+
8+
video_capture = cv2.VideoCapture(0)
9+
10+
fourcc = cv2.VideoWriter_fourcc(*'XVID')
11+
out = cv2.VideoWriter('face_video.avi', fourcc, 8.0, (640,480))
12+
start = time.time()
13+
while time.time() - start < 20:
14+
# Capture frame-by-frame
15+
ret, frame = video_capture.read()
16+
17+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
18+
19+
faces = faceCascade.detectMultiScale(
20+
gray,
21+
scaleFactor=1.1,
22+
minNeighbors=5
23+
)
24+
25+
# Draw a rectangle around the faces
26+
for (x, y, w, h) in faces:
27+
print('x:', x, 'y:', y, 'w:', w, 'h:', h)
28+
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
29+
30+
# Display the resulting frame
31+
out.write(frame)
32+
#cv2.imshow('Video', frame)
33+
out.release()
34+
35+
# When everything is done, release the capture
36+
video_capture.release()
37+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)