openCV:为 IplImage 添加透明度
我有一个 3 通道 IplImage。我想创建一个 4 通道图像并将其 Alpha 通道设置为小于 1.0 的值以使其半透明。
首先,我将 Alpha 通道(第 4 个通道)设置为 0.5:
cvSet(Image_c4, cvScalar(0,0,0,0.5);
这是我用来将 3 通道图像复制到 4 通道图像的命令。
cvCvtColor(Image_c3, Image_c4, CV_RGB2RGBA);
问题:Image_c3 是彩色的。 Image_c4 成为 Image_c3 的灰度副本(并且没有透明度)。
更新: 事实证明,上面的代码实际上是正确的并且有效,并且实际上比下面答案中建议的解决方案更简洁。我在其他地方遇到了一个不相关的错误。
I have a 3-channel IplImage. I would like to create a 4-channel image and set the alpha channel for it to a value less than 1.0 to make it semi-transparent.
First I set the alpha channel (the 4-th channel) to 0.5:
cvSet(Image_c4, cvScalar(0,0,0,0.5);
Here is the command that I used to copy the 3-channel image into a 4-channel image.
cvCvtColor(Image_c3, Image_c4, CV_RGB2RGBA);
The problem: Image_c3 is in color. Image_c4 becomes a gray scale copy of Image_c3 (and with no transparency).
Update:
It turned out that the code above is actually correct and works and is actually more concise than the suggested solutions in the answers below. I had an unrelated bug somewhere else.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许还有另一种方法,但我添加了这样的透明度:
Maybe there is another way but I add transparency like this: