使用PySide将QImage转换为Numpy数组 [英] QImage to Numpy Array using PySide
本文介绍了使用PySide将QImage转换为Numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在从PyQt切换到PySide.
I am currently switching from PyQt to PySide.
With PyQt I converted QImage
to a Numpy.Array
using this code that I found on SO:
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,因为这是
However ptr.setsize(incomingImage.byteCount())
does not work with PySide as this is part of the void*
support of PyQt.
我的问题是:如何使用PySide将QImage转换为Numpy.Array
.
My Question is: How can I convert a QImage to a Numpy.Array
using PySide.
Version Info
> Windows 7 (64Bit)
> Python 2.7
> PySide Version 1.2.1
> Qt Version 4.8.5
推荐答案
PySide似乎没有提供bits
方法.如何使用 constBits 获取指向数组的指针?
PySide doesn't seem to offer a bits
method. How about using constBits to get the pointer to the array?
这篇关于使用PySide将QImage转换为Numpy数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文