Unable to read image correctly

In the got snapchat filter challenge, when trying to read the mustache.png image using cv2, the image on cv2.imshow() or even on plt.imshow() is all black image instead of the black part only at mustache and background as white.

Same with glasses.png image.

How to resolve this issue ?

Hi @keshari
Transparent PNG images have 4 channels; 3 for Red, Green and Blue (RGB) and one for Alpha. It turns out, when Opencv reads the transparent PNG images, it discards the ‘alpha’ channel or the information about transparency. It just renders the images as it is present in the RGB channels. So while working with the mustache.png or glasses.png file you need to take in consideraion the 4th (alpha) channel of the image
Here is the code that might help you, (For adding glasses to the image)

Hope this might helps :slight_smile:

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.