Kinect on Ubuntu with OpenNI
UPDATED May 1 2012 for the latest versions of everything!
I’ve spent all this morning trying to talk to the Microsoft Kinect using OpenNI. As it turns out, the process is not exceptionally difficult, it’s just there doesn’t seem to be any up to date documentation on getting it all working. So, this post should fill the void. I describe how to get access to the Kinect working using Ubuntu 11.04, OpenNI, and NITE.To talk to the Kinect, there are two basic parts: OpenNI itself, and a Sensor module that is actually responsible for communicating with the hardware. Then, if you need it, there is NITE, which is another module for OpenNI that does skeletal tracking, gestures, and stuff. Depending on how you plan on using the data from the Kinect, you may not need NITE at all.
Step 1: Prerequisites
We need to install a bunch of packages for all this to work. Thankfully, the readme file included with OpenNI lists all these. However, to make life easier, this is (as of writing) what you need to install, in addition to all the development packages you (hopefully) already have.
sudo apt-get install git build-essential python libusb-1.0-0-dev freeglut3-dev
There are also some optional packages that you can install, depending on whether you want documentation, Mono bindings, etc. Note that on earlier versions the install failed if you didn’t have doxygen installed, even though it is listed as optional.
sudo apt-get install doxygen graphviz mono-complete
Step 2: OpenNI
OpenNI is a framework for working with what they are calling natural interaction devices.Anyway, this is how it is installed:
Check out from Git
OpenNI is hosted on Github, so checking it out is simple:
git clone https://github.com/OpenNI/OpenNI.git
From there, change into the Platform/Linux-x86/CreateRedist directory, and run the RedistMaker script. Note that even though the directory is named x86, this same directory builds 64 bit versions just fine. So, don’t fret if you’re on 64bit Linux.
cd OpenNI/Platform/Linux/CreateRedist chmod +x RedistMaker ./RedistMaker
The RedistMaker script will compile everything for you. You then need to change into the Redist directory and run the install script to install the software on your system.
cd ../Redist/OpenNI-Bin-Dev-Linux-[xxx] (where [xxx] is your architecture and this particular OpenNI release) sudo ./install.sh
Step 3: Kinect Sensor Module
OpenNI doesn’t actually provide anything for talking to the hardware, it is more just a framework for working with different sensors and devices. You need to install a Sensor module for actually doing the hardware interfacing. Think of an OpenNI sensor module as a device driver for the hardware. You’ll also note on the OpenNI website that they have a Sensor module that you can download. Don’t do this though, because that sensor module doesn’t talk to the Kinect. I love how well documented all this is, don’t you?
The sensor module you want is also on GitHub, but from a different user. So, we can check out the code. We also need to get the kinect branch, not master.
git clone https://github.com/avin2/SensorKinect cd SensorKinect
The install process for the sensor is pretty much the same as for OpenNI itself:
cd Platform/Linux/CreateRedist chmod +x RedistMaker sudo ./RedistMaker cd ../Redist/Sensor-Bin-Linux-[xxx] (where [xxx] is your architecture and this particular OpenNI release) sudo chmod +x install.sh sudo ./install.sh
On Ubuntu, regular users are only given read permission to unknown USB devices. The install script puts in some udev rules to fix this, but if you find that none of the samples work unless you run them as root, try unplugging and plugging the Kinect back in again, to make the new rules apply.
Step 4: Test the OpenNI Samples
At this point, you have enough installed to get data from the Kinect. The easiest way to verify this is to run one of the OpenNI samples.
cd OpenNI/Platform/Linux-x86/Bin/Release ./Sample-NiSimpleViewer
You should see a yellow-black depth image. At this point, you’re left with (optionally) installing the higher level NITE module.
Step 5: Install NITE (optional)
Firstly, you need to obtain NITE. Go to the following link, select OpenNI compliant Middleware Binaries.
Download either the 32 or 64 bit version, depending on your platform. As of writing they only have versions for Ubuntu 10.10, but these seem to work fine with 11.04 as well.
Extract the archive, and run the installer:
At some point, you may be asked for a license key. A working license key can be found just about anywhere on the Internet. I don’t think PrimeSense care, or maybe this is a non-commercial license or something. But whatever, just copy that license into the console, including the equals sign at the end, and NITE will install just fine.
After following these steps, you will be able to write programs that use the Microsoft Kinect through OpenNI and NITE middleware. I hope this helps someone, because I spent a lot of time screwing around this morning trying to get it all to work. Like I said, the process is pretty straight forward, it just hasn’t been written down in one place (or I suck at google).