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

Pranav Dar 02 Apr, 2018 • 2 min read

Overview

  • 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

 

Introduction

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!

 

Pranav Dar 02 Apr 2018

Senior Editor at Analytics Vidhya. Data visualization practitioner who loves reading and delving deeper into the data science and machine learning arts. Always looking for new ways to improve processes using ML and AI.

Frequently Asked Questions

Lorem ipsum dolor sit amet, consectetur adipiscing elit,

Responses From Readers

Clear

Santosh
Santosh 02 Apr, 2018

Hey Dude, Thanks for sharing such a nice thing, but i wonder is it the same technology used to mask sensor things in a video.

Pablo
Pablo 13 Apr, 2018

Only I remember Black Mirror after read that article?