Blur faces in a photo without uploading it anywhere

Before I share a photo with other people in it, I often want to hide their faces. The quick tools for that are mostly websites, and they all start the same way: upload your photo first. That is the opposite of what I want when the reason is privacy.

So I built Face Blur. It is a small Python tool that finds the faces in a photo and blurs them, on your own computer. You can use one command, or a local web page where you choose the faces. It needs no account and no internet connection, and the photo never leaves your machine.

What it does

  • Auto mode: one command finds every face and blurs it, then prints how many faces it blurred.
  • Manual mode: a local web page shows a box on each face. Click a box to turn the blur on or off. Switch to Draw and drag a rectangle over anything else you want to hide, like a name tag or a face the detector missed. Then preview and download.
  • Three methods: a soft blur, pixelate, or one flat colour, with a strength from 1 to 10.
  • Fair on every face: the blur grows with the size of each face, so a small face at the back is as hidden as a large one in front.

Nothing leaves your computer

Privacy was the reason for the tool, so I wanted it to hold up in the details, not only in the headline:

  • The model is in the package. Face detection uses YuNet, an ONNX lightweight model from the OpenCV model zoo (MIT licence). It is stored in the repository with a pinned checksum. Nothing is downloaded at run time.
  • The server is local only. The web page talks to a server on 127.0.0.1.  The page loads no external scripts.
  • No temp files. The server keeps nothing. The browser sends the image with each request, and the server answers from memory.
  • No metadata. Photos often carry EXIF data: the camera, the date and sometimes the GPS position. The output is written without it.

One pipeline, three ways in

The command line, the web page and a small API all call the same detect-and-blur code. That sounds obvious, but a code review still found a gap: the extra margin around each face was applied in the command line but not for faces chosen in the web page. The fix was to make each region remember where it came from, the detector or the user. Now all three give the same result for the same photo.

The tool has 72 tests. The test photo is the public-domain Apollo 11 portrait of Neil Armstrong from NASA, plus a rotated copy to check that sideways phone photos come out the right way up.

What I learned

  • Choose a model for its install, not only for its accuracy. YuNet runs in plain OpenCV. The heavier alternative would have made the tool harder to install than the problem it solves.
  • Writing a new file is a free privacy step. Saving the output again removes the metadata, but only after you apply the photo’s orientation, or the faces end up in the wrong place.
  • A server with no state has nothing to leak. When the browser keeps the image, there are no files to clean up and nothing left behind.
  • “Blurred” is not a yes or no. The method and the strength decide how much is really hidden.

More information

How to install it, all the options and the limits are on the project page: Face Blur

Code: github.com/neiro-data/useful-tools/tool-face-blur

Other tools in the collection: Useful Tools, for example the Webpage Time Limiter.

Picture of Nelson Eiró

Nelson Eiró

Senior Data Engineer

LinkedIn

Add comment: