On Tue, Nov 26, 2013 at 9:37 PM, Peter Rennert <p.rennert@cs.ucl.ac.uk> wrote:
I probably did something wrong, but it does not work how I tried it. I am not sure if you meant it like this, but I tried to subclass from ndarray first, but then I do not have access to __array_interface__. Is this what you had in mind?
from PySide import QtGui import numpy as np
class myArray(): def __init__(self, shape, bits, strides):
You need to pass in the image as well and keep a reference to it.
self.__array_interface__ = \ {'data': bits, 'typestr': '<i32', 'descr': [('', '<f8')], 'shape': shape, 'strides': strides, 'version': 3}
Most of these are wrong. Something like the following should suffice: class QImageArray(object): def __init__(self, qimage): shape = (qimage.height(), qimage.width(), -1) # Generate an ndarray from the image bits and steal its # __array_interface__ information. arr = np.frombuffer(qimage.bits(), dtype=np.uint8).reshape(shape) self.__array_interface__ = arr.__array_interface__ # Keep the QImage alive. self.qimage = qimage -- Robert Kern