ibaiGorordo / pyKinectAzure

Python library to run Kinect Azure DK SDK functions
MIT License
446 stars 114 forks source link

_k4arecord.k4arecord.k4a_playback_open ctype error #35

Closed windingwind closed 2 years ago

windingwind commented 2 years ago

Hi, thank you for this excellent work. I'm trying to use the repo to do body tracking using recorded MKV.

However, I failed with ctype data-type check at a strange point, _k4arecord.k4arecord.k4a_playback_open.

Here is my code (not well tested):

_k4a.k4a.setup_library(modulePath)

k4a_record = _k4arecord.k4arecord(modulePath)
capture_handle = _k4a.k4a_capture_t()
calibration_handle = _k4a.k4a_calibration_t()

playback_handle = _k4arecordTypes.k4a_playback_t()

"""
my error occurs here:
"""
k4a_record.k4a_playback_open(ctypes.create_string_buffer(os.path.join(root_path, "kinect", device, "out.mkv").encode('utf-8')), playback_handle)

# k4a.k4a_calibration_get_from_raw(ctypes.create_string_buffer(raw_calibration.encode("utf-8")), ctypes.c_size_t(len(raw_calibration)), _k4atypes.K4A_DEPTH_MODE_NFOV_UNBINNED, _k4atypes.K4A_COLOR_RESOLUTION_1536P, calibration_t)

k4a_record.k4a_playback_get_calibration(playback_handle, calibration_handle)
body_tracker = kinectBodyTracker(bodyTrackingModulePath, calibration_handle, _k4abt.K4ABT_DEFAULT_MODEL)
while True:
    k4a_record.k4a_playback_get_next_capture(playback_handle, capture_handle)

    body_tracker.enqueue_capture(capture_handle)
    body_tracker.detectBodies()

    for body in body_tracker.bodiesNow:
        body_tracker.printBodyPosition(body)
        print(body.skeleton)

If argument 2 is playback_handle, it says

argument 2: <class 'TypeError'>: expected LP_LP__handle_k4a_playback_t instance instead of LP__handle_k4a_playback_t

If ctypes.pointer(playback_handle), it says

argument 2: <class 'TypeError'>: expected LP_LPhandle_k4a_playback_t instance instead of LP_LPhandle_k4a_playback_t

Which is very confusing, because it seems like ctypes.pointer(playback_handle) just have the right data type.

I also tried

isinstance(_k4arecordTypes.k4a_playback_t, ctypes.POINTER(_k4arecordTypes.k4a_playback_t))

True

What should I do?

Thanks!

windingwind commented 2 years ago

I'm sure all module paths are set correctly, I tested them with sample codes like realtime body tracker.

I'm using: Ubuntu 18.04 with python 3.8.8 conda env; k4a 1.4.1, k4abt 1.1

windingwind commented 2 years ago

I'm not very familiar with ctypes. I tried ctypes.POINTER(playback_handle), ctypes.byref(playback_handle), ctypes.POINTER(playback_handle)().

All failed, no doubt.

I also referred to other sample codes using APIs with a ctypes.POINTER(k4a_xxx_t) as argtypes, find out they just use 'k4a_xxx_t()' without any other operation as function input. Am I missing any point?

ibaiGorordo commented 2 years ago

Sorry for the delay,

I have uploaded a major refactor that was long overdue. I have added an example "examplePlaybackBodyTracker.py" to perform body tracking in a recording that did not have body tracking enabled.