我在Cython中有一个cdefed类,它看起来非常类似于以下内容:
cdef class AprilTagDetector:
cdef capriltag.apriltag_detector_t* _apriltag_detector
def __cinit__(self):
self._apriltag_detector = capriltag.apriltag_detector_create();
# standard null checks
# standard __dealloc__(self) here
property quad_decimate:
def __get__(self):
return self._apriltag_detector.quad_decimate相应的.pxd文件如下所示:
cdef extern from "apriltag.h":
# The detector itself
ctypedef struct apriltag_detector_t:
pass
# Detector constructor and destructor
apriltag_detector_t* apriltag_detector_create()
void apriltag_detector_destroy(apriltag_detector_t* td);问题是,当我编译这段代码时,它会弹出以下错误:
property quad_decimate:
def __get__(self):
return self._apriltag_detector.quad_decimate ^
------------------------------------------------------------
apriltags.pyx:47:14: Cannot convert 'apriltag_detector_t *' to Python object这里发生了什么事?我还无法从Cython文档中找到它。
发布于 2015-03-14 16:32:08
谢天谢地,当我和一个朋友在黑客空间做这个项目时,我发现了这个问题。问题在ctypedef struct apriltag_detector_t块中。当我在块中编写pass时,我认为Cython会自动计算出结构的内部内容,并允许我访问所需的元素--这里是quad_decimate。
事实并非如此。要让Cython理解结构的内容,必须将结构中的内容告诉它如下:
ctypedef struct apriltag_detector_t:
float quad_decimatehttps://stackoverflow.com/questions/28999518
复制相似问题