在OpenCV中创建透明图像 [英] Creating transparent image in OpenCV

查看:1432
本文介绍了在OpenCV中创建透明图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在OpenCV中创建透明图像,并以jpg格式将其波动,但是没有成功.

I am trying to create a transparent image in OpenCV and wave it as jpg without any success.

我的代码是这样的:

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.

我该怎么做?

如果OpenCV无法做到这一点,那么我有没有免费的库?

If OpenCV can not do this, is there any free library that I use for this?

推荐答案

似乎JPEG 不支持透明度 .不过,PNG确实可以,因此您将需要更改输出文件格式.

It appears that JPEG doesn't support transparency. PNG does, though, so you will want to change your output file format.

此外,alpha值255表示完全可见.将Alpha值更改为零,以使图像完全透明:

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

这篇关于在OpenCV中创建透明图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆