Create snapchat filter

how to apprach this problem?

Hey @prajjwalrkstr, first of all when you load the nose haarcascade file and than run it to identify the nose, you can x,y,w,h. Now to place the moustache there, keep this things in mind.

Load the moustache image using,
img = plt.imread(’./Train/mustache.png’)
print(img.shape)
You will notice that img has 4 channels and not 3. These channels are rgba. Where ‘a’ channel stores the opacity of channel. It will be greater than 0 if there is some opacity otherwise zero.

Next step is to resize this moustache, to the one having same width and height to that of nose detected.

Than you need to iterate on every pixels value on img from x to x+w and from y+h-heightofmoustache to y+h. And replace the pixel values to that of moustache image if ‘a’ channel value i.e. opacity value is greater than 0.

Similarly do this for eyes.

Hope this cleared your doubt. :blush:

1 Like