我正在研究numpt矩阵,我可以创建一个HSV图像,然后在RGB图像中转换。我创建了一个矩阵HSV,包括:
matrix_=np.zeros([3, H-kernel+1, W-kernel+1], dtype=np.float32)
在我用255,θ角的大小填充它之后,每个值:
matrix_[:, row, column]=np.array([th, 255, mag])
最后,我将其转换为:
cv2.cvtColor(matrix_, matrix_, cv2.COLOR_HSV2RGB)
但是它在cv2.cvtColor中抛出“TypeError: only size-1 arrays can be converted to Python scalars
”。为什么?我哪里错了
您正在混合参数的顺序
见cvtColor的文件:
如您所见,目标矩阵是第三个参数。
code
是第二个参数。code
应该是标量,但是您正在将matrix_
作为第二个参数传递,因此您得到了错误:"TypeError: only size-1 arrays can be converted to Python scalars"
为避免错误,您可以使用:
最好使用返回值(语法更清晰):
现在还有另一个例外:
"Invalid number of channels in input image"
您将矩阵形状设置错误:
它应该是:
语法
matrix_[:, row, column]=np.array([th, 255, mag])
看起来很奇怪。您没有发布
row
、column
、th
和mag
的值。我不能说它是否正确。
我必须假设这超出了你的问题范围
相关问题 更多 >
编程相关推荐