Cythonを使ってPythonにいくつかのC++クラスと関数をラップしようとしています。 これまでは2つのクラスをラップしていましたが、今は関数をラップしたいと思います。Pythonを含む複雑なオブジェクトをC++関数から返すCython
関数のシグネチャは、私がCLNF
とFaceModelParameters
クラスを成功裏に包まれている、と私はトラブルこのanalyze
機能をラップを持っています
std::map<std::string, std::vector<PyObject*>> analyze(PyObject* img, LandmarkDetector::CLNF& clnf_model, LandmarkDetector::FaceModelParameters& params);
です。
この関数はopencvを扱うのでPyObject*
を扱うので、それらの言語間で簡単に渡すことができます。 とpythonオブジェクトとの間、およびpython Matとcv::Mat
の間のキャストを実行するために私はthese functionsを使用しています。
これは私のPYXファイルです:
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))
しかし、それをコンパイルしようとすると、私はエラーメッセージ
landmarks.pyx:26:23: Python object type 'Python object' cannot be used as a template argument
を取得する(ラインmap[string, vector[object]] analyze [...]
をいう)