Kinect for Windows
The first generation of the Kinect sensor introduced in 2010 was called Xbox 360 Kinect and was intended to be used with the Xbox 360 gaming console. Later, Microsoft released another version called Kinect for Windows. This sensor looked exactly the same but had improved features for kiosk and application development like Near Mode. The biggest difference is that the Kinect for Windows was licensed for commercial app distribution, and the 360 one is for development work only.
In 2013 a new Kinect sensor was released with the XBOX One console as well as a new Kinect for Windows so both first generation sensors are now outdated. Unfortunately the XBOX One Kinect that comes with the console can no longer be used for development work like you can with the XBOX 360 Kinect.
In this introduction we will be dealing with the new generation of the Kinect for Windows sensor.
Kinect for Windows V2
XBOX and the Kinect are Microsoft products so it’s understandable that they want to restrict development to Windows PCs only. There are a few libraries like Libfreenect2 that, in theory, could enable Macs to work with the Kinect but they are not very reliable. I couldn’t get it working possibly due to this issue.
For the simple task of streaming data you probably don’t want to maintain a full desktop machine so I was looking at options to go as cheap and small as possible. It would be interesting to see if the new Raspberry PI 2 running Windows 10 IoT could handle this task? Or maybe one of these Stick PCs?
Let’s setup the Windows machine first, the one that is going to receive and handle the sensor data in the Node.js application. The reason why the Kinect 2 Node.js library we are going to use only works on Windows machines is that it relies on the official Kinect 2 SDK that can only be installed to Windows machines. Go ahead, and install it first from this page. You might want to restart your machine after this step. Please also note that in order to install the SDK you will need a 64bit Windows 8 or higher.
Next, you need Node.js installed in the Windows command line. The official Windows Installer can be downloaded from nodejs.org. If the installation was successful entering
node -v into the command line will give you the version number of Node installed. You need at least version 0.11.3 for the Kinect 2 module to work. The installation will depend on node-gyp so install that too:
npm install -g node-gyp.
If that wasn’t enough, you will need to install Microsoft Visual Studio C++ 2013 for Windows Desktops (Express version works too) and if you have a 64-bit build then the Windows 7 64-bit SDK. Yes, even if you are not on Windows 7.
After that you can type
npm install kinect2 and the library will be installed to your machine…
Reading skeleton data
Now that everything is installed, let’s test and extract the skeleton tracking data!
output.js for instance. We need to start off this file by loading the Kinect 2 library and initialising it:
After that we power up the Kinect with the .open() method and test if it returned true in the same line which means that the start up was successful:
Inside this if condition we can now add an asynchronous event listener that waits for the skeleton data to arrive:
Running this js file from the project folder with
node output.js will result in outputting the pure sensor data in a JSON format.
Here's the whole script in one, again:
Next week I’m going to publish a new post in which we will carry on and:
- Analyse the skeleton data and see what properties of the body can we extract from it
- Connect to the web socket server from Chrome on a Macintosh and visualise the skeleton data with HTML and CSS
- Define and interpret gestures from the pure data and create a full screen photo gallery that can be swiped back and forth with arm movements
Follow me on Twitter or Facebook in case you are interested and don't want to miss the new post.