Initial cpp reimplementation.

This commit is contained in:
Daniel
2024-09-11 11:40:00 +02:00
parent 7b426d209c
commit 244f46559c
14 changed files with 1904 additions and 1 deletions

13
swig/Makefile Normal file
View File

@ -0,0 +1,13 @@
# Standard compile options for the c++ executable
FLAGS = -fPIC
# The python interface through swig
PYTHONI = -I/usr/include/python3.8/
PYTHONL = -Xlinker -export-dynamic
# Default super-target
all:
cd ../spt/ && g++ -fPIC -std=c++2a -Wall -I/usr/include/opencv4 -c *.cpp ; cd ../swig/
swig -c++ -python -keyword -o spt_wrap.cxx spt.i
g++ $(FLAGS) $(PYTHONI) -I/usr/include/opencv4 -c spt_wrap.cxx -o spt_wrap.o
g++ $(PYTHONL) $(LIBFLAGS) -shared ../spt/*.o spt_wrap.o -lopencv_core -lopencv_imgproc -lopencv_calib3d -o _spt.so

51
swig/spt.i Normal file
View File

@ -0,0 +1,51 @@
%module spt
%{
// Includes the header in the wrapper code
#include "../spt/camera.hpp"
#include "../spt/interface.hpp"
%}
// Some modules need extra imports beside the main .hpp file
%include "std_array.i"
%include "std_string.i"
%include "std_vector.i"
// Instantiate templates used by example
// If the template is too nested (>2), parts of it need to be declared as well
namespace std {
%template(DoubleMatrix_3x3) array<array<double, 3>, 3>;
%template(VectorDouble) vector<double>;
%template(DoubleMatrix_3x1) array<array<double, 1>, 3>;
%template(DoubleMatrix_3x4) array<array<double, 3>, 4>;
%template(Matrix_Jx4) vector<array<double, 4>>;
%template(Matrix_NxJx4) vector<vector<array<double, 4>>>;
%template(Matrix_Jx3) vector<array<double, 3>>;
%template(Matrix_VxNxJx3) vector<vector<vector<array<double, 3>>>>;
%template(VectorCamera) vector<Camera>;
%template(DoubleMatrix_2x3) array<array<double, 3>, 2>;
%template(VectorString) vector<std::string>;
}
// Convert vector to native (python) list
%naturalvar Camera::K;
%naturalvar Camera::DC;
%naturalvar Camera::R;
%naturalvar Camera::T;
// Improve printing of result objects
%extend Camera {
std::string __str__() const {
return $self->to_string();
}
}
// Ignore: Warning 503: Can't wrap 'operator <<' unless renamed to a valid identifier.
%warnfilter(503) Camera;
// Ignore: Warning 511: Can't use keyword arguments with overloaded functions.
// The warning is cause by enabling keyword arguments, which doesn't work for vectors.
#pragma SWIG nowarn=511
// Parse the header file to generate wrappers
%include "../spt/camera.hpp"
%include "../spt/interface.hpp"