python opencv生成背景透明图标_Tqdada的博客-CSDN博客
import numpy as np
import cv2
import math
img = np.zeros((230,230), dtype=np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
img[:,:,:] = 255
#画星号,可以根据需要绘制其他形状
#line1 0°
color = (0,0,0)
width = 55
cv2.line(img, (115, 30), (115, 115), color, width)
#line2 72°
x2 = 115+85*math.sin(0.4*math.pi)
y2 = 115-85*math.cos(0.4*math.pi)
cv2.line(img, (115,115),(int(x2),int(y2)),color,width)
#line3 -72°
x3 = 230-int(x2)
y3 = int(y2)
cv2.line(img, (115,115), (x3,y3), color, width)
#line4 144°
x4 = 115+100*math.sin(0.2*math.pi)
y4 = 115+100*math.cos(0.2*math.pi)
cv2.line(img, (115,115), (int(x4),int(y4)), color, width)
#line5 216°
x5 = 230-int(x4)
y5 = int(y4)
cv2.line(img, (115,115), (x5,y5), color, width)
#创建四通道图片
b,g,r = cv2.split(img)
a = np.ones(b.shape,dtype=b.dtype)*255
for i in range(230):
for j in range(230):
if(b[i][j] == 255 and g[i][j] == 255 and r[i][j] == 255):
a[i][j] = 0
img_al = cv2.merge((b,g,r,a))
#查看保存图片
cv2.imshow("img", img_al)
cv2.imwrite("img.png", img_al)
cv2.waitKey(0)
————————————————
版权声明:本文为CSDN博主「Tqdada」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Tqdada/article/details/105725007
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/jacke121/article/details/124464529
内容来源于网络,如有侵权,请联系作者删除!