Automatically detect and blur all faces in a video stream in real time — useful for GDPR compliance, public-space cameras, research datasets, and any application where identity must be protected without losing the utility of the video.
What you will learn
- How to detect faces at 60+ FPS using a lightweight YOLOv8 face model
- How to apply Gaussian blur, pixelation, or black-box anonymisation
- How to process and save anonymised video files offline
- How to balance detection accuracy vs processing speed
- GDPR and privacy considerations for AI vision systems
Step 1 — Run the face blur demo
cd ~/tutorials/13-face-blur
python3 face_blur.py --source 0 --method gaussian --show
Step 2 — Three blur methods
def blur_region(frame, x1, y1, x2, y2, method='gaussian'):
roi = frame[y1:y2, x1:x2]
if method == 'gaussian':
blurred = cv2.GaussianBlur(roi, (51, 51), 30)
elif method == 'pixelate':
h, w = roi.shape[:2]
temp = cv2.resize(roi, (w//10, h//10))
blurred= cv2.resize(temp, (w, h), interpolation=cv2.INTER_NEAREST)
elif method == 'blackout':
blurred = np.zeros_like(roi)
frame[y1:y2, x1:x2] = blurred
return frame
Step 3 — Process and save a full video file
python3 face_blur.py --source ~/videos/original.mp4 --method pixelate --output ~/videos/anonymised.mp4