Halloween Mask Using Image Processing

Introduction: Halloween Mask Using Image Processing

Image processing has its advantages in developing crazy applications. This project uses face recognition algorithm in creating a spooky Halloween effect without the use of any materials, just simple image processing concepts and techniques.

Here I've used OpenCV and python as the programming language.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Image Acquisition

The first and foremost step is image acquisition. Using the cv2.VideoCapture() function, we first capture each frame from the webcam. These are the frames where the processing takes place.

After capturing frames from the webcam, we select a spooky background image. I've chosen the V for Vendetta background logo. Now we need to blend it with the frame captured by the web cam.

This involves a concept of 'added weight', where the 2 images are added in a certain ratio such that the sum of their ratios is 1. I've added both the images in a 1:1 ratio (0.5*img1 + 0.5*img2)

Step 2: Face Recognition

After this, we now use face recognition algorithm so as to blend the desired mask on the face along with that background in step 2.

There are 2 ways in which this can be done

1. Using 'Haar-cascade frontal face default' file as provided in the OpenCV package. The following link is useful for face recognition using OpenCV.


2. Create your own training data set of your face so as to make the algorithm even more efficient.

I had used Haar cascade for face recognition and this algorithm returns 4 values which are, the starting x & y coordinate of your face (in pixel) and the width and height of your face (in pixels). Just for confirmation, I've drawn a rectangle so that I understand that my face is being detected and this process is real-time. It means that the rectangle moves along with your face, visible on the screen.

Step 3: Selection of Mask and Adding It on the Face

The next step is to choose a creepy mask. I had chosen V for Vendetta mask which I wanted to blend it on my face.

1. Since, the masks that you choose can be of different sizes, It is important to resize it with the size of your detected face. So step 1 involves resizing the mask to the size of your detected face.

2. After resizing, you need to replace your face by the mask

3. But replacing the mask isnt exactly the desired result, but we need to blend the mask on the face. So we use a technique of padding.

The reason behind using padding is that, we create a separate image, of the same size as that of the frame captured by web cam and blend the padded image to the spooky background image. Since the position of the face is known, we just need to add zeros' to the mask and resize it to the same size as that of captured image from camera.

The padded image is attached.

Step 4: Blending the Mask on the Face

This is the final step of the project

Where the padded image needs to be added with the spooky background image in step 2. The addition uses the concept of added weights again so it is up to the user the ratio in which he wants to add both the images.

The user has the opportunity to choose which ever mask or background he wants.

I've done with a couple of different masks and couple of different backgrounds as uploaded.

Step 5: Conclusion

People who are unable to make stuffs for Halloween but are keen to celebrate, could use this computer vision technique and celebrate it in a unique style! All you need is OpenCV and python thats it.

It is also extremely cost effective - 0$ required to make this and could be exploited further based on your creativity and imagination.

It would indeed be grateful if the readers could suggest their esteemed feedback so that improvements could be done.


Step 6: Source Code

Halloween Decor Contest 2016

Participated in the
Halloween Decor Contest 2016

Be the First to Share


    • Heart Contest

      Heart Contest
    • Fiber Arts Contest

      Fiber Arts Contest
    • Paper Contest

      Paper Contest