473,785 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ctypes and pointers

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(cvImag e)
print cvImage
cvImage2 = macopencv.cvClo neImage(cvImage )

The output is

2007-04-14 19:22:53.910 SequenceGrabber Test[5320] Returning IplImage at
Address of IplImage: e860c60
e860c60
c_void_p(243666 016)
2007-04-14 19:22:53.915 SequenceGrabber Test[5320] Exception raised
during posting of notification. Ignored. exception:
exceptions.Valu eError: 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
Apr 14 '07 #1
2 3412
[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...thonCansiCombo
..

This example loads the function find_root from the dll
root_find_lib.d ll 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.LoadLibr ary("root_find_ lib.dll")
find = root_find_lib.f ind_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/

On 14 Apr, 19:25, "Diez B. Roggisch" <d...@nospam.we b.dewrote:
Hi,

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

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(cvImag e)
print cvImage
cvImage2 = macopencv.cvClo neImage(cvImage )

The output is

2007-04-14 19:22:53.910 SequenceGrabber Test[5320] Returning IplImage at
Address of IplImage: e860c60
e860c60
c_void_p(243666 016)
2007-04-14 19:22:53.915 SequenceGrabber Test[5320] Exception raised
during posting of notification. Ignored. exception:
exceptions.Valu eError: 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

Apr 16 '07 #2
per9000 wrote:
[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...thonCansiCombo
.

This example loads the function find_root from the dll
root_find_lib.d ll 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.LoadLibr ary("root_find_ lib.dll")
find = root_find_lib.f ind_root
find.restype = c_double
I found the solution to be

X.from_address( address)

where X is some ctypes.Structur e

Diez
Apr 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1525
by: Thomas Heller | last post by:
It's release day ;-) ctypes 0.6.3 released ===================== Overview 'ctypes' is a Python package to create and manipulate C data types in Python, and to call functions in dynamic link libraries/shared dlls. It allows wrapping these libraries in pure Python.
1
2590
by: Thomas Heller | last post by:
ctypes 0.9.1 released - Sept 14, 2004 ===================================== Overview ctypes is a ffi (Foreign Function Interface) package for Python 2.3 and higher. ctypes allows to call functions exposed from dlls/shared libraries and has extensive facilities to create, access and manipulate
3
5552
by: Lenard Lindstrom | last post by:
Posted in a previous thread was some Python code for accessing Window's Simple MAPI api using the ctypes module. http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9 This Simple MAPI module was Ian's completed version of an example I had posted in an earlier message. In it I had to set some pointer fields in a C structure to NULL. I was not happy with the solution I used so I made an inquiry on the ctypes-users...
3
5006
by: rubbishemail | last post by:
Hello, i've got a problem with pointers in the following function which i want to use: I16 __stdcall DO_ReadPort (U16 CardNumber, U16 Port, U32 *Value) The function is supposed to read out the status of a digital port of analog digital interface card. I got this function from Dask.h which came with the card. The relevant lines concerning this function are the following:
2
2331
by: cantankerousoldgit | last post by:
I am trying to call a DLL with a function like this: """DESCRIPTION: Get a list of objects attributes matching attribute values ARGUMENTS: session : the current session classId : the class Id of objects owning attributes to
12
10129
by: p.lavarre | last post by:
Q: The C idea of (pv != NULL) is said most directly in Python ctypes how? A: We are of course supposed to write something like: def c_not_null(pv): return (ctypes.cast(pv, ctypes.c_void_p).value != None) Yes?
3
4231
by: p.lavarre | last post by:
Subject: Python CTypes translation of (pv != NULL) And so then the next related Faq is: Q: How should I test for ((void *) -1)? A: (pv == 0xffffFFFF) works often.
2
3633
by: Richard Jones | last post by:
Does anyone know how to do the equivalent of this using ctypes? image_data = malloc(width * height * components); row_pointers = png_get_rows(png_ptr, info_ptr); for (y = 0; y < height; y++) memcpy(&image_data, row_pointers, width * components); That is, I need to get the address of a location *within* an allocated
2
4436
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p * len(id) # id is a list of strings Id_dat=StringVector() for i in range(len(Id)): ....Id_dat=id
3
4808
by: Ron Garret | last post by:
CTypes on a 64-bit machine appears to be truncating pointers to 32 bits: $ uname -a Linux monster1 2.6.18-6-amd64 #1 SMP Mon Jun 16 22:30:01 UTC 2008 x86_64 GNU/Linux $ cat foo.c void* foo(void* x) { return x; } $ gcc -fPIC -shared foo.c -o foo.so $ file foo.so foo.so: ELF 64-bit LSB shared object, AMD x86-64, version 1 (SYSV), not
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.