Kinect shuts down after running this code and gives error

420 Views Asked by At

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:

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! Thanks!

1

There are 1 best solutions below

0
On

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

Secondly, I think your indentation is off, you have a function definition in a for loop in a while loop:

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. Not sure why that is. You could try setting the elevation angle to 0 right after initializing nui:

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