【发布时间】:2017-10-01 21:00:21
【问题描述】:
我有以下 Cython 函数
def detect(width, height, np.ndarray[np.uint8_t, ndim=1] frame):
cdef detection_payload* detection = scan_frame(width, height, frame)
return DetectionPayload()._setup(detection)
这是scan_frame的签名
cdef extern from "tag36h11_detector/tag36h11_detector.h":
cdef struct detection_payload:
int size
apriltag_detection_t* detections
ctypedef detection_payload detection_payload_t
detection_payload* scan_frame(int width, int height, uint8_t* data)
这就是我尝试将数组传递给detect的方式
// test.py
from tag36h11_detector import detect
import numpy as np
a = np.array([1,2,3], dtype=np.uint8)
detect(4, 5, a)
这是我得到的错误...
Traceback(最近一次调用最后一次): 文件“test.py”,第 6 行,在 检测(4, 5, a) 文件“tag36h11_detector.pyx”,第 67 行,在 tag36h11_detector.detect 中 cdef detection_payload* detection = scan_frame(width, height, frame) 类型错误:预期字节,找到 numpy.ndarray
【问题讨论】:
-
如果尚未这样做,您需要在设置中包含 numpy 标头:cython.readthedocs.io/en/latest/src/reference/compilation.html