使用opencv在python中将RGB图像转换为RGBA的最佳方法是什么?
假设我有一个有形状的数组
(185, 198, 3) - it is RGB
Run Code Online (Sandbox Code Playgroud)
另一种是带有形状的alpha蒙版 (185, 198)
如何合并它们并保存到文件?
在下面给出的程序中,我将 alpha 通道添加到 3 通道图像以控制其不透明度。但是无论我给的 alpha 通道的值是多少,对图像都没有影响!任何人都可以解释我为什么?
import numpy as np
import cv2
image = cv2.imread('image.jpg')
print image
b_channel,g_channel,r_channel = cv2.split(image)
a_channel = np.ones(b_channel.shape, dtype=b_channel.dtype)*10
image = cv2.merge((b_channel,g_channel,r_channel,a_channel))
print image
cv2.imshow('img',image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
我可以在终端中看到添加了 alpha 通道并且它的值随着我在程序中的更改而变化,但对图像本身的不透明度没有影响!
我是 OpenCV 的新手,所以我可能会遗漏一些简单的东西。感谢帮助!