首先要了解opencv中读取图片的格式
图像储存格式
import cv2 as cv
import numpy as np
def creat_image():
# 3通道图像
img = np.zeros([400,400,3],np.uint8)
img[:,:,0]=np.ones([400,400])*255
cv.imshow("window0",img)
# 单通道图像
gray=np.ones([400,400],np.uint8)
gray=gray*125
cv.imshow("window1",gray)
array=np.ones([3,3],np.float32)
array.fill(13.2)
print(array)
array1=array.reshape([1,9])
print(array1)
creat_image()
cv.waitKey(0)
cv.destroyAllWindows()
[[13.2 13.2 13.2]
[13.2 13.2 13.2]
[13.2 13.2 13.2]]
[[13.2 13.2 13.2 13.2 13.2 13.2 13.2 13.2 13.2]]
不能将3×3reshape成1×10
不知道为什么,我将数据类型改为uint16,无法产生蓝色图像