Pointers
Javier Correa <[email protected]> Tue, 9 Nov 2010 17:16:53 +0000
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
--===============0303935313==
Content-Type: multipart/alternative; boundary=20cf3054a88533bc040494a1e895
--20cf3054a88533bc040494a1e895
Content-Type: text/plain; charset=UTF-8
I-m new to pyrex and I'm trying to use it to have access to a library
(MesaSR, http://www.mesa-imaging.ch/drivers.php), but I can't make use of
pointers.
I can't seem to define a function that one of its arguments it's a pointer
(a function that initialize the structure). I'm also having troubles with
using the SR_GetImage that returns a void* pointer.
My code is as follows:
import numpy
cdef extern from "libMesaSR.h":
ctypedef SRCAM
int SR_OpenUSB(SRCAM * cam, unsigned int serial)
int SR_ReadSerial(SRCAM cam)
int SR_GetRows(SRCAM cam)
int SR_GetCols(SRCAM cam)
void * SR_GetImage(SRCAM cam, unsigned int i)
cdef class MesaSR:
cdef SRCAM cam
cdef int cols
cdef int rows
cdef object range_image
def __init__(self, serial):
status = SR_OpenUSB(&self.cam, serial)
self.cols = SR_GetCols(self.cam)
self.rows = SR_GetRows(self.cam)
self.range_image = numpy.empty([self.rows, self.cols], 'H')
def get_image(self):
cdef void * images
cdef unsigned int value
image = SR_GetImage(self.cam, 0)
for 0 <= i < self.cols:
for 0 <= j <self.rows:
value = image[i + j*self.cols]
self.range_image[j][i] = value
And I'm getting:
mesasr.pyx:5:22: Pointer base type cannot be a Python object
mesasr.pyx:18:22: Cannot take address of Python variable
mesasr.pyx:26:21: Cannot convert 'void *' to Python object
Am I missing something?
--
Javier Correa
Por favor, no imprimas este e-mail si realmente no lo necesitas... Conservar
el medio ambiente es nuestra tarea...
Please, don't print this e-mail if it's not needed... preserve the
environment is our task...
--20cf3054a88533bc040494a1e895
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div>I-m new to pyrex and I'm trying to use it to have access to a libr=
ary (MesaSR,=C2=A0<a href=3D"http://www.mesa-imaging.ch/drivers.php">http:/=
/www.mesa-imaging.ch/drivers.php</a>), but I can't make use of pointers=
.</div>
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8"><d=
iv><br></div><div>I can't seem to define a function that one of its arg=
uments it's a pointer (a function that initialize the structure). I'=
;m also having troubles with using the SR_GetImage that returns a void* poi=
nter.</div>
<div><br></div><div>My code is as follows:</div><div><br></div><div>import =
numpy</div><div><br></div><div>cdef extern from "libMesaSR.h":</d=
iv><div>=C2=A0=C2=A0 ctypedef SRCAM</div><div>=C2=A0=C2=A0 int SR_OpenUSB(S=
RCAM * cam, unsigned int serial)</div>
<div>=C2=A0=C2=A0 int SR_ReadSerial(SRCAM cam)</div><div>=C2=A0=C2=A0 int S=
R_GetRows(SRCAM cam)</div><div>=C2=A0=C2=A0 int SR_GetCols(SRCAM cam)</div>=
<div>=C2=A0=C2=A0 void * SR_GetImage(SRCAM cam, unsigned int i)</div><div><=
br></div><div>cdef class MesaSR:</div>
<div>=C2=A0=C2=A0 cdef SRCAM cam=C2=A0</div><div>=C2=A0=C2=A0 cdef int cols=
</div><div>=C2=A0=C2=A0 cdef int rows</div><div>=C2=A0=C2=A0 cdef object ra=
nge_image</div><div><br></div><div>=C2=A0=C2=A0 def __init__(self, serial):=
</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0status =3D SR_OpenUSB(&self.cam, s=
erial)</div>
<div>=C2=A0=C2=A0 =C2=A0 =C2=A0self.cols =3D SR_GetCols(self.cam)</div><div=
>=C2=A0=C2=A0 =C2=A0 =C2=A0self.rows =3D SR_GetRows(self.cam)</div><div>=C2=
=A0=C2=A0 =C2=A0 =C2=A0self.range_image =3D numpy.empty([self.rows, self.co=
ls], 'H')</div><div><br></div><div>=C2=A0=C2=A0 def get_image(self)=
:</div>
<div>=C2=A0=C2=A0 =C2=A0 =C2=A0cdef void * images</div><div>=C2=A0=C2=A0 =
=C2=A0 =C2=A0cdef unsigned int value</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0im=
age =3D SR_GetImage(self.cam, 0)</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0for 0 =
<=3D i < self.cols:</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 for 0=
<=3D j <self.rows:</div><div>
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0value =3D image[i + j*self.c=
ols]</div><div>=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.range_im=
age[j][i] =3D value</div><div><br></div><div>And I'm getting:</div><div=
><div>mesasr.pyx:5:22: Pointer base type cannot be a Python object</div>
<div>mesasr.pyx:18:22: Cannot take address of Python variable</div><div>mes=
asr.pyx:26:21: Cannot convert 'void *' to Python object</div></div>=
<div><br></div>Am I missing something?<br>-- <br>Javier Correa<br><br>Por f=
avor, no imprimas este e-mail si realmente no lo necesitas... Conservar el =
medio ambiente es nuestra tarea... <br>
Please, don't print this e-mail if it's not needed... preserve the =
environment is our task...<br><br>
--20cf3054a88533bc040494a1e895--
--===============0303935313==
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
_______________________________________________
Pyrex mailing list
[email protected]
http://lists.copyleft.no/mailman/listinfo/pyrex
--===============0303935313==--