我创建红色图像并尝试通过 cv2.imwrite 保存它
import numpy as np
import cv2
RED = [0, 0, 255]
IMAGE_SIZE = 100
image = np.empty([IMAGE_SIZE, IMAGE_SIZE], dtype=type(RED))
for i in range(IMAGE_SIZE):
for j in range(IMAGE_SIZE):
image[i, j] = RED
cv2.imwrite("red.png", image)
但是我得到错误
File "C:/Users/Andrew/Desktop/Programms/image-processing-cource/Tracks.py", line 11, in save_image
cv2.imwrite(name, image)
TypeError: img data type = 17 is not supported
如何解决?
谢谢!
最佳答案
dtype = type(RED)
为您提供类型 list
而不是类型 int
。
你需要:
image = np.empty([IMAGE_SIZE, IMAGE_SIZE, 3], dtype=type(RED[0]))
关于python-2.7 - 类型错误 : img data type = 17 is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27051084/