void * C array to a Numpy array using Swig



Hello People

I hope I am On Topic. Anyways, here is my problem. Any insights would
be really appreciated.

I have wrapped a C IO module using SWIG -> Python Module. Suppose the
name of the module is "imageio" and the reader function from the file
is image_read() which returns an object ( "filled" C structure) with a
lot of members.

Let

a = imageio.image_read("testfile.image")

Now a is the object which contains pointer to data of the image. ( void
* pdata). ( a also contains the datatype which I need to typecast to
get the data pointed by pdata). My question is how to access the data
pointed by pdata in *Python*.

Ideally I want the data to be converted into a Scipy(Numpy) Array
object so that I can perform further operations in Python. Any pointers
will be appreciated.

I think this has to do with PyArrayObjects, TypeMaps etc. but I
couldn't consolidate the whole information. If anyone has done this
kinda stuff before or if anyone can point me to a correct/better way,
it would be really great.

Regards
Krish Subramaniam

.



Relevant Pages

  • Re: Python Memory Leak using SWIG
    ... I then call it from python like so: ... returned is a pointer to the data. ... tell SWIG to delete the data, and return the structure some other way? ... // set the dimensions for this scale & angle ...
    (comp.lang.python)
  • Python Memory Leak using SWIG
    ... I then call it from python like so: ... returned is a pointer to the data. ... tell SWIG to delete the data, and return the structure some other way? ... // set the dimensions for this scale & angle ...
    (comp.lang.python)
  • Re: Wrapping c functions
    ... If it's truly opaque and you trust your use of the code you can ... at the Python/C interface cast the integer back to a pointer. ... Or use the Python extension API to make a new type. ... FreeImage interface using SWIG. ...
    (comp.lang.python)
  • Re: Pocket PC - Pointer Crash
    ... PUSHORT pData; ... I'm de-referencing a pointer who's contents/values I can view without any ... problems in the memory watch window. ... int FOO ...
    (microsoft.public.pocketpc.developer)
  • Re: Help with PAM and ctypes
    ... addr is the memory address as a Python integer. ... the preferred way to create a NULL pointer in ctypes is to call the pointer type without an argument: ... My initial attempt to fix this involved wrapping strdup to allocate a ... copy of a string to send back to PAM. ...
    (comp.lang.python)