Documentos de Académico
Documentos de Profesional
Documentos de Cultura
GetstartedwithXBOXKinect2JavaScriptdevelopment
1/8
22/9/2016
GetstartedwithXBOXKinect2JavaScriptdevelopment
The rst 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 dierence is that the Kinect for Windows was licensed
for commercial app distribution, and the 360 one is for development work only.
Both of these sensors have a USB connector and are compatible with PCs so can be
used for JavaScript development.
2/8
22/9/2016
GetstartedwithXBOXKinect2JavaScriptdevelopment
XBOX and the Kinect are Microsoft products so its 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 couldnt get it working possibly due to this issue.
From my experience after weeks and weeks of researching, testing and talking to at
Back
Blog Resources
least a dozen developers, it seems that the most reliable way of working with the
Kinect cross-platform, and with JavaScript most importantly, is this: Connect the
Kinect to a Windows machine running Node.js and the Kinect2 library. This Node.js
application on the Windows machine can receive the sensor data with no issues from
the ocial SDK. From there we can publish and stream the data through web
sockets to any other machine: Windows, Mac or Linux. So essentially we are only
using the Windows machine as a low level server that reads pure data from the
Kinect and publishes it for other computers to use and interpret.
Installation
http://www.webondevices.com/getstartedwithxboxkinect2javascriptdevelopment/
3/8
22/9/2016
GetstartedwithXBOXKinect2JavaScriptdevelopment
Lets setup the Windows machine rst, 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
ocial Kinect 2 SDK that can only be installed to Windows machines. Go ahead, and
install it rst from this page. You might want to restart your machine after this step.
Please
Windows
8 or
Backalso note that in order to install the SDK you will need a 64bitBlog
Resources
higher.
Download
FREE installed
Ebook: Introduction
to JavaScript
Next, you
need Node.js
in the Windows
commandElectronics
line. The ocial
Windows Installer can be downloaded from nodejs.org. If the installation was
successful entering nodev 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: npminstallgnode
gyp .
If that wasnt 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 npminstallkinect2 and the library will be installed to your
machine
varKinect2=require('kinect2');
varkinect=newKinect2();
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:
if(kinect.open()){
console.log("Kinectopened!");
}
http://www.webondevices.com/getstartedwithxboxkinect2javascriptdevelopment/
4/8
22/9/2016
GetstartedwithXBOXKinect2JavaScriptdevelopment
Inside this if condition we can now add an asynchronous event listener that waits for
the skeleton data to arrive:
kinect.on('bodyFrame',function(bodyFrame){
for(vari=0;i<bodyFrame.bodies.length;i++){
Back
Blog Resources
if(bodyFrame.bodies[i].tracked){
console.log(bodyFrame.bodies[i]);
Download FREE Ebook: Introduction to JavaScript Electronics
}
}
});
//requestbodyframes
kinect.openBodyReader();
//closethekinectafter1minute
setTimeout(function(){
kinect.close();
console.log("KinectClosed");
},60000);
Running this js le from the project folder with nodeoutput.js will result in
outputting the pure sensor data in a JSON format.
http://www.webondevices.com/getstartedwithxboxkinect2javascriptdevelopment/
5/8
22/9/2016
GetstartedwithXBOXKinect2JavaScriptdevelopment
varKinect2=require('kinect2');
Back
Blog Resources
varkinect=newKinect2();
Download FREE Ebook: Introduction to JavaScript Electronics
if(kinect.open()){
console.log("KinectOpened");
//listenforbodyframes
kinect.on('bodyFrame',function(bodyFrame){
for(vari=0;i<bodyFrame.bodies.length;i++){
if(bodyFrame.bodies[i].tracked){
console.log(bodyFrame.bodies[i]);
}
}
});
//requestbodyframes
kinect.openBodyReader();
//closethekinectafter5seconds
setTimeout(function(){
kinect.close();
console.log("KinectClosed");
},60000);
}
Now you have the Kinect 2 skeleton data available in Node.js and JavaScript!
Next week Im 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
- Create a JavaScript web socket server on the Windows machine and stream the
skeleton data for browsers running any operating system on any machine
- Connect to the web socket server from Chrome on a Macintosh and visualise the
skeleton data with HTML and CSS
http://www.webondevices.com/getstartedwithxboxkinect2javascriptdevelopment/
6/8
22/9/2016
GetstartedwithXBOXKinect2JavaScriptdevelopment
- De ne 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.
Back
Back to all
Blog Resources
Leave a Reply
You must be logged in to post a comment.
Free Ebook
Step up your web developer career and learn hardware prototyping.
This ebook will get you started with JavaScript Arduino electronics development in a
couple of hours.
Email address
Web on Devices
Electronics Hacking with JavaScript and other Web Technologies
http://www.webondevices.com/getstartedwithxboxkinect2javascriptdevelopment/
7/8
22/9/2016
GetstartedwithXBOXKinect2JavaScriptdevelopment
Back
Blog Resources
Mate Marschalko
Front-end Web Developer, Creative Technologist and Maker. Builds Internet connected devices for the Internet of
Things.
http://www.webondevices.com/getstartedwithxboxkinect2javascriptdevelopment/
8/8