This project provides a real-time face blurring (and pixelation) tool using your webcam. It uses OpenCV’s deep learning face detector and a tracker for smooth, fast face anonymization.
- Real-time webcam feed
- Face detection using OpenCV DNN (SSD Caffe model)
- Face tracking for performance
- Two anonymization modes:
- Blur (default)
- Pixelate (press
pto switch)
- Switch modes on the fly (
bfor blur,pfor pixelate) - Mirror image display (like a selfie camera)
- Python 3.x
- OpenCV (with contrib modules)
- Webcam
-
Install dependencies:
pip install opencv-contrib-python
-
Download the face detection model files:
- res10_300x300_ssd_iter_140000.caffemodel
- deploy.prototxt
- Place both files in the same directory as
face_blur.py.
-
Run the script:
python face_blur.py
- The webcam window will open and display a mirrored video feed.
- Detected faces will be blurred (default) or pixelated.
- Press
bto switch to blur mode. - Press
pto switch to pixelate mode. - Press
qto quit.
- Uses a DNN model to detect faces in the webcam feed.
- Initializes a tracker on the detected face for smooth, fast updates.
- Applies either a blur or pixelation effect to the face region.
- Overlays the processed face back onto the video frame.
- Displays the result in real time.
- The script uses OpenCV’s legacy tracker API. If you get errors, ensure you have
opencv-contrib-pythoninstalled. - For best results, use in a well-lit environment.
MIT License