Read RGBA Image OpenCV

2019-07-30 16:16发布

问题:

I am stuck with reading, processing and displaying sample.png image which contains RGB and an additional Alpha layer. I have manually removed background in this image and only foreground appears in windows image slideshow propgram. I couldnt find any useful information anywhr... when i read it from opencv usng functions imread or cvloadimage it creates a white background by itself... i have read documentation of highgui which states that these functions only deal wth RGB not RGBA...any help or idea will be helpful...

Thanks Saleh...

回答1:

AFAIK only current solution is to load alpha channel as separate image and then join it together. You can use cvtColor() to add alpha channel to Mat with image and e.g. mixChannels() to mix it together with loaded aplha image.



回答2:

You can use cv::imread() with IMREAD_UNCHANGED option, to read the data to a cv::Mat structure. If you still need an IplImage to work with, it is possible to convert from cv::Mat to IplImage without losing the alpha channel.