PyKinect - write Kinect games using Python!

PyKinect enables writing awesome games and interfaces using Python:

Run

Set breakpoints & Explore Kinect sensor data in the debugger directly:

Run

Prerequisites

PyKinect itself doesn't depend on Pygame - you can write games without it. However, our samples do. We use it because Pygame is awesome & popular.

Installation

PyKinect is a Python package available from PyPI.

You can install it in your CPython 2.7 32-bit environment using:

pip install pykinect

If you use PTVS with the Visual Studio sample project template, it will prompt to install PyKinect for you at project creation.

The Visual Studio sample project template for PyKinect is available as part of the PTVS Samples 2.1.vsix. Download it from the PTVS downloads page.

Don't forget to also install Pygame and the Kinect SDK.

Sample Project

To create a sample project, select File, New, Project, then under Python, Samples, choose PyGame using PyKinect.

New Project

You'll have the option of installing PyKinect in a new virtual environment, your global Python 2.7 environment or skip installation.

Install PyKinect

When the project finishes loading, it will display instructions for installing Pygame. You can skip that if you are using your global Python 2.7 with Pygame already installed.

Install PyGame

The sample code basically sets up the event loop & does basic skeleton tracking.

Install PyGame

For a slightly more involved sample, please see PyGameDemo.py.

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

Notes

A couple of things to watch out for:

  • Currently only 32-bit flavor of CPython is supported (ie, don't install it with 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 handled appropriately.

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.



This page was generated using a tool. Changes will be lost when the html is regenerated. Source file: PyKinect.md

d944f85bf7937db9ba6eca4cb2239dd1dc394daf032665f46ad81f2c632755f1

Last edited Tue at 9:08 PM by huguesv, version 14

Comments

Teketel Jun 1, 2013 at 11: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 10: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 3: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 11:31 PM 
Cool stuff, can we expect regular updates to this to keep pace with the main SDK releases?

TheApe Feb 13, 2012 at 8: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