this is a demo of blurring faces in video please note this example requires opencv the cv2 library to be installed only to read from your webcam opencv is not required to use the facerecognition library it s only required if you want to run this specific demo if you have trouble installing it try any of the other demos that don t require it instead get a reference to webcam 0 the default one initialize some variables grab a single frame of video resize frame of video to 14 size for faster face detection processing find all the faces and face encodings in the current frame of video display the results scale back up face locations since the frame we detected in was scaled to 14 size extract the region of the image that contains the face blur the face image put the blurred face region back into the frame image display the resulting image hit q on the keyboard to quit release handle to the webcam this is a demo of blurring faces in video please note this example requires opencv the cv2 library to be installed only to read from your webcam opencv is not required to use the face_recognition library it s only required if you want to run this specific demo if you have trouble installing it try any of the other demos that don t require it instead get a reference to webcam 0 the default one initialize some variables grab a single frame of video resize frame of video to 1 4 size for faster face detection processing find all the faces and face encodings in the current frame of video display the results scale back up face locations since the frame we detected in was scaled to 1 4 size extract the region of the image that contains the face blur the face image put the blurred face region back into the frame image display the resulting image hit q on the keyboard to quit release handle to the webcam
import face_recognition
import cv2








video_capture = cv2.VideoCapture(0)


face_locations = []

while True:
    
    ret, frame = video_capture.read()

    
    small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

    
    face_locations = face_recognition.face_locations(small_frame, model="cnn")

    
    for top, right, bottom, left in face_locations:
        
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4

        
        face_image = frame[top:bottom, left:right]

        
        face_image = cv2.GaussianBlur(face_image, (99, 99), 30)

        
        frame[top:bottom, left:right] = face_image

    
    cv2.imshow('Video', frame)

    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break


video_capture.release()
cv2.destroyAllWindows()