import cv2

## python3 -m pip install opencv-contrib-python

alg = "haarcascade_frontalface_default.xml"

#haar_cascade = cv2.CascadeClassifier(alg)
haar_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + alg)

## -1 on linux, 0 on windows
cam = cv2.VideoCapture(-1)

while True:
    _,img = cam.read()
    grayImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    face = haar_cascade.detectMultiScale(grayImg, 1.3, 4)
    for (x, y, w, h) in face:
        cv2.rectangle(img, (x,y), (x+w, y+h), (0, 255,0), 2)
    cv2.imshow("FaceDetection", img)
    key = cv2.waitKey(10)
    if key == 27:
        break
cam.release()
cv2.destroyAllWindows()
