简体   繁体   English

运行此代码后Kinect关闭并出错

[英]Kinect shuts down after running this code and gives error

I'm trying to run the following code, 我正在尝试运行以下代码,

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

but Kinect shuts down and gives the following error: 但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

I'm new to PyKinect so any help is appreciated! 我是PyKinect的新手,所以任何帮助都表示赞赏! Thanks! 谢谢!

Firstly, there are typos in your code. 首先,代码中存在拼写错误。 You're assigning a callback to skeleton_frame_ready function in kinect.skeleton_frame_ready+=skeleton_frame_ready , but have defined it as def skeleton_fram_raedy(skeleton_frame) . 您正在kinect.skeleton_frame_ready+=skeleton_frame_readyskeleton_frame_ready函数分配回调,但已将其定义为def skeleton_fram_raedy(skeleton_frame)

Secondly, I think your indentation is off, you have a function definition in a for loop in a while loop: 其次,我认为你的缩进是关闭的,你在while循环中的for循环中有一个函数定义:

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

Try something like this: 尝试这样的事情:

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

Thirdly, the error indicates that invalid argument is passed to nui for the kinect camera angle. 第三,错误表明无效参数传递给nui用于kinect摄像机角度。 Not sure why that is. 不知道为什么会这样。 You could try setting the elevation angle to 0 right after initializing nui: 初始化nui后,您可以尝试将仰角设置为0:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM