python - opencv python : mat data type = 17 is not supported

标签 python opencv

我只是想在 python 中使用 opencv 将图像从 BGR 转换为 RGB。 但是这样做时我收到此错误消息:

line 62, in getRep\n    rgbImg = cv2.cvtColor(imgFrame, 

cv2.COLOR_BGR2RGB)\nTypeError: src data type = 17 is not supported\n

我看到图像作为参数传递,它如我所料在 BGR 中,但它不起作用:

def getRep(self, imgFrame, multiple=False):
    bgrImg = imgFrame.copy()
    cv2.imshow('debug', imgFrame)   #this line does show a BGR image
    cv2.waitKey(0)
    rgbImg = cv2.cvtColor(imgFrame, cv2.COLOR_BGR2RGB)


def recognize(self, imgFramePath):
    imgFrame= cv2.imread(imgFramePath)
    imgFrame = np.array(imgFrame)
    reps = self.getRep(imgFrame, False)

这些是正在解释的所有行,也是唯一与我面临的问题相关的行。有人知道我做错了什么吗?

谢谢

最佳答案

您的图像是 CV_8S 图像(8 位有符号整数)。 This site显示从数字数据类型到实际类型的转换,类型 17 对应于 8 位有符号 int。这是问题,因为 cvtColor() 不接受 8 位带符号的 int 图像作为输入。来自 cvtColor() 上的文档:

src – input image: 8-bit unsigned, 16-bit unsigned (CV_16UC...), or single-precision floating-point.

所以你的输入图像需要是类型 CV_8U (numpy.uint8) 或 CV_16U (numpy.uint16) 或 CV_32F (numpy.float32),并为您正在使用的颜色转换设置适当数量的 channel 。

关于python - opencv python : mat data type = 17 is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45656057/

相关文章:

azure - 从 dockerfile 构建 Azure 机器学习环境(tensorflow)失败

python - Pandas 使用数组分配列值

opencv - 寻找裁剪和缩放的相似图像

opencv - 如何在Windows中使用PGI运行OpenACC + OpenCV?

python - 使用 OpenCV 连续执行线分割(裁剪)

python - 在 python 中的嵌套 for 循环中使用索引的推荐样式

python - 尝试使用 MySQLdb 获取一个单元格的值

python - __ne__ 应该作为 __eq__ 的否定来实现吗?

python : check if the nested dictionary exist

c++ - 将 RANSAC 应用于 vector<Point2f> 以进行相似性变换