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?

  1. How to train models to detect faces and license plates from a given image.
  2. Using the Roboflow API to run the trained model on your custom images.
  3. Automatically censor detected faces 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.

Example of face blurring or fogging with computer vision
Example of license plate fogging

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.

Google Maps blurring faces preserving 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 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 and agriculture, to manufacturing and gaming that are open source and free to use. Tip: Search using the keyword 'faces' or 'license plates' and we are ready to go

0:00
/
Visual tutorial on how to collect data using Roboflow Universe

In addition to downloading the datasets, you can also clone data from Roboflow Universe 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 or upload your own data. Then you'll use Roboflow Annotate to label the data for model training.

Train a Facial Recognition 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 and identification cards.

0:00
/
Steps to train a face blurring model using Roboflow

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 in Roboflow.

One-click training results using Roboflow

Along with model performance data, we also have access to visualizations for the training and validation curves.

Model training visualizations

Using the Computer Vision Model to Censor the Region of Interest (ROI)

After successfully training the model, go to the Deploy page and use the API script provided to censor the images.

Roboflow deployment API

Using Roboflow API is straightforward, install using pip:

pip install roboflow

After successful installation,

  1. Import the Roboflow module,
  2. Enter your API key,
  3. Call your project name,
  4. Choose your model version.

Use predict function and choose the confidence and overlap threshold values suitable to your custom needs.

Sample JSON output from predict function

After the prediction, extract the region of interest (ROI):

Blur or Pixelate the ROI as below:

Blur:

Pixelate:

Example usage of protecting children's privacy

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, 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!