传回并使用C的结构指针数组?

时间:2017-09-30 17:25:41

标签: python c struct ctypes

我有以下C代码

int num_detections = zarray_size(detections);

apriltag_detection_t tag_detections[num_detections];
for (int i = 0; i < zarray_size(detections); i++) {
    apriltag_detection_t *det;
    zarray_get(detections, i, &det);
    tag_detections[i] = det;
}

在Python通过ctypes调用的函数中定义。我希望能够将tag_detections(一个struct指针数组)传回我的Python函数,并能够以struct的形式访问Python对象。这就是我在Python方面所拥有的。

libtag36h11_detector = ctypes.CDLL('tag36h11_detector/libtag36h11_detector.so')
_scan_frame = libtag36h11_detector.scan_frame
_scan_frame.argtypes = (ctypes.c_int, ctypes.c_int, ndpointer(ctypes.c_uint8, flags="C_CONTIGUOUS"))
...
def scan_frame(frame):
    height, width, channels = frame.shape
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    frame = frame.flatten()
    _scan_frame(width, height, frame)

搜索结果已经找到了相反的方法(将Python对象数组传递给C struct的数组)

0 个答案:

没有答案