A small Python app that captures a live webcam stream and runs real-time face detection using a pre-trained MediaPipe model.
This repository is being built step-by-step toward a simple face filter overlay and optional background segmentation.
- Live webcam capture (OpenCV)
- Real-time face detection (MediaPipe Face Detection, pre-trained)
- Draws a bounding box around the detected face
- PNG overlay filter (transparent PNG blended onto the webcam feed)
- Background segmentation (MediaPipe Selfie Segmentation, pre-trained)
- Background replacement modes: blur / solid color / image
- Modular project structure (
src/package)
Place a transparent PNG overlay here:
assets/glasses.pngbackground.jpg— optional background image for mode3(any JPG/PNG)
The PNG must contain an alpha channel (transparency). The overlay is resized relative to the detected face box and alpha-blended onto the frame.
From the project root:
conda env create -f environment.yml
conda activate webcam-ai-filter
conda activate webcam-ai-filterpython -m src.mainq— quit the appb— toggle background effect (none ↔ blur)1— solid background2— blur background3— background image (requiresassets/background.jpg)
- OpenCV frames are BGR by default; MediaPipe expects RGB (conversion is done in code).
- Background segmentation is real-time but may reduce FPS depending on camera resolution. The app uses downscaling and mask smoothing for performance/quality.
- Add overlay filter (PNG with alpha blending) based on direction of view
- Add simple face tracking / smoothing
- Add background segmentation and replacement