Blurring Faces to Preserve Privacy with Computer Vision

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.
- Using the Roboflow API (opens in a new tab) to run the trained model on your custom images.
- Automatically censor detected faces (opens in a new tab) and license plates to anonymize data captured in computer vision projects.
What is Fogging or Blurring in Computer Vision?
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.


Pixelization is 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
Just 3 simple steps:
- Step 1: Collect data
- Step 2: Train a model
- Step 3: Use the Roboflow API to deploy the model
Collect Data of Faces for Model Training
Luckily, we have Roboflow Universe (opens in a new tab) which is home to the world's largest collection of annotated and ready to use datasets related to various industries such as self-driving cars (opens in a new tab) and agriculture (opens in a new tab), to manufacturing (opens in a new tab) and gaming (opens in a new tab) that are open source and free to use. Tip: Search using the keyword 'faces' or 'license plates' and we are ready to go
In addition to downloading the datasets, you can also clone data from Roboflow Universe (opens in a new tab) directly to a project in your Roboflow account.
If you need additional data beyond what is provided in Universe, you can upload Youtube videos as training data (opens in a new tab) or upload your own data (opens in a new tab). Then you'll use Roboflow Annotate to label the data for model training.
Train a Face Detection Model
We then upload our downloaded image dataset to the Roboflow app to train our model to detect faces. This process can be done for any data you want to obfuscate and anonymize such as license plates (opens in a new tab) and identification cards (opens in a new tab).
After uploading your dataset, properly labeling the data, adding augmentations, and generating the dataset, you can train a computer vision model with one-click using Roboflow Train.
Below are the results after training the model using the Accurate model (opens in a new tab) in Roboflow.

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:
pip install inference-sdk supervisionRun 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.
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):
roi = sv.crop_image(image=image, xyxy=detections.xyxy[0])
To blur every face, use BlurAnnotator. A larger kernel_size gives a stronger blur; 35 hides facial features without overdoing it.
blur_annotator = sv.BlurAnnotator(kernel_size=35)
blurred = blur_annotator.annotate(scene=image.copy(), detections=detections)
cv2.imwrite("blurred.jpg", blurred)To pixelate instead, use PixelateAnnotator. A larger pixel_size gives bigger blocks.
pixelate_annotator = sv.PixelateAnnotator(pixel_size=12)
pixelated = pixelate_annotator.annotate(scene=image.copy(), detections=detections)
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 annotator works frame by frame. sv.process_video reads a video, runs your callback on each frame, and writes the anonymized result:
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 blur_annotator.annotate(scene=frame.copy(), detections=detections)
sv.process_video(source_path="input.mp4", target_path="blurred.mp4", callback=callback)Privacy Safeguards in Roboflow Enterprise
To enforce masking across every camera and upload, not just one script, the Roboflow Enterprise platform builds it in. Talk to sales to set it up for your team.

Start Your First Blurring Project with Computer Vision
Hopefully you can use parts of this application to build your own project. To get started, find a dataset in Roboflow Universe (opens in a new tab), consider the best method for deploying your model, and ship your first project.
If you end up building something, please share it in our forum (opens in a new tab)!