OpenCV 2.4 Jpeg to PNG with alpha channel

2020-07-10 06:34发布

I have a JPEG and a Mask. I want to create a PNG with the three JPEG channels and the alpha channel should be the Mask. How can I achieve this with OpenCV?

Regards

标签: c++ opencv
2条回答
\"骚年 ilove
2楼-- · 2020-07-10 06:54

Thanks for your answer, I found a second solution:

cv::Mat transparent( height, width, CV_8UC4);
cv::Mat srcImg[] = {JPEG_img, alpha_Mask};
int from_to[] = { 0,0, 1,1, 2,2, 3,3 };
cv::mixChannels( srcImg, 2, &transparent, 1, from_to, 4 );

This works perfect, not sure which solution is better.

查看更多
等我变得足够好
3楼-- · 2020-07-10 07:07
std::vector<cv::Mat> channels;
cv::split(jpgImage, channels);
channels.push_back(mask);
cv::Mat bgraImage;
cv::merge(channels, bgrAImage);

Documentation for split and merge functions

查看更多
登录 后发表回答