在Python中使用NumPy创建一个白色图像 |
您所在的位置:网站首页 › cad怎么生成白底图片保存 › 在Python中使用NumPy创建一个白色图像 |
在Python中使用NumPy创建一个白色图像
让我们看看如何使用NumPy和cv2来创建一个白色的图像。一幅白色图像的所有像素都是255。 方法1:使用np.full()方法。 # importing the libraries import cv2 import numpy as np # creating an array using np.full # 255 is code for white color array_created = np.full((500, 500, 3), 255, dtype = np.uint8) # displaying the image cv2.imshow("image", array_created)输出: 方法2:通过使用np.zeroes()创建一个数组。 # importing the modules import numpy as np import cv2 # creating array using np.zeroes() array = np.zeros([500, 500, 3], dtype = np.uint8) # setting RGB color values as 255,255,255 array[:, :] = [255, 255, 255] # displaying the image cv2.imshow("image", array)输出: |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |