Learn everything about Analytics

Home » ‘Person Blocker’ is a Python Script that Blocks Out Entire People in Images

‘Person Blocker’ is a Python Script that Blocks Out Entire People in Images


  • Using ‘Person Blocker’ you can block out people and up to 80 other objects in images
  • The algorithm behind it uses Mask R-CNN that is pre-trained on the MS COCO dataset
  • The output gives us 2 images – one static and one animated



We’ve all seen those edited videos paraded around in the news and movies where a person’s face is blacked out due to various reasons. You can now do the same on your machine by typing just a few lines of code!

A group of developers have created a python library called ‘Person Blocker’ that automatically blocks out entire people in images using a pre-trained neural network. The algorithm uses Mask R-CNN that is pre-trained on the MS COCO dataset. And the cherry on top? No GPU required!

And not just people, the algorithm is able to block out entire objects as well. The algorithm recognizes 80 different types of objects, including vehicles, animals, electronic gadgets, among other things. You can find the entire list in the ‘class.py’ file on GitHub (link given at the end of this section).

There are two steps associated with blocking objects in the image:

  • Running in inference mode to get the object IDs for each object
  • Blocking those object IDs

You can run Person Blocker from the command line itself:

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

The output of this is two-fold – a static image and an animated image.

There are a few dependencies attached to this library and we have listed them below:

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

You can view the GitHub repository for ‘Person Blocker’ here.


Our take on this

We tried out this library in python and we pretty impressed with the results. This will be a good go-to library for anyone getting into the image processing field. You can see below how the algorithm runs and the labels that are used to recognise objects in the image:

You can choose to block out anything in that image that has been labelled. Pretty impressive, isn’t it? Let us know in the comments below how it worked out for you.


Subscribe to AVBytes here to get regular data science, machine learning and AI updates in your inbox!


You can also read this article on our Mobile APP Get it on Google Play
This article is quite old and you might not get a prompt response from the author. We request you to post this comment on Analytics Vidhya's Discussion portal to get your queries resolved