import numpy as np
import cv2

img_arr = np.zeros([200,300,3])  #创建一个黑色像,大小为200x300
# img_arr = np.ones([400,300,3])  #创建一个白色图像
# img_arr = np.arange(400*300*3) .reshape([400,300,3])/(400*300*3)  #渐变色,从最黑到最白
# img_arr = np.random.rand(400,400,3)  #生成噪声数据
# img_arr = np.random.randn(400,400,3)  #生成噪声数据
#
# img_arr = np.random.normal(0,1,(400,400,3))

cv2.imshow("",img_arr)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
import numpy as np

img_arr = np.empty([400,400,3])  # 此处为生成全为0的数组,np.empty()函数,依给定的shape, 和数据类型 dtype,  返回一个一维或者多维数组,数组的元素不为空,为随机产生的数据。
print(img_arr)
# [0,0,255]
img_arr[...,2]=0
img_arr[...,2]=0
img_arr[...,2]=255
cv2.imshow("",img_arr)
cv2.waitKey(0)
cv2.destroyAllWindows()

 

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐