[Image-SIG] Trying to implement the array interface

Mark Asbach asbach at ient.rwth-aachen.de
Wed Jan 14 12:17:40 CET 2009


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 
  .
- 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.

The stuff described above is in the head revision of OpenCV,  
accessible via "svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk/opencv 
".

I've tried using the following packages with OpenCV this way:
- numpy (1.0.4): everything works as expected. This is the most  
important library for OpenCV users, so this is a good sign.
- pylab/matplotlib (0.91.2): seems to use numpy / scipy-core.  
Everything okay.
- 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?
- Numeric (24.2): I can create arrays from OpenCV datatypes and print  
them. Converting to other types however always yields 'Cannot convert  
scalar to float' or 'a float is required'. Strange :-/ Numeric.array  
instances also don't carry an __array_interface__. I can however  
convert by using numpy.arrays as intermediate step.
- Gnuplot (1.7): uses Numeric, so doesn't work as well
- pymat: didn't check. Seems to use Numeric, test results cover  
Numeric 23 and Matlab 6.5 only, so this package might be dead?
- numarray: didn't check. Is there still any relevance of this package?

Best,
Mark

-- 
Mark Asbach
Institut für Nachrichtentechnik, RWTH Aachen University
http://www.ient.rwth-aachen.de/cms/team/m_asbach

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4403 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090114/66ef420d/attachment.bin>


More information about the Image-SIG mailing list