[SciPy-User] [SciPy-user] numpy and C

tinauser tinauser@libero...
Wed Jun 9 06:38:21 CDT 2010

Dear Charles,
thanks for the reply.
The part of code causing the problem was exactly this

Pymatout_img->data= cam_frame->data;
where Pymatout is a PyArrayObject and cam_frame is a structure having a
pointer to undefined char data.

The code works all right if I recast in this way

Pymatout_img->data= (char*)cam_frame->data;

I'm not sure if this is allowed;I guessed it works because even if
Pymatout_img->data is always a pointer to char, the PyArrayObject looks in
->descr->type_num to see what is the data type.


Charles R Harris wrote:
> On Thu, Jun 3, 2010 at 7:36 AM, tinauser <tinauser@libero.it> wrote:
>> Hallo,
>> I'm pretty new with both Python and C
>> I have a C application that run a python script.The python script then
>> uses
>> some
>> C functions written in the code that embedd the script itself.
>> I want to pass array from the C code (where an API is giving pointer to
>> data
>> I
>> want to plot in Python) and Python (a GUI).
>> What I've done so far  is to allocate before calling the Pyhon script a
>> PyArray
>> with PyArray_SimpleNew. Since the data are unsigned char, the command is:
>> my_second_array = (PyArrayObject *)PyArray_SimpleNew(2,dim,NPY_UBYTE);
>> When I call the Python script,I sent my_second_array.On a timer,
>> my_second_array
>> is used as a parameter for a C written function: the idea is to assign
>> the
>> pointer of a frame to my_second_array.data.
>> PyArrayObject *Pymatout_img=NULL;
>> PyArg_ParseTuple(args, "O", &Pymatout_img);//Pymatout_img is the matrix
>> that
>> was
>> created in C during the initialization with PyArray_SimpleNew
>> Pymatout_img->data= cam_frame->data;
>> The problem is that the compiler (I'm using visual C 2008) says that
>> cannot
>> convert *char to *unsigned char...
>> Can someone explains me what i'm doing wrong?
> Can you show the code that is causing the problem? There should be a line
> number somewhere.
> Chuck
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

View this message in context: http://old.nabble.com/numpy-and-C-tp28767579p28829120.html
Sent from the Scipy-User mailing list archive at Nabble.com.

More information about the SciPy-User mailing list