PNG image with alpha channel
I'm new to OpenCV and I've done a small POC for reading an image from some URL.
I'm reading the image from an URL using video capture.
The code is as follows:
VideoCapture vc;
vc.open("http://files.kurento.org/img/mario-wings.png");
if(vc.isOpened() && vc.grab())
{
cv::Mat logo;
vc.retrieve(logo);
cv::namedWindow("t");
imwrite( "mario-wings-opened.png", logo);
cv::imshow("t", logo);
cv::waitKey(0);
vc.release();
}
This image is not opened correctly, possibly due to alpha channel.
What is the way to preserve alpha channel and get the image correctly?
Any help is appreciated.
-Thanks
Actual image and expected output:
Opened image:
yes, the VideoCapture discards alpha, which is of absolutely no relevance in computer-vision
What could be a possible solution though? I had tried this using lib-curl too, and had the same output. This image is supposed to be overlay-ed on top of another image, hence I need it to have a transparent background.
Is there no option of maintaining alpha values at all?
"This image is supposed to be overlay-ed on top of another image" -- opencv != photoshop. wrong tool for your job
(btw, the curl solution imports it correctly, but you won't see the effect from alpha using imshow())
I meant the following:
I'll use a server through which I'll be streaming video. I'll be doing video processing frame by frame. The goal is to add some image logo to this video stream.
The above mentioned code works for other images perfectly, just specific png files turn out looking like this.
Thanks though :)
video in general does not have alpha, so you'll have to find another way of blending
I tried to integrate curl with my server and it raised a lot of dependency issues which was why I had to shift to video capture.
If curl is doing it correctly, I'll look into integrating it. Thanks!
If it's just one image, use imread with the flag IMREAD_UNCHANGED to read in the alpha channel.
@Tetragramm, imread() fails since I have to pass an URL.