import cv2
import sys
import playsound

face_cascade = cv2.CascadeClassifier('cascades/haarcascade_frontalface_default.xml')

# capture video using cv2
video_capture = cv2.VideoCapture(0)

while True:
    # capture frame by frame, i.e, one by one 
    ret, frame = video_capture.read()
    
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    
    # for each face on the projected on the frame
    faces = face_cascade.detectMultiScale(
        gray,
        scaleFactor = 1.1,
        minNeighbors = 5, 
        # minSize(35, 35)
    )
    
    # loop through the video faces for detection
    for (x, y, w, h) in faces:
        point1 = x+w
        point2 = y+h
        frame_color = (50, 50, 200)
        
        rectangleBox = cv2.rectangle(frame, (x, y), (point1, point2), frame_color, 2)
        cv2.imshow('video', frame)
        if faces.any():
            playsound.playsound('openDoorAlert.mp3', True)
            
            if len(faces) > 1:
                print("There are " + str(len(faces)) + " peoples at the gate")
            else:
                print("There is " + str(len(faces)) + " person at the gate")
        else:
            pass
        if cv2.waitKey(1) & 0xFF == ord('q'):
            sys.exit()
        

[((5, 15, 5, 84), 'cv2.CascadeClassifier', 'cv2.CascadeClassifier', ({(5, 37, 5, 83): '"""cascades/haarcascade_frontalface_default.xml"""'}, {}), "('cascades/haarcascade_frontalface_default.xml')", False, 'import cv2\n'), ((8, 16, 8, 35), 'cv2.VideoCapture', 'cv2.VideoCapture', ({(8, 33, 8, 34): '0'}, {}), '(0)', False, 'import cv2\n'), ((14, 11, 14, 50), 'cv2.cvtColor', 'cv2.cvtColor', ({(14, 24, 14, 29): 'frame', (14, 31, 14, 49): 'cv2.COLOR_BGR2GRAY'}, {}), '(frame, cv2.COLOR_BGR2GRAY)', False, 'import cv2\n'), ((30, 23, 30, 85), 'cv2.rectangle', 'cv2.rectangle', ({(30, 37, 30, 42): 'frame', (30, 44, 30, 50): '(x, y)', (30, 52, 30, 68): '(point1, point2)', (30, 70, 30, 81): 'frame_color', (30, 83, 30, 84): '2'}, {}), '(frame, (x, y), (point1, point2), frame_color, 2)', False, 'import cv2\n'), ((31, 8, 31, 34), 'cv2.imshow', 'cv2.imshow', ({(31, 19, 31, 26): '"""video"""', (31, 28, 31, 33): 'frame'}, {}), "('video', frame)", False, 'import cv2\n'), ((33, 12, 33, 58), 'playsound.playsound', 'playsound.playsound', ({(33, 32, 33, 51): '"""openDoorAlert.mp3"""', (33, 53, 33, 57): '(True)'}, {}), "('openDoorAlert.mp3', True)", False, 'import playsound\n'), ((42, 12, 42, 22), 'sys.exit', 'sys.exit', ({}, {}), '()', False, 'import sys\n'), ((41, 11, 41, 25), 'cv2.waitKey', 'cv2.waitKey', ({(41, 23, 41, 24): '(1)'}, {}), '(1)', False, 'import cv2\n')]