I have the following C code
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;
}
defined in a function that is being called by Python via ctypes
. I want to be able to pass back tag_detections
(an array of struct
pointers) back to my Python function, and be able to access the struct
s as Python objects. Here's what I have on the Python side.
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)
Search results have turned up ways to do the other way around (passing an array of Python objects to an array of C struct
s)