Lle*_*ims 5 python opencv python-3.x
我想创建一个小的 scrypt 来创建没有背景的 png 图像。我已经阅读了一些信息,但不确定这是否可以与opencv. (抱歉,如果这是一个愚蠢的问题,但我是这个库的新手)。
创建图像很容易,
import cv2
import numpy as np
# Create a black image
img = np.zeros((512,512,3), np.uint8)
# Drawing a circle
circle = cv2.circle(img,(256,256), 63, (0,0,255), -1)
#
cv2.imwrite('circle.png',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
但是,没有背景可以保存吗?在这个例子中,可以只保存圆吗?
非常感谢!!!
我在下面的代码中向图像添加了透明通道(或图层)。会给人一种背景什么都没有的感觉。
import cv2
import numpy as np
# Create a black image
img = np.zeros((512,512, 4), np.uint8)
# Drawing a circle
circle = cv2.circle(img, (256,256), 63, (0,0,255, 255), -1)
#
cv2.imwrite('circle.png',img)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2167 次 |
| 最近记录: |