Create a transparent image in OpenCV

I am trying to create a transparent image in OpenCV and without excitement massaging it as jpg.

My code is something like this:

string outputImageName="myimage.jpg";
Mat outputImage(outputRows,outputCols,CV_8UC4);
outputImage=cv::Scalar(255,255,255,255);
imwrite(outputImageName,outputImage);

But the image is not transparent, and its color is white.

How can i do this?

If OpenCV cannot do this, is there a free library that I use for this?

+1
source share
2 answers

JPEG doesn't seem to support transparency . PNG, however, so you will want to change the format of the output file.

In addition, an alpha value of 255 indicates full visibility. Change the alpha value to zero to make the image completely transparent:

outputImage=cv::Scalar(255,255,255,0);
+5
source

.jpg , , .png .

+3

Source: https://habr.com/ru/post/1683424/


All Articles