Detects faces and licence plates in images and videos, then replaces them with realistic AI-generated content instead of black boxes or blur.
Faces and licence plates in photos and videos are personal data under GDPR and CCPA. Classic anonymization (blur, black boxes) protects privacy but ruins the image. This project detects sensitive regions and regenerates them with a diffusion model, so the result stays private and still looks natural.
Image / video frame
│
├─► Face detection ── InsightFace SCRFD (buffalo_l)
├─► Plate detection ─ YOLO (custom weights, optional) → OpenCV Haar cascade fallback
│
▼
Binary mask from bounding boxes (+ adjustable dilation)
│
▼
Stable Diffusion 2 inpainting (diffusers) ── prompt + negative prompt
│
▼
Optional synthetic plate text ──► anonymized image / video
- Face detection with InsightFace SCRFD, running on GPU when available and falling back to CPU
- Licence plate detection with YOLO (bring your own
.ptweights), falling back to an OpenCV Haar cascade - Generative inpainting with
stabilityai/stable-diffusion-2-inpainting, with tunable steps and guidance - Synthetic plate text: draws a random fake plate number over detected plates
- Mask controls: separate dilation for faces and plates, plus a live red mask-overlay preview
- Video anonymization: processes MP4s frame by frame with a frame limit for demos
- Quality evaluation: PSNR and SSIM computed on the non-masked regions, to check that the rest of the image is preserved
- Streamlit UI with Image, Video, Evaluation and Datasets tabs, and a download button for the result
git clone https://github.com/Anupbhagat77/<repo-name>.git
cd <repo-name>
docker compose up --buildOpen http://localhost:8501. The first inpainting run downloads the Stable Diffusion model (~1–2 GB), which is cached in a Docker volume for later runs.
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
streamlit run app/streamlit_app.py💡 A CUDA GPU makes inpainting much faster. On CPU each image takes noticeably longer.
app/
├── streamlit_app.py # UI: image, video, evaluation and dataset tabs
├── detectors.py # InsightFace face detection, YOLO + Haar plate detection
├── inpaint.py # Stable Diffusion 2 inpainting pipeline
└── utils.py # masks, overlays, fake plate text
data/ # inputs (git-ignored)
outputs/ # results (git-ignored)
Dockerfile
docker-compose.yml
requirements.txt
- Fine-tune a YOLO model on CCPD for more robust plate detection
- Speed up video by detecting on keyframes and tracking between them
- Identity-leakage checks, such as face-recognition similarity before vs. after
University project at HTW Berlin. Technical implementation (detection pipeline, generative inpainting, evaluation and UI) by Anup Bhagat.