๐ŸŽ™ Free live masterclass ยท Sun, 29 Nov, 7:00 pm IST ยท Java Full Stack roadmap Register free โ†’
Skills101

Real-time face detection and blur

Detect faces from your webcam in real time and automatically blur them, a privacy tool for videos.

Beginnerโฑ 4โ€“6 hours๐Ÿชœ 7 stepsPythonOpenCV

What you'll learn

  • โ—†Reading video frames with OpenCV
  • โ—†Face detection with a pretrained model
  • โ—†Image operations (blur, draw)

What you'll build

  • โœ“Live webcam face boxes
  • โœ“Blur mode for privacy
  • โœ“Process a saved video file
  • โœ“FPS counter

Step-by-step guide

  1. 1

    Install

    pip install opencv-python.

  2. 2

    Read the webcam

    cap = cv2.VideoCapture(0); loop ret, frame = cap.read(); cv2.imshow; quit on "q".

  3. 3

    Detect faces

    Use cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml") or the DNN face detector for better accuracy.

  4. 4

    Draw or blur

    cv2.rectangle for boxes; for blur, frame[y:y+h, x:x+w] = cv2.GaussianBlur(face, (51, 51), 30).

  5. 5

    Video files

    Read a file with VideoCapture(path) and write the result with cv2.VideoWriter.

  6. 6

    FPS

    Measure time per frame and draw the FPS with cv2.putText.

  7. 7

    Ethics

    Only record people who agreed. Mention privacy in your README.

๐Ÿš€ Make it stand out

  • +Pixelate instead of blur
  • +Detect and blur number plates
  • +Compare Haar vs DNN accuracy