PyKinect – write Kinect games using Python!

 API Reference

We are very excited to announce PyKinect with PTVS 1.1.  PyKinect enables writing awesome games and interfaces using Python:

 

pykinect.vs

Dino goes on a diet: Before (grey) and After (yellow)

 

pykinect.vs.debug

Set breakpoints & Explore Kinect sensor data in the debugger directly

 

Prerequisites:

- CPython 2.7

- PyGame (http://www.pygame.org/download.shtml)

- Kinect SDK (http://kinectforwindows.org/  32-bit only!)

- Speech support (Kinect for Windows Runtime Language Pack, version 0.9)

- A kinect sensor (note you don’t need an Xbox 360 to use PyKinect) 

- A kinect Power/USB Adaptor (eg: Sample from Amazon.com)

 

Installation:

Assuming you’ve already installed PTVS & a CPython interpreter, install PyGame, Kinect SDK and PyKinect (order doesn’t matter).  To verify the installation, you can check: Tools/Python Tools/Samples/PyKinect -- you should be able use this to install PyKinect into a 32-bit Python distribution:

 

pykinect.install

Note: PyKinect only works with a 32-bit CPython setup currently

 

Run the demos:

 

File/New project/… /Kinect Game  - this is the “hello world!” of Kinect.  This basically sets up the event loop & does basic skeleton tracking:

 

pykinect.hw

Pykinect & Pygame make writing Kinect games easy

 

For a slightly more involved sample, please see:

https://hg01.codeplex.com/pytools/raw-file/76d5a3d3bf67/Release/Product/Python/PyKinect/PyKinect/PyGameDemo.py

This sample renders the skeletons w the video or depth cameras.  When you run this sample, it opens a console window & prints the available keyboard commands.

 

Notes about PyKinect:

PyKinect itself doesn’t depend on Pygame – you can write games w/o it.  However, our samples do.  We use it because Pygame is awesome & popular.

A couple of things to watch out for:  

- Currently only 32-bit flavor of CPython is supported (ie, don’t install it w a 64-bit Python interpreter even if PTVS allows it)

- If you are not getting skeleton tracking: make sure your body is within the sensor’s range & your legs are visible to the camera.

- Sometimes the Pygame event queue can be overfilled – if this happens an exception is raised and can be handles appropriately.

 

 

 

 

Cool things you do with Kinect:

Check out the Xbox Kinect page: http://www.xbox.com/en-US/Kinect/Kinect-Effect .

 

A request!

If you develop a game or a sample that you’re willing to share, please let us know!  We’d love to see what you’ve come up with & we can feature it here.

 

Thanks!

Last edited Aug 16, 2012 at 7:14 PM by huguesv, version 13

Comments

Teketel Jun 1, 2013 at 10:15 AM 
Great job. while i was trying to setup py kinect and run any of the demo files i get the following error:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Traceback (most recent call last):
File "C:\Users\Jonathan\Downloads\Compressed\KinectDemos\KinectKonsole.py", line 30, in <module>
with nui.Runtime() as kinect:
File "C:\Python27\lib\site-packages\pykinect-1.0-py2.7.egg\pykinect\nui\__init__.py", line 107, in __init__
self._nui = _NuiCreateSensorByIndex(index)
File "C:\Python27\lib\site-packages\pykinect-1.0-py2.7.egg\pykinect\nui\_interop.py", line 237, in _NuiCreateSensorByIndex
__NuiCreateSensorByIndex(index, ctypes.byref(inst))
File "_ctypes/callproc.c", line 936, in GetResult
WindowsError: [Error -2097085051] Windows Error 0x83010585
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

What do you advice? Thanks.

huguesv Aug 20, 2012 at 9:36 PM 
I have created a work item to add support for the new features introduced in the 1.5 SDK. Note that PyKinect currently works with the 1.5 SDK, it just doesn't have the new features.
http://pytools.codeplex.com/workitem/800
You can vote for it to show your interest.

amodal1 Jun 24, 2012 at 2:29 AM 
Fancy seeing you here, djtomservo. I'll repeat your question for a more specific case. Has this been updated for the 1.5 version of the SDK?

djTomServo May 23, 2012 at 10:31 PM 
Cool stuff, can we expect regular updates to this to keep pace with the main SDK releases?

TheApe Feb 13, 2012 at 7:48 PM 
The code in the examples and in the pykinect module seems to be broken. The example worked after changing two lines:

1) in PyGameDemo.py:
every "frame.image.contents.bits" -> "frame.image.bits"

2) and in the pykinect\nui\structs.py:
line 114: return desc.height.value -> return desc.height

after this the demo should definitely start