ErsterTest 494 Bytes
Newer Older
1
2
3
4
5
6
7
import numpy as np
import cv2

detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)

while (True):
Arne Gerdes's avatar
Arne Gerdes committed
8
9
10
11
12
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = detector.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
13

Arne Gerdes's avatar
Arne Gerdes committed
14
15
16
    cv2.imshow('frame', img)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
17
18
19

cap.release()
cv2.destroyAllWindows()