[Numpy-discussion] Trying to implement the array interface
Wed Jan 14 07:37:55 CST 2009
2009/1/14 Mark Asbach <firstname.lastname@example.org>:
> Hi there,
> I'm currently extending the Python wrapper for the Open Computer Vision
> Library (opencv) with the goal to interface numerical libraries as seemless
> as possible. Unfortunately, it doesn't seem to be that easy ;-)
> What I've done so far:
> - Added an __array_interface__ property to the Python side of OpenCV data
> structures (matrices and images) that uses version 3 of the interface
> definition and supplies the keys 'version', 'shape', 'typestr', 'data' and
> in some cases 'strides' when we have non-continuos memory layout. I think,
> I'm compatible to http://numpy.scipy.org/array_interface.shtml .
Great! How did you do it? I've written something like this before, but
it was always very complex :|
> - Added parsing the __array_interface__ of Python objects passed to OpenCV
> methods. I'm a bit unsure of how to use the C/C++ side (array struct) and if
> I can expect it to be there (for example: I don't provide one with OpenCV).
> Since I intend to keep OpenCV independent of numpy, calling functions from
> numpy.h is not an option, as far as I can see.
Perhaps you can tell SWIG to extrat those informations from the numpy
array? A more complex numpy.i would probably be enough.
> - PIL (1.1.6): the array interface (Python side) doesn't adhere to the
> definition -> no 'version' key, 'data' is string, not a tuple holding the
> pointer. What to do with this?
Perhaps you can force it to pass numpy.asarray(image)?
Information System Engineer, Ph.D.
Blogs: http://matt.eifelle.com and http://blog.developpez.com/?blog=92
More information about the Numpy-discussion