1

So I have an .hpp file that I'm planning to use in swig, but said file has a template (Mat_<float> to be exact), but whenever I run swig I end up getting:

example.hpp::30: Error: Syntax error in input(1).

With line 30 being:

Mat_<float> measurement(8,1);

I'm not very familiar with c++ (and using cv2 for this one particular project isn't really possible), and from what I've found I need to define the template in my .i file, but looking through the examples, I wasn't quite sure how I should go about doing that. Any help?

My .i file:

%module example

%include <opencv.i>
%cv_instantiate_all_defaults

%{
    #include "example.hpp"
%}

%include "example.hpp"

(I'm using opencv-swig for the OpenCV part)

Commands for compiling/building:

swig -I/home/me/Documents/.../opencv-swig/lib/ -I/usr/include -python -c++ example.i

g++ -shared -std=c++1z -fpic example_wrap.cxx $(pkg-config --cflags --libs python3) $(pkg-config --libs opencv) -o _example.so
Community
  • 1
  • 1
SSBakh
  • 1,487
  • 1
  • 14
  • 27
  • Can you share more of your `file.hpp` file ? And is it the same file as `example.hpp` ? – Fifi Aug 16 '19 at 08:38
  • @Fifi Oh my bad, they're the same file, and file/example were just placeholder names. Edited. – SSBakh Aug 16 '19 at 08:58
  • Did you try without the line 30 ? I already had the same error message and it was not related to the indicated line, but with a problem sooner – Fifi Aug 16 '19 at 09:09
  • @Fifi Yup. I am 100% sure it's just a matter of defining the template. – SSBakh Aug 16 '19 at 09:11
  • And does it work with an other type ? (Like `Mat_` for example) – Fifi Aug 16 '19 at 09:23
  • @Fifi No, it just doesn't work in general. And from what I've gathered, it comes from using a template, and said template needs to be defined in the .i file, however, despite looking at the documentation, I wasn't quite sure how to go about doing that. – SSBakh Aug 16 '19 at 09:25
  • Maybe you can try to open an issue in the github of opencv-swig. – Fifi Aug 21 '19 at 12:53

1 Answers1

1

Swig documentation on templates

You might need to use something like %template(Mat_float_) Mat_<float>; at the end of your .i file.

Joe'
  • 376
  • 6
  • 10