GitHub - minimaxir/person-blocker: Automatically "block" people in ima...

 4 years ago
source link: https://github.com/minimaxir/person-blocker
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.


Person Blocker


A script to automatically "block" people in images (like the Black Mirror episode White Christmas) using Mask R-CNN pretrained on the MS COCO dataset. No GPU required!

But you can block more than just people: up to 80 different types of objects can be blocked, including giraffes and busses!


Person Blocker is used from the command line:

python3 person_blocker.py -i images/img3.jpg -c '(128, 128, 128)' -o 'bus' 'truck'
  • -i/--image: specifies the image file.
  • -m/--model: path to the pretrained COCO model weights (default: current directory): if not specified, it will download them automatically to the current directory if not already present (note: the weights are 258 MB!)
  • -c/--color: color of the mask, in either quote-wrapped hexidecimal or 3-element RGB tuple format. (default: white)
  • -o/--object: list of types of objects to block (or object IDs of specific objects). You can see the allowable choices of objects to block in classes.py or by using the -names flag. (default: person)
  • -l/--labeled: saves a labeled image annotated with detected objects and their object ID.
  • -n/--names: prints the class options for objects, then exits.

The script outputs two images: a static (pun intended) image person_blocked.png and an animated image person_blocked.gif like the one at the beginning of this README.


python3 person_blocker.py -i images/img1.jpg


python3 person_blocker.py -i images/img2.jpg -c '#c0392b' -o 'giraffe'


python3 person_blocker.py -i images/img3.jpg -c '(128, 128, 128)' -o 'bus' 'truck'


Blocking specific object(s) requires 2 steps: running in inference mode to get the object IDs for each object, and then blocking those object IDs.

python3 person_blocker.py -i images/img4.jpg -l

img4 labels

python3 person_blocker.py -i images/img4.jpg -o 1



The same requirements as Mask R-CNN:

  • Python 3.4+
  • TensorFlow 1.3+
  • Keras 2.0.8+
  • Numpy, skimage, scipy, Pillow, cython, h5py

plus matplotlib and imageio


Max Woolf (@minimaxir)

Max's open-source projects are supported by his Patreon. If you found this project helpful, any monetary contributions to the Patreon are appreciated and will be put to good creative use.



Code used from Mask R-CNN by Matterport, Inc. (MIT-Licensed), with minor alterations and copyright notices retained.

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK