It's easier to just use the buffer object returned from QImage.bits()
and np.frombuffer()
.
def qimage2array(q_image):
width = q_image.width()
height = q_image.height()
arr = np.frombuffer(q_image.bits(), dtype=np.uint8).reshape([height, width, -1])
return arr