forked from twtrubiks/FaceDetect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathface_detect_camera.py
More file actions
28 lines (24 loc) · 893 Bytes
/
Copy pathface_detect_camera.py
File metadata and controls
28 lines (24 loc) · 893 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
import cv2
def main():
face_detect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
name = "twtrubiks"
number = 0
cam = cv2.VideoCapture(0)
while True:
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# faces = face_detect.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5, minSize=(200, 200))
faces = face_detect.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=5)
for (x, y, w, h) in faces:
number += 1
cv2.imwrite("camera/{}.{}.jpg".format(name, number), gray[y:y + h, x:x + w])
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.waitKey(100)
cv2.imshow("Face", img)
cv2.waitKey(1)
if number >= 10:
break
cam.release()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()