Deface is a free and open-source command-line tool that allows you to automatically blur human faces in pictures or videos without relying on any external editing software or online service.
For videos, it first detects all human faces frame by frame and then applies your selected blur anonymization filter to each detected face region, but note that it will strip the audio by default.
This tool is specially built for defacing human faces, but out of curiosity, I tried feeding animals, anime characters, and groups of people, and you can see the result below.
As you can see, it performs well with human faces but not with animals and cartoons; during testing with various pictures, it occasionally functions if the face geometry resembles a human, but most of the time it won’t do anything.
However, it was just my curiosity to experiment with faces other than human and share those curious individuals like me, but in reality, no one is going to deface animal or cartoon characters, and for human faces, it works like a charm.
So, read this article to learn how to install this tool on your system and use it to deface your next solo or group photo without relying on any editing software or online services.
Tutorial Details
Description | Deface: Anonymize Human Faces |
Difficulty Level | Low |
Root or Sudo Privileges | No |
OS Compatibility | Linux, Windows, and macOS |
Prerequisites | Python and PIP |
Internet Required | Yes (for installation) |
How to Install Deface on Linux, Windows, and macOS
The “deface
” is available for all popular operating systems, such as Linux, Windows, and macOS, but it requires Python with PIP installed on those systems as a prerequisite.
So, if you already have them installed, then execute the following command to install it.
$ python3 -m pip install deface
Once the installation is finished, the “deface
” command will become accessible.
How to Deface Faces in Pictures and Videos Using Deface
To demonstrate the usage of the “deface
” command, we will deface faces for a group of people from the picture and video using different anonymization filters or replace them with custom pictures.
Deface Faces From a Picture
To deface human faces in a picture, you can use the “deface
” command by specifying the path or filename of the picture, the “--replacewith
” option with anonymization filter mode (e.g., “blur
“, “solid
“, “mosaic
“), and lastly, the “-o
” option specifying the output filename.
The following is an example of defacing a group of human faces with all the filter modes.
#Anonymize the faces in blur filter mode.
$ deface input.jpg --replacewith blur -o output.jpg
#Anonymize the faces in solid filter mode.
$ deface input.jpg --replacewith solid -o output.jpg
#Anonymize the faces in mosaic filter mode.
$ deface input.jpg --replacewith mosaic -o output.jpg
The following is an output of the defaced pictures:
Deface Faces With A Custom Picture
Despite the anonymization filter mode, you can deface faces with any custom image by using the filter mode “img
“, specifying the “--replaceimg
” option with a path or filename of the picture that will replace the faces.
For example, the following command will replace all the human faces in the “input.jpg
” picture with the “emoji.png
” picture.
$ deface input.jpg --replacewith img --replaceimg emoji.png -o output.jpg
Output:
Deface Faces From a Video
Defacing faces from a video can also be achieved using the same command by simply replacing the picture with your video file. Note that, by default, it will remove the audio from the video. To keep the audio file, you have to use the “--keep-audio
” or “-k
” option.
Here’s a command-line example of defacing a video file without audio, with audio, and replacing the faces with a custom image.
#Anonymize the faces from the input file with no audio output.
$ deface input.mp4 --replacewith blur -o output.mp4
#Anonymize the faces from the input file with audio output.
$ deface input.mp4 --replacewith blur --keep-audio -o output.mp4
#Anonymize the faces from the input file with a custom image.
$ deface input.mp4 --replacewith blur img --replaceimg emoji.png -o output.mp4
The following is an output of the defaced video created using the first command:
Final Word
I’ll conclude this article, but you can dig deeper and experiment with various options, such as scaling, drawing scores, thresholds, etc., by checking the help section using the “deface -h
” command.
Now, if you have any questions or queries related to the topic, do let me know in the comment section.
Till then, peace!
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.