2024-09-01
OpenCV
00

在这里插入图片描述

1 调程序中的127可以提取多少颜色,有时候有毛边;

2 png是带透明度的图,有颜色的部分设置透明度255就是完全不透明,原来白色的部分设置透明度0就是完全透明;

python
import cv2 import numpy as np inputimg = 'minio.png' thresh=180 img1 = cv2.imread(inputimg, 0) ret, thresh1 = cv2.threshold(img1, 127, 255, cv2.THRESH_BINARY) img = cv2.imread(inputimg) b, g, r = cv2.split(img) b[thresh1 > thresh] = 0 g[thresh1 > thresh] = 0 r[thresh1 > thresh] = 0 alpha_channel = np.zeros(b.shape, dtype=b.dtype) alpha_channel[thresh1 < thresh] = 255 img = cv2.merge([b, g, r, alpha_channel]) cv2.imwrite("res.png", img)
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!