I am trying to wrap some C++ classes and functions to Python using Cython. So far I have wrapped 2 classes, and now I want to wrap a function.
The function's signature is
std::map<std::string, std::vector<PyObject*>> analyze(PyObject* img, LandmarkDetector::CLNF& clnf_model, LandmarkDetector::FaceModelParameters& params);
I have successfully wrapped the CLNF
and FaceModelParameters
classes, and I am having trouble wrapping this analyze
function.
The function deals with PyObject*
s because it deals with opencv, and I'd like to be able to pass them easily between the languages. I am using these functions in order to perform the casting between cv::Point
to python objects and between python Mat to cv::Mat
.
This is my pyx file:
from libcpp.vector cimport vector
from libcpp.map cimport map
from libcpp.string cimport string
from cpython.ref cimport PyObject
from cython.operator cimport dereference as deref
cdef extern from "LandmarkDetectorModel.h" namespace "LandmarkDetector":
cdef cppclass CLNF:
CLNF(string) except +
cdef extern from "LandmarkDetectorParameters.h" namespace "LandmarkDetector":
cdef cppclass FaceModelParameters:
FaceModelParameters(vector[string] &) except +
cdef class PyCLNF:
cdef CLNF *thisptr
def __cinit__(self, arg):
self.thisptr = new CLNF(<string> arg)
cdef class PyLandmarkDetectorParameters:
cdef FaceModelParameters *thisptr
def __cinit__(self, args):
self.thisptr = new FaceModelParameters(args)
cdef extern from "FaceLandmarkVid.h":
map[string, vector[object]] analyze(object, CLNF&, FaceModelParameters&)
cdef PyAnalyze(object img, PyCLNF clnf, PyLandmarkDetectorParameters facemodel):
return analyze(img, deref(clnf.thisptr), deref(facemodel.thisptr))
But upon trying to compile it I get the error message
landmarks.pyx:26:23: Python object type 'Python object' cannot be used as a template argument
(which refers to the line map[string, vector[object]] analyze [...]
)