ctypes and pointers

D

Diez B. Roggisch

Hi,

I'm working under mac os x with the OpenCV-library that I load via ctypes.

From a ObjectiveC-methodcall I get an integer, that "really" is a
pointer to an IplImage-structure.

I've got a function that takes such a pointer. But I don't find a way to
pass it to that very function.

These are the relevant parts of my code:

cvImage = self._f.cvImage()
print "Address of IplImage: %x" % cvImage
cvImage = c_void_p(cvImage)
print cvImage
cvImage2 = macopencv.cvCloneImage(cvImage)

The output is

2007-04-14 19:22:53.910 SequenceGrabberTest[5320] Returning IplImage at
Address of IplImage: e860c60
e860c60
c_void_p(243666016)
2007-04-14 19:22:53.915 SequenceGrabberTest[5320] Exception raised
during posting of notification. Ignored. exception:
exceptions.ValueError: depythonifying 'pointer', got 'int'


The first line is actually from the ObjectivC-method, a log-statement.

As one can see, the pointer is passed back as integer.

But then I'm stuck.

Any suggestions would be appreciated!

diez
 
P

per9000

[This might be a double posting, if it isn't my previous post was
lost]

Look up "restype" in the ctypes library - it sets the return type from
a function. You may want to set it to c_void_p of something similar,
instead of the default int.

I made a similar discovery in my blog -
http://www.pererikstrandberg.se/blog/index.cgi?page=PythonCansiCombo
..

This example loads the function find_root from the dll
root_find_lib.dll into the variable "find". the restype of find is
then set to a c_double. This means that the item returned from C is a
C_double and not the default int.
root_find_lib = windll.LoadLibrary("root_find_lib.dll")
find = root_find_lib.find_root
find.restype = c_double


You may already know this but 243666016 == 0E860C60 in different
bases.

HTH,
Per

[:)]-|--<

--

Per Erik Strandberg
..NET Architect - Optimization
Tomlab Optimization Inc.
http://tomopt.com/tomnet/
 
D

Diez B. Roggisch

per9000 said:
[This might be a double posting, if it isn't my previous post was
lost]

Look up "restype" in the ctypes library - it sets the return type from
a function. You may want to set it to c_void_p of something similar,
instead of the default int.

I made a similar discovery in my blog -
http://www.pererikstrandberg.se/blog/index.cgi?page=PythonCansiCombo
.

This example loads the function find_root from the dll
root_find_lib.dll into the variable "find". the restype of find is
then set to a c_double. This means that the item returned from C is a
C_double and not the default int.
root_find_lib = windll.LoadLibrary("root_find_lib.dll")
find = root_find_lib.find_root
find.restype = c_double

I found the solution to be

X.from_address(address)

where X is some ctypes.Structure

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,043
Members
48,769
Latest member
Clifft

Latest Threads

Top