|
From: Daniel R. <dr...@gm...> - 2010-07-23 17:39:56
|
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
> Swi...@li...
> https://lists.sourceforge.net/lists/listinfo/swig-user
|