How to overlay an PNG image with alpha channel to another PNG?
I have two PNG images (overlay.png and underlay.png) both with alpha channel. I tried the addWeight and copyTo API to mask overlay.png to underlay.png, but the result image is not what I want.
overlay.png
underlay.png
result png i wish
This is my test code:
void blend_two_images() {
cv::Mat underlay = cv::imread("/home/underlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat overlay = cv::imread("/home/overlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat roi = underlay(cv::Rect(0, 0, overlay.cols, overlay.rows));
cv::addWeighted(roi, 0, overlay, 1, 0, roi);
cv::imwrite("/home/result.png", underlay);
}
How can I get the result I wish? Thanks a lot!