Copy from Transparent Mat

I have an image that is the background.
I have the foreground that is an object with background is transparent on a BGRA mat.
How to merge the 2 images ? without to display the transparent pixels?
Thank you

Hi @Christophe_Jacquelin

This is a quick reply, sorry I’m not posting code.

You can scan the image pixel by pixel, and generate an output image with the desired result: copy the pixel from foreground unless it is transparent, in which case copy from background.

You can also produce a mask from foreground alpha channel, and use the mask to blend the images, all with Mat arithmetics.

Remember, OpenCV is not an image processing library, but a computer vision one. It’s more about extracting meaning from images.

Thanks now its working.

1 Like