Automatically blurring faces and license plates before data enters a storage pipeline is a practical way to handle personally identifiable information in computer vision deployments, following the same approach used by Google Maps Street View. This tutorial covers collecting face and license plate datasets from Roboflow Universe, training a detection model, and using the Roboflow API to run inference and then apply OpenCV blur or pixelation to each detected region of interest. The result is an anonymization step that can be inserted into any image or video pipeline without changing downstream processing.
Quote of the day: “Keep calm and carry on.” -Winston Churchill
Computer vision applications can be used in a variety of settings and sometimes information captured in your dataset might not be information you want to be responsible for having such as personally identifiable information, banking information, or any other sensitive data.
In these instances, you can ensure the data is anonymized by blurring, pixelating, or fogging any specific data before it enters your database. This post will show you how to do this using computer vision.
What to expect from this blog post?
How to train models to detect faces and license plates from a given image.
Fogging, also known as blurring, is used for censorship or privacy in which a visual area of any image, video, or livestream is blurred to obscure the data captured.
Pixelizationis also a form of fogging. This technique is used widely across industries from street mapping to news reporting to social media.
Example: Face Blurring Used in Google Maps
When Street View imagery is published to Google Maps, Google employs censoring faces to protect individuals’ privacy.
Steps Involved for Blurring Faces with Computer Vision
Along with model performance data, we also have access to visualizations for the training and validation curves.
Using the Computer Vision Model to Censor the Region of Interest (ROI)
After successfully training the model, go to the Deploy page (opens in a new tab) and use the API script provided to censor the images.
After training, call your model from Python with the Roboflow inference SDK, then use supervision (opens in a new tab), Roboflow's open source computer vision library, to blur or pixelate every detected face. Install both packages:
Shell
pip install inference-sdk supervision
Run the model on an image and convert the response into a supervision Detections object. Replace MODEL_ID with your project ID and version from your model's Deploy page (opens in a new tab), and add your Roboflow API key.
Python
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient
client = InferenceHTTPClient(
api_url="https://serverless.roboflow.com",
api_key="YOUR_ROBOFLOW_API_KEY",
)
MODEL_ID = "your-project/1" # your face (or license plate) model ID and version
image = cv2.imread("people.jpg")
result = client.infer(image, model_id=MODEL_ID)
detections = sv.Detections.from_inference(result)
detections = detections[detections.confidence > 0.4]
The model returns one prediction per face with the box center, width, height, class, and confidence:
After the prediction, extract the region of interest (ROI):
Python
roi = sv.crop_image(image=image, xyxy=detections.xyxy[0])
To blur every face, use BlurAnnotator. Faces are oval, so the helper below keeps the blur inside an ellipse fitted to each box instead of the whole rectangle. A larger kernel_size gives a stronger blur; 35 hides facial features without smearing the area around the face.
Python
import numpy as np
def anonymize(image, detections, annotator):
annotated = annotator.annotate(scene=image.copy(), detections=detections)
mask = np.zeros(image.shape[:2], dtype=np.uint8)
for x1, y1, x2, y2 in detections.xyxy.astype(int):
center = ((x1 + x2) // 2, (y1 + y2) // 2)
axes = ((x2 - x1) // 2, (y2 - y1) // 2)
cv2.ellipse(mask, center, axes, 0, 0, 360, 255, -1)
return np.where(mask[..., None] == 255, annotated, image)
blur_annotator = sv.BlurAnnotator(kernel_size=35)
blurred = anonymize(image, detections, blur_annotator)
cv2.imwrite("blurred.jpg", blurred)
To pixelate instead, pass a PixelateAnnotator to the same helper. A larger pixel_size gives bigger blocks.
Python
pixelate_annotator = sv.PixelateAnnotator(pixel_size=12)
pixelated = anonymize(image, detections, pixelate_annotator)
cv2.imwrite("pixelated.jpg", pixelated)
Both annotators cover every face the model finds, so group photos and crowded scenes are handled in one call.
Blur Faces in Video
The same helper works frame by frame. sv.process_video reads a video, runs your callback on each frame, and writes the anonymized result:
Python
def callback(frame, index):
result = client.infer(frame, model_id=MODEL_ID)
detections = sv.Detections.from_inference(result)
detections = detections[detections.confidence > 0.4]
return anonymize(frame, detections, blur_annotator)
sv.process_video(source_path="input.mp4", target_path="blurred.mp4", callback=callback)
Start Your First Blurring Project with Computer Vision