在用numpy 去创建一个矩阵(numpy.ndarray)并想用它生成图片时一定要记住,矩阵中每个元素的类型必须是dtype=np.uint8 也可以这样写dtype=“uint8”
例如
import numpy as np
import cv2
# 随便创建一个矩阵
a = np.array([1,1], dtype=np.uint8)
# 也可以这样写 a = np.array([1,1], dtype = "np.uint8")
cv2.imshow('a',a)
cv2.waitKey()
cv2.destroyAllWindows()
当已经创建了一个矩阵,想要转换数值类型时可以这样写
#例如已经创建了矩阵A(numpy.ndarray)
B = A.astype("uint8")
否则想要生成图片,或进行其他opencv处理时就会报错。
error: (-215:Assertion failed)
src_depth != CV_16F && src_depth != CV_32S
in function 'convertToShow'