masked
is a cli tool made to automatically anonymize eyes in videos.
It uses detectron2 for keypoints detections, and some weird math to apply a mask.
This project was inspired by one of the poster from the movie Parasite, so the attempt was to only cover the eyes (just like in the poster). If you tweak the default values, you can cover whole faces, but it might be easier for you to use a tool made for that purpose, like deface.
Parasite poster | masked demo |
---|---|
Parasite.masked.demo.mp4 |
masked
is compatible with Windows, Linux and macOS.
If you have a nvidia CUDA-enabled GPU, you can (and you really should) install CUDA to benefit from hardware acceleration, making the inference faster (see Windows or Linux CUDA installation guide).
If you don't have CUDA installed, you can still use masked
, you just need to use the --cpu
option.
masked
uses poetry as a dependency manager, make sure it is installed before getting started
(see poetry installation instructions).
It also uses ffmpeg in order to keep the audio of the videos you mask
(see ffmpeg website to download a binary).
FFmpeg executable needs to be in your PATH
for masked
to use it.
You can also use the --no-audio
option to skip the audio copy.
You first need to get the source of masked
, and use poetry to create a virtualenv and install the dependencies:
git clone https://github.com/Aziks0/masked.git
cd masked
poetry install
You then need to install detectron2
(and pytorch
+ torchvision
if you build it from source)
Warning
Remember that you are using
poetry
! Install the following package in thepoetry
virtualenv withpoetry run <PIP_COMMAND>
.
detectron2
has pre-built wheels for Linux,
but you can also build it from source if you prefer.
You need to build detectron2
from source, please refer to the detectron2 installation guide.
You first need to install pytorch and torchvison. Please refer to the pytorch website for the installation guide.
Then, you need to install detectron2
. It doesn't support Windows -officially-, so you need a "custom" source to build and install it.
You can either use my fork version
or use your own fork and fix the source yourself (see this commit).
Exemple installation with CUDA 11.3
installed:
poetry run pip install torch torchvison --extra-index-url https://download.pytorch.org/whl/cu113
poetry run pip install git+https://github.com/Aziks0/detectron2-windows.git
Please refer to the detectron2 build guide for further information.
Use poetry run masked -i <VIDEO_PATH>
to run the tool.
Check the available options here or with the poetry run masked -h
command.
usage: masked [-h] --input INPUT [--output OUTPUT] [--threshold THRESHOLD] [--mask-scale WIDTH HEIGHT]
[--mask-color RED GREEN BLUE] [--remove-duplicates] [--faces FACES] [--no-audio] [--visualize]
Anonymize faces in videos
optional arguments:
-h, --help show this help message and exit
--input INPUT, -i INPUT
Path to video file.
--output OUTPUT, -o OUTPUT
Path to the output video file.
--threshold THRESHOLD, -t THRESHOLD
Minimum score for faces to be masked, [0,1].
--mask-scale WIDTH HEIGHT, -ms WIDTH HEIGHT
Scale factor for face masks, ]0,+∞].
--mask-color RED GREEN BLUE, -mc RED GREEN BLUE
Face masks color, in RGB.
--remove-duplicates, -rd
Try to remove duplicated detections.
--faces FACES, -f FACES
Specify the number of faces that will appear in the video. Only the X most probable detections
will be anonymized.
--no-audio Don't keep the audio from the input video.
--visualize Draw scores and boxes. This argument is only compatible with {input|output|threshold|no-audio}
arguments.
- poetry — licensed under MIT License
- detectron2 — licensed under Apache License 2.0
- ffmpeg-python — licensed under Apache License 2.0
- opencv-python — licensed under MIT License
- numpy — licensed under BSD 3-Clause License
- colorama — licensed under BSD 3-Clause License
- tqdm — licensed under multiple licenses
- Parasite — © Barunson Entertainment & Arts Corp and © CJ ENM.