python - 使用 cython 包装 C++ 项目

标签 python c++ cython

我想使用 cython 包装一个 c++ 项目,以便在 python 代码中使用。主类具有来自其他本地类的实例。我是否必须为每个已使用的类编写 pyx 文件或仅包装主类就足够了?

提前致谢!


编辑:

这是我要包装的代码: https://github.com/vojirt/asms/tree/master/src 我想包装 colortracker 函数,因为这个类中使用了其他类,我是否也需要包装它们?

最佳答案

感谢 DavidW,问题已解决。我用这段代码来包装 cv::Mat:

cdef extern from "opencv2/core/core.hpp" namespace "cv":
    cdef cppclass Mat:
        Mat() except +
        void create(int, int, int)
        void* data

只需要包装直接在colortracker类的公共(public)函数中使用的类和函数。

关于python - 使用 cython 包装 C++ 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42164249/

相关文章:

python - Cython numpy 数组形状,元组赋值

python - 用 Python 和 Numpy 计算协方差

python-igraph 如何添加带权重的边?

python - CherryPy 更改我的响应代码

python - Groupby 多级索引中的时间仓

cython - 分发 python 包时处理 dylibs

c++ - 为什么 unique_ptr 有效但 auto_ptr 不适用于 STL

c++ - 连 catch 体顶点 OpenGL

c++ - 由于舍入行为导致 float 和错误结果

python - 带有 Cython 装饰器的纯 Python : How to get attribute access at module level