Problem in snapchat filters

code-https://ide.codingblocks.com/s/308142
sir please explain this portion of code in above code

overlay=cv2.imread(“train/glasses.png”,cv2.IMREAD_UNCHANGED)
overlay=cv2.cvtColor(overlay,cv2.COLOR_BGRA2RGBA)

overlay=cv2.resize(overlay,(w,h))
print(overlay.shape)

for i in range(overlay.shape[0]):
for j in range(overlay.shape[1]):
if(overlay[i,j,3]>0):
fullimg[y+i,x+j,:]=overlay[i,j,:-1]

Hi @pandeyaman461

Request you to share the code through the Coding Blocks IDE or Google Drive.

The indentation is all messed up here and it is very difficult to debug in this form.

Hey @pandeyaman461

Let me explain the requested code section.
Firstly, we’ll resize the overlay to the size of the desired section of the face (the eyes or below the nose)
overlay=cv2.resize(overlay,(w,h))

Now, we need to superimpose this resized overlay onto our original image. The overlay image has a 4th dimension which determines the transparency of a particular pixel. What we will do is that we’ll iterate over all overlay pixels. For pixels with 100% transparency, we’ll select the original image pixel value, and for pixels which are not transparent, we’ll select the overlay pixel value.

if(overlay[i,j,3]>0):
    fullimg[y+i,x+j,:]=overlay[i,j,:-1]

Hope this helps!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.