Reputation: 18148
I am trying to create a transparent image in OpenCV and wave it as jpg without any success.
My code is something such as 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 colour is white.
How can I do this?
If OpenCV can not do this, is there any free library that I use for this?
Upvotes: 2
Views: 11807
Reputation: 408
It is not possible to make a .jpg image transparent, it is not supported by the format, try .png instead.
Upvotes: 3
Reputation: 11329
It appears that JPEG doesn't support transparency. PNG does, though, so you will want to change your output file format.
Also, an alpha value of 255 indicates full visibility. Change your alpha value to zero to make the image fully transparent:
outputImage=cv::Scalar(255,255,255,0);
Upvotes: 6