PNG image with alpha channel

asked 2016-04-06 07:15:29 -0600

AVB gravatar image

updated 2020-10-24 03:20:31 -0600

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:
image description

Opened image:
image description

edit retag flag offensive close merge delete

Comments

yes, the VideoCapture discards alpha, which is of absolutely no relevance in computer-vision

berak gravatar imageberak ( 2016-04-06 07:28:01 -0600 )edit

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?

AVB gravatar imageAVB ( 2016-04-06 07:36:06 -0600 )edit

"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())

berak gravatar imageberak ( 2016-04-06 07:39:05 -0600 )edit

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 :)

AVB gravatar imageAVB ( 2016-04-06 07:49:37 -0600 )edit

video in general does not have alpha, so you'll have to find another way of blending

berak gravatar imageberak ( 2016-04-06 07:51:34 -0600 )edit

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!

AVB gravatar imageAVB ( 2016-04-06 07:54:21 -0600 )edit

If it's just one image, use imread with the flag IMREAD_UNCHANGED to read in the alpha channel.

Tetragramm gravatar imageTetragramm ( 2016-04-07 07:02:25 -0600 )edit

@Tetragramm, imread() fails since I have to pass an URL.

AVB gravatar imageAVB ( 2016-04-07 07:37:31 -0600 )edit