Skip to main content

A CLI tool that can remove faces from videos and replace them with images.

Project description

Table of Contents

  1. Building instructions
    1. installing the CLI tool itself
    2. pyproject and MANIFEST
    3. structurey
    4. installing it as a library
    5. Usage

Building instructions

installing the CLI tool itself

pipx install faceblocker

And then, you'll be able to do things like this!

img

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/.

structurey

pwd
tree -L 2 ./ -I "envs|build"

installing it as a library

If you want to download and run it from source, do

pip install faceblocker

and then run faceblocker using

python3 -m faceblocker 

If things are working right with the script and the virtual environment you (Hopefully!) installed this into, faceblocker should be in your $PATH and should allow for being called with just

and then run faceblocker using

faceblocker 

Usage

faceblocker -h

so as an example,

faceblocker -i inputvideo.mp4

should take inputvideo.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.

parameter default  
–scale 0.4 For 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.
–score 0.3 The cutoff confidence score of any bounding boxes. Any boxes that is less likely than this to be a face are discarded
–nmsthreshold 0.1 The "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.
–nkboundboxes 1000 The number of bounding boxes generated per frame
–samplerate 5 This 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.
–blockfactor 1.5 Where a face is detected, how much should the height and width of the bounding box of the covering image be scaled?
–unstretch False Due 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.mp4

will create a video like the gif above.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

faceblocker-0.0.4.tar.gz (4.2 MB view details)

Uploaded Source

Built Distribution

faceblocker-0.0.4-py3-none-any.whl (211.1 kB view details)

Uploaded Python 3

File details

Details for the file faceblocker-0.0.4.tar.gz.

File metadata

  • Download URL: faceblocker-0.0.4.tar.gz
  • Upload date:
  • Size: 4.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for faceblocker-0.0.4.tar.gz
Algorithm Hash digest
SHA256 948321723a75146e1ce42398234fc9f11d7522973db3a5b8511445654c61370b
MD5 381e95b1781afc61eaabef7d9579a394
BLAKE2b-256 11f0edd9f46fded6f489b7f82cf6c48270e72188bff061683c0f0e8975d7dc01

See more details on using hashes here.

File details

Details for the file faceblocker-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: faceblocker-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 211.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for faceblocker-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ed6651d3fabc3b5b55c2e0e487e099a87cbd50f0bdf3f2177edcc2637e700247
MD5 f36809fae2703d31a06106af9876d66c
BLAKE2b-256 73a27ffe7ef88d967e7f3c64ec16bf639b727b2bf2dce35183b129613f85f16e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page