234234234

opencv 修改像素为透明色

import os

import cv2


img = cv2.imread("./test.bmp")

# 转成透明度图片
img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)

width, height, channel = img.shape

for i in range(width):
for j in range(height):
b,g,r,a = img[i][j]
# 把白色像素改成透明色
if r == 255 and g == 255 and b == 255:
# print(r,g,b)
img[i][j] = [0,0,0,0]

img = cv2.resize(img, (256, 256))

cv2.imwrite("test.png", img)
cv2.waitKey(100000)
posted @ 2021-06-16 09:39  ukeepgoing  阅读(2120)  评论(0)    收藏  举报
23423423423