Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

🛡️ Privacy-Preserving Vision with Generative Inpainting

Detects faces and licence plates in images and videos, then replaces them with realistic AI-generated content instead of black boxes or blur.

Python PyTorch Stable Diffusion Hugging Face OpenCV YOLO Streamlit Docker


📌 Why

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.

⚙️ How it works

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

✨ Features

  • Face detection with InsightFace SCRFD, running on GPU when available and falling back to CPU
  • Licence plate detection with YOLO (bring your own .pt weights), 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

🚀 Getting started

Option A: Docker

git clone https://github.com/Anupbhagat77/<repo-name>.git
cd <repo-name>
docker compose up --build

Open 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.

Option B: Local Python

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.

📁 Project structure

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

🔮 Future work

  • 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

👥 Credits

University project at HTW Berlin. Technical implementation (detection pipeline, generative inpainting, evaluation and UI) by Anup Bhagat.


More projects on my portfolio · LinkedIn

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages