so if I have:

cdef class IplImage:
       cdef c_lib.IplImage* thisptr


cdef class CvMat:
      cdef c_lib.CvMat* thisptr



then I can just do this?

def exposedPythonFunc(image):   where image can be an IplImage or CvMat
      c_lib.cFunction(image.thisptr)      since I know thisptr exists



or must I do?

def exposedPythonFunc(image):
     if isinstance(image, IplImage):
            c_lib.cFunction(image.thisptr)

    elif isinstance(image, CvMat):
           c_lib.cFunction(image.thisptr)

    else:
           raise NotImplementedError


Thanks!

Chris

On Fri, May 22, 2009 at 12:50 AM, Dag Sverre Seljebotn <
[email protected]> wrote:

> Hi Chris,
>
> > the problem is that the C library has several functions that will accept
> > one
> > of many types of arrays.
> >
> > The function parameter type is CvArr whose definition is (in C):
> >
> > typedef void CvArr;
> >
> > and the functions are declared as accepting CvArr* types as arguments.
> >
> > two of the types I am wrapping are IplImage and CvMat both of which can
> be
> > passed as CvArr*.
> >
> > I would like to make python callable functions that accept either
> instance
> > of IplImage or CvMat (which I have created as extension types).
> >
> > Unfortunately, i haven't yet been able to figure it out through various
> > tinkering with subclassing, casting, or void pointers....
>
> Note that
>
> def f(CvMat foo): ...
>
> is almost exactly the same as
>
> def f(foo):
>    if not isinstance(foo, CvMat): raise some error...
>
> So, what you do is
>
> def f(obj):
>    if isinstance(foo, CvMat): (a)
>    elif isinstance(foo, IplImage): (b)
>    else: raise some error
>
> Dag Sverre
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to