运行此代码后Kinect关闭,并显示错误

时间:2017-06-01 10:45:26

标签: python python-2.7 kinect pykinect

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

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的新手,所以任何帮助都表示赞赏!谢谢!

1 个答案:

答案 0 :(得分:0)

首先,代码中存在拼写错误。您已在skeleton_frame_ready中为kinect.skeleton_frame_ready+=skeleton_frame_ready功能分配回调,但已将其定义为def skeleton_fram_raedy(skeleton_frame)

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

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()

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

with nui.Runtime() as kinect:
    kinect.camera.elevation_angle = 0
    kinect.skeleton_frame_ready+=skeleton_frame_ready