Daniel,

thanks! If I understand you correctly, you wrote your own typemap right now to "parse" the python list and extract its objects... That's what I'm trying to do right now, too, so if you could send me your code that would probably help me out a lot!

I was wondering however, if there was a simpler way such as by using

%template(MatVector) std::vector<cv::Mat>;

and just supplying the conversion between the PyObjects *in* the list and cv::Mat.

I guess one can somehow register the conversion routine with the underlying swig code for std::vector... (?)  Right now it only seems to work for Swig types.

Thanks anyway!

Martin


On Fri, Jul 23, 2010 at 7:39 PM, Daniel Russel <drussel@gmail.com> wrote:
I've used a set of typemaps and associated C++ converter classes to handle similar cases (eg python lists of python tuples of objects going to std::vector of std::pairs). The disadvantage of my approach is you have to write C++ code to convert a PyObject for the Numpy array into your C++ matrix (that may not be hard, but I don't know how to do it offhand). It also makes heavy use of templates and boost on the C++ side, in case this is a problem. Anyway, I can send you that code to check out if it helps.
      --Daniel

On Jul 23, 2010, at 8:52 AM, Martin Baeuml wrote:

> Hi,
>
> I have written some typemaps that convert numpy arrays to cv::Mat and back, using fragments from the excellent numpy.i.  Basically they look like:
>
> typemap(in) const cv::Mat& {
>     $1 = array_to_mat($input);
>     if ($1 == NULL)
>         SWIG_fail;
> }
> typemap(int) cv::Mat& {
> ...
> }
> ...
>
> This works fine.  I'm having problems however with generating proper conversion function for std::vector<cv::Mat>  from a *list* of numpy arrays.
>
> Basically I have a function
>
> void do_something(const std::vector<cv::Mat>& input);
>
> and I want to call it with
>
> input = [numpy.zeros((10,10)) for i in range(10)]
> do_something(input)
>
> I tried
>
> namespace std {
> %template(MatVector) vector<cv::Mat>;
> }
>
> but this did not have the desired effect.  Looking at the generated code, it seems as if swig does not use my defined typemaps to convert the input numpy arrays within the list to cv::Mats.  I have also tried understanding how std_vector.i works but I was not able to wrap my head around it...
>
> Is there any way to achieve this?
>
> Thanks
> Martin
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first_______________________________________________
> Swig-user mailing list
> Swig-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/swig-user


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Swig-user mailing list
Swig-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user



--
Martin Bäuml
Karlsruhe Institute of Technology
Institute for Anthropomatics
Adenauerring 2, 76131 Karlsruhe, Germany
Email: baeuml@kit.edu
Phone: +49 721 608 6265, Fax: +49 721 60 77 21