相关疑难解决方法(0)

在Cython中返回一个结构数组

我试图在Cython中返回一个结构数组.

// .pyx

from libc.stdint cimport uint8_t

cdef extern from "<apriltag.h>":
    cdef struct apriltag_detection:
        int id
        double c[2]
        double p[4][2]

    ctypedef apriltag_detection apriltag_detection_t

cdef extern from "tag36h11_detector/tag36h11_detector.h":
    apriltag_detection_t* scan_frame(int width, int height, uint8_t* data);

cdef class Detection:
    # how do I "link" this to the struct defined above?
    def __cinit__(self):
        pass
    def __dealloc__(self):
        pass

def detect(width, height, frame):
    return scan_frame(width, height, frame)
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想detect在Python代码中调用该函数,并获取一个Detection对象列表,其中Detection是一个类型为apriltag_detectiondede 的C结构的包装类apriltag_detection_t.

我收到以下编译错误:

tag36h11_detector.pyx:22:21:无法将'apriltag_detection_t*'转换为Python对象

我找不到在文档中的任何地方返回指向结构或结构数组的指针的引用.

更新3

// .h …
Run Code Online (Sandbox Code Playgroud)

c python arrays struct cython

5
推荐指数
1
解决办法
1394
查看次数

标签 统计

arrays ×1

c ×1

cython ×1

python ×1

struct ×1