-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_face.py
More file actions
34 lines (25 loc) · 767 Bytes
/
Copy pathbuild_face.py
File metadata and controls
34 lines (25 loc) · 767 Bytes
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
from imutils.video import VideoStream
import imutils
import time
import cv2
import os
def build_face(path):
detector = cv2.CascadeClassifier("models/haarcascade_frontalface_default.xml")
vs = VideoStream(src=0 + cv2.CAP_DSHOW).start()
time.sleep(2.0)
total = 0
for _ in range(15):
frame = vs.read()
orig = frame.copy()
frame = imutils.resize(frame, width=400)
rects = detector.detectMultiScale(
cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), scaleFactor=1.1,
minNeighbors=5, minSize=(30, 30))
for (x, y, w, h) in rects:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
p = os.path.sep.join([path, "{}.png".format(str(total).zfill(5))])
cv2.imwrite(p, orig)
total += 1
time.sleep(0.25)
cv2.destroyAllWindows()
vs.stop()