I am trying to port some C ++ classes and functions to Python using Cython. So far I have wrapped 2 classes, and now I want to wrap a function.
Function Signature
std::map<std::string, std::vector<PyObject*>> analyze(PyObject* img, LandmarkDetector::CLNF& clnf_model, LandmarkDetector::FaceModelParameters& params);
I successfully wrapped the CLNF and FaceModelParameters , and I was unable to wrap this analyze function.
The function deals with PyObject* because it deals with opencv, and I would like to be able to easily transfer them between languages. I use these functions to cast between cv::Point python objects and between the python pressure gauge 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 when I try to compile it, I get an error
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 [...] )
source share