import cv2 as cv
import dlib
def draw_rect(img, faces):
    for face in faces:
        cv.rectangle(img,(face.left(),face.top()),(face.right(),face.bottom()),(0,255,0),2)
    return img

if __name__ == '__main__':
    cap = cv.VideoCapture(0)
    while True:
        ret, frame = cap.read()
        if not ret:
            break
        frame_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        detector = dlib.get_frontal_face_detector()
        result = detector(frame_gray,1)
        img_reslut = draw_rect(frame.copy(),result)
        cv.imshow("frame",img_reslut)
        cv.waitKey(1)
    cap.release()
