AI in Action: How to automate the boring task of blurring car number plates for sharing on social media

Ravi Sawhney
6 min readDec 29, 2019

--

TL;DR — If you want to automate the process of blurring car number plates (aka license, registration plates) or even faces using open source software on a windows machine then read on.

A group of us are members of a car club and do the occasional track day here in the UK. We wanted to share some of the images online but were concerned about bad actors misusing the data to reveal personal information or worse cloning the number plates (several tracks do not allow covering up of plates plus its a pain if you forget to remove during a refuel!). Google obfuscates licence plates as part of its Street View privacy policy so it seems like a good idea to anonymize your own number plate when posting media online.

Currently members were doing this manually using Photoshop or similar software which can blur or pixelate plates but this takes time and the picture may contain several cars.

In the spirit of automating boring tasks (which I qualify this as) I was interested to see if their is technology available to the technically literate person to anonymize licence plates by automatically blurring them in photos.

Automating this type of task requires the software to deal with unstructured information it will never have seen before and this is where the power of AI comes into play.

1. Find some software — Github to the rescue

As a non professional programmer I am amazed by the depth and breadth of software available on Github to solve real world problems. This was my first port of call to see if there is any open source software that could do this.

After some trawling through various repositories I came across Anonmyizer offered by a understand.ai. If you plan on using software from Github beyond personal use you need to educate yourself on the different licences that open source software is offered under (hint: there are many and its not always obvious to know what you can / can’t do). This application was offered under Apache License 2.0 which is friendly for nearly all types of uses.

Look in the LICENSE.txt file

Anonmyizer is written in python and uses Tensorflow, the extremely popular open source machine learning platformed used by Google in its various products. I was keen to try this out and especially make use my 1080 GTX Nvidia GPU for some machine learning. (Note — if you do not have a supported GPU then this tutorial should work with your CPU, it will just take longer to process the images).

2. Install Tensorflow (and NVIDIA CUDA) on Windows 10

It took some searching and trial and errors to find this excellent write-up on how to install Tensorflow with Nvidia CUDA on a Windows 10 machine.

If you use this guide I strongly recommend you follow all the steps in the order they are written. If you already have Python installed then you can skip the step that outlines how to install Python.

Success looks like this!

Note, at time of writing Tensorflow doesn’t work with latest version of Python (3.8) so use 3.7 or below.

3. Install Anonymizer from Github

The instructions from the readme are fairly straightforward but took some tweaks to work for me on windows. Specifically:

  1. Install Git for Windows (if you haven't already) from here.
  2. The requirements.txt file in the repository lists all the packages that need to be installed for the application to work. The version of Tensorflow it suggests you install (1.11.0) was throwing errors for me so I changed this to 1.13.1 and it worked perfectly. Just edit txt file directly with this version once you have installed the repository on your machine.
  3. It is worth using the Python virtualenv feature when installed this package as the readme suggests, this ensures all the requirement packages are kept isolated to this application. There is a good primer here on it for windows 10.
  4. To check if you have successfully installed virtualenv type this:
$ python c:\<path to>\virutalenv.py c:\<path to>\anonymizer 
$ cd anonymizer\Scripts
$ activate

Which should return this:

(anonymizer) $ c:\<path to>\anonmyizer\Scripts

4. Testing your setup for first time

In the virtualenv simply run:

(anonymizer) $ python anonymizer/bin/anonymize.py — input ./images — image-output ./images/output — weights ./weights

Note, when you first run this it will take some time as the application downloads the weight files created as part of the model training process. The good thing is that you do not have the build the model from scratch locally saving you hours (if not days) of electricity.

Processing! What you should see if things are working

If you go to the output folder you should see the successfully processed image.

Provided stock photo — Original
Provided stock photo — After being processed

Want to try something more impressive? Well here are some licence free photos I found on Creative Commons before and after processing.

Image 1 — Original
Image 1 — After being processed
Image 2 — Original
Image 2 — After being processed
Image 3 — Original
Image 3 — After being processed
Image 4 — Original
Image 4 — After being processed

The images above were taken from Creative Commons, the attributions are as follows:

Image 1: “Cadwell Park Track Day Opentrack Track Days 28th July 2013” by Opentrack Track days is licensed under CC BY-NC 2.0

Image 2: “GW-162016_0331_140818AA” by mdlambphotos is licensed under CC BY-SA 2.0

Image 3: “Silverstone Track Day 26th Feb 2017 with Opentrack Track Days” by Opentrack Track days is licensed under CC BY-NC 2.0

Image 4: “GW-162016_0331_145001AA” by mdlambphotos is licensed under CC BY-SA 2.0

5. Tweaking to get best results

As you can see above the results are good across a number of different images several of which contain multiple cars and number plates shown in varying perspectives.

In order to get results this good it took some experimentation with the configuration options of the application. These are already explained in the readme file but this configuration worked well in most cases.

$ python anonymizer/bin/anonymize.py — input ./images — image-output ./images/output — weights ./weights — obfuscation-kernel=”101,3,19" — plate-threshold=0.05

If you find it is not picking up a number plate in an image you can reduce the plate-threshold down to 0.001 to increase the chances but note you might find it blurring other features (false positives).

6. Wait, it works for faces too?

Yes that is right! Whilst I was looking for something that could blur number plates this application also works well on faces as you will see from the other image in the output folder.

Provided stock photo — Original
Provided stock photo — After being processed

Until very recently it would have been impossible to automate this task by someone using their own computer at home. Thanks to advances in AI (data, hardware and open source algorithms) it is possible to find novel uses of this technology to automate the more complex boring tasks.

--

--