Package: faceblocker
Table of ContentsBuilding instructionsinstalling the CLI tool itselfpyproject and MANIFESTstructureyinstalling it as a libraryUsageBuilding instructionsinstalling the CLI tool itselfpipx install faceblockerAnd then, you'll be able to do things like this!pyproject and MANIFEST[project]
name = "faceblocker"
version = "0.0.4"
authors = [
{name="Rita Collins", email="r.collins3730@gmail.com" },
]
description = "A CLI tool that can remove faces from videos and replace them with images."
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"moviepy<2.0",
"opencv-python>4.8.0",
]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]

[project.urls]
"Homepage" = "https://gitlab.com/rdotcollins/movie-anonymiser"
"Bug Tracker" = "https://gitlab.com/rdotcollins/movie-anonymiser/issues"

#[tool.setuptools.packages]
#find = {}  # Scan the project directory with the default parameters
[tool.setuptools]
include-package-data = true
# OR
[tool.setuptools.package-data]
"faceblocker.models" = ["*"]

  
[tool.setuptools.dynamic]
readme = {file = ["README.org"]}
[tool.setuptools.packages.find]
# All the following settings are optional:
namespaces = true
where = ["src"]  # ["."] by default
include = ["*"]  # ["*"] by default

[project.scripts] 
faceblocker = "faceblocker.deface:main"

[build-system]
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"

# Command Description
# include pat1 pat2 ... Add all files matching any of the listed patterns (Files must be given as paths relative to the root of the project)
# exclude pat1 pat2 ... Remove all files matching any of the listed patterns (Files must be given as paths relative to the root of the project)
# recursive-include dir-pattern pat1 pat2 ... Add all files under directories matching dir-pattern that match any of the listed patterns
recursive-include ./yunet_model/*
include test_lsoh_out.gif	  
# recursive-exclude dir-pattern pat1 pat2 ... Remove all files under directories matching dir-pattern that match any of the listed patterns
# global-include pat1 pat2 ... Add all files anywhere in the source tree matching any of the listed patterns
# global-exclude pat1 pat2 ... Remove all files anywhere in the source tree matching any of the listed patterns
# graft dir-pattern Add all files under directories matching dir-pattern
# prune dir-pattern Remove all files under directories matching dir-pattern
# The patterns here are glob-style patterns: * matches zero or more regular filename characters (on Unix, everything except forward slash; on Windows, everything except backslash and colon); ? matches a single regular filename character, and [chars] matches any one of the characters between the square brackets (which may contain character ranges, e.g., [a-z] or [a-fA-F0-9]). Setuptools also has undocumented support for ** matching zero or more characters including forward slash, backslash, and colon.
# Directory patterns are relative to the root of the project directory; e.g., graft example* will include a directory named examples in the project root but will not include docs/examples/.structureypwd
tree -L 2 ./ -I "envs|build"installing it as a libraryIf you want to download and run it from source, dopip install faceblockerand then run faceblocker usingpython3 -m faceblockerIf things are working right with the script and the virtual environment you (Hopefully!) installed this into,faceblockershould be in your$PATHand should allow for being called with justand then run faceblocker usingfaceblockerUsagefaceblocker -hso as an example,faceblocker -i inputvideo.mp4should takeinputvideo.mp4, render a black square over all faces detected using the default settings on the model.
The default settings are fairly liberal in considering things "faces" and will often block first, ask questions later.
The default parameters are set to the following.parameterdefault–scale0.4For speed reasons, face detection is done on a resized version of the frame in memory. 0.5 means faces are detected on a frame half the width and height of the initial frame.–score0.3The cutoff confidence score of any bounding boxes. Any boxes that is less likely than this to be a face are discarded–nmsthreshold0.1The "interval over union" score of any bounding boxes with respect to the training data. Any boxes with an IOU score less than this are discarded.–nkboundboxes1000The number of bounding boxes generated per frame–samplerate5This script will sample every k'th frame of the video to detect faces on it, use this to specify how often it will attempt to detect a face. Higher is more accurate.–blockfactor1.5Where a face is detected, how much should the height and width of the bounding box of the covering image be scaled?–unstretchFalseDue to an upstream bug in moviepy, some vertical videos are automatically rescaled horizontally and will look strangely wide. Set this flag to "True" to stop this from happening.faceblocker -i /home/river/Videos/test_lsoh.mp4 -p /home/river/Pictures/fox_1f98a.png --samplerate 2 --scale 0.3 --nms_threshhold -o test_lsoh_out.mp4will create a video like the gif above.