简体   繁体   中英

Opencv - Overlay image without cvAddWeighted

there are plenty of tutorials showing how to blend two images in opencv:

But all of them are based on this equation:

opencv blending http://opencv.itseez.com/_images/math/afeb868ed1632ace1fe886b5bfbb6fd933b742b8.png

which means that I will be combining two images by averaging them and consequently I'll be loosing intensity on both images.

For instance, let alpha = 0.5, f0(x) = 255, and f1(x) = 0 . After applying this equation, the result image g(x) = 127 . That is not what I need. The first image should remain unchanged. And the transparency must be applied in the second one.

My problem is:

the first image f0(x) should not be changed and an alpha should be applied to the second image f1(x) when it overlays the first image f0(x).

I cannot figure out how to do this. Any help?

Unfortunately, alpha channels are not supported by OpenCV. From the imread documentation:
Note that in the current implementation the alpha channel, if any, is stripped from the output image. For example, a 4-channel RGBA image is loaded as RGB if flags > 0 .

See this SO post for a possible work around using imagemagick.

Hope that is helpful!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM