1

我正在尝试运行以下代码,

from pykinect import nui
from pykinect.nui import JointId
from pykinect.nui import SkeletonTrackingState
from pykinect.nui import TransformSmoothParameters
with nui.Runtime() as kinect:
    kinect.skeleton_frame_ready+=skeleton_frame_ready
    kinect.skeleton_engine.enable=True
    while True:
        frame= kinect.skeleton_engine.get_next_frame()
        for skeleton in frame.SkeletonData:
            def skeleton_fram_raedy(skeleton_frame):
                for index,data in enumerate(skeleton):
                   if skeleton.eTrackingState==nui.SkeletonTrackingState.TRACKED:
                        head=data.SkeletonPositions[JointId.Head]
                        print head

但 Kinect 关闭并给出以下错误:

Traceback (most recent call last):
  File "C:\Users\sayyed javed ahmed\Desktop\Humaira\Practice Codes-Python\skeletonnew.py", line 5, in <module>
    with nui.Runtime() as kinect:
  File "C:\Python27\lib\site-packages\pykinect\nui\__init__.py", line 126, in __init__
    self.camera = Camera(self)
  File "C:\Python27\lib\site-packages\pykinect\nui\__init__.py", line 352, in __init__
    self.elevation_angle
  File "C:\Python27\lib\site-packages\pykinect\nui\__init__.py", line 359, in get_elevation_angle
    return self.runtime._nui.NuiCameraElevationGetAngle()
  File "C:\Python27\lib\site-packages\pykinect\nui\_interop.py", line 200, in NuiCameraElevationGetAngle
    _NuiInstance._NuiCameraElevationGetAngle(self, ctypes.byref(res))
  File "_ctypes/callproc.c", line 950, in GetResult
WindowsError: [Error -2147024883] The data is invalid

我是 PyKinect 的新手,因此感谢您的帮助!谢谢!

4

1 回答 1

0

首先,您的代码中有拼写错误。您正在为skeleton_frame_readyin 中的函数分配回调kinect.skeleton_frame_ready+=skeleton_frame_ready,但已将其定义为def skeleton_fram_raedy(skeleton_frame).

其次,我认为您的缩进已关闭,您在 for 循环中的 while 循环中有一个函数定义:

while True:
    frame= kinect.skeleton_engine.get_next_frame()
    for skeleton in frame.SkeletonData:
        def skeleton_fram_raedy(skeleton_frame):
        ...

尝试这样的事情:

from pykinect import nui
from pykinect.nui import JointId
from pykinect.nui import SkeletonTrackingState
from pykinect.nui import TransformSmoothParameters

def skeleton_frame_ready(skeleton_frame):
    for skeleton in frame.SkeletonData:
        if skeleton.eTrackingState==nui.SkeletonTrackingState.TRACKED:
            for index,data in enumerate(skeleton):
                head=data.SkeletonPositions[JointId.Head]
                print head

with nui.Runtime() as kinect:
    kinect.skeleton_frame_ready+=skeleton_frame_ready
    kinect.skeleton_engine.enable=True
    while True:
        frame= kinect.skeleton_engine.get_next_frame()

第三,错误表明为 kinect 相机角度传递了无效参数。不知道为什么会这样。您可以尝试在初始化 nui 后立即将仰角设置为 0:

with nui.Runtime() as kinect:
    kinect.camera.elevation_angle = 0
    kinect.skeleton_frame_ready+=skeleton_frame_ready
于 2017-11-10T10:45:14.973 回答