【发布时间】:2013-11-11 08:48:59
【问题描述】:
我目前正在从 PyQt 切换到 PySide。
使用 PyQt,我使用在 SO 上找到的代码将 QImage 转换为 Numpy.Array:
def convertQImageToMat(incomingImage):
''' Converts a QImage into an opencv MAT format '''
incomingImage = incomingImage.convertToFormat(4)
width = incomingImage.width()
height = incomingImage.height()
ptr = incomingImage.bits()
ptr.setsize(incomingImage.byteCount())
arr = np.array(ptr).reshape(height, width, 4) # Copies the data
return arr
但是 ptr.setsize(incomingImage.byteCount()) 不适用于 PySide,因为这是 PyQt 的 void* support 的一部分。
我的问题是:如何使用 PySide 将 QImage 转换为 Numpy.Array。
编辑:
Version Info
> Windows 7 (64Bit)
> Python 2.7
> PySide Version 1.2.1
> Qt Version 4.8.5
【问题讨论】:
-
PySide 似乎没有提供
bits方法。这也是 PyQt 的一部分吗?用constBits怎么样? -
m( 不敢相信我没有看到!非常感谢。如果您将您的评论作为答案重新发布,我会接受它。再次感谢!
-
完成了,但这足以回答这个问题吗?
-
是的,因为它是唯一缺少让它工作的东西。我编辑我的问题以在几秒钟内添加工作代码。
标签: python qt numpy pyqt pyside