How to get started with Kinect for Windows on Ubuntu using OpenNI

The Kinect can be connected to a computer and used for a lot of fun projects. OpenNI is a popular library that is used by many applications and libraries to use the Kinect. You can also use the OpenNI API in your programs to access the output of the Kinect. This post describes the steps I used to get OpenNI working with the Kinect for Windows sensor on Ubuntu:

Preliminary checks

  1. This post is about the Kinect for Windows sensor. It is not about the Kinect for Xbox 360 sensor. If you don’t know which type of Kinect you are using, read about the difference between the two types of Kinect.
  2. Plug the power plug of the Kinect to a power source. Plug the USB plug of the Kinect into your computer running Ubuntu. You should see the light on the Kinect blink slowly in green color.
  3. Ensure that the Kinect has been identified by the Linux kernel. You can check this by listing all the USB devices as described in this post. Check if the 3 devices described in that post are listed with the correct product and vendor IDs.

Install unstable branch of OpenNI 1.x

By default, OpenNI does not ship with the drivers for Kinect. Also, OpenNI 2.x does not seem to work with Kinect for Windows. To use the Kinect for Windows sensor on Ubuntu, it seems that the unstable version of OpenNI 1.x should be used.

Get the unstable branch of OpenNI 1.x code:

$ git clone https://github.com/OpenNI/OpenNI.git
$ cd OpenNI/
$ git checkout -b unstable origin/unstable

Compile the OpenNI code:

$ cd Platform/Linux/CreateRedist/
$ ./RedistMaker

Install the OpenNI headers, libraries and binaries on the system:

$ cd ../Redist/
$ cd OpenNI-Bin-Dev-Linux-x64-v1.5.4.0/
$ sudo ./install.sh

You now have OpenNI installed. However, it cannot yet communicate with your Kinect for Windows sensor. To get that working, we need to install the Kinect drivers.

Install SensorKinect drivers

These are drivers that have been modified to work with OpenNI 1.x (not OpenNI 2.x) on Linux. We need to compile and install this to use the Kinect. Compilation of these drivers needs OpenNI to be installed, which is why we did that step first.

Get the code of SensorKinect:

$ git clone https://github.com/avin2/SensorKinect.git
$ cd SensorKinect/

Compile the SensorKinect driver code:

$ cd Platform/Linux/CreateRedist/
$ ./RedistMaker

Install the SensorKinect drivers:

$ cd ../Redist/
$ cd Sensor-Bin-Linux-x64-v5.1.2.1/
$ sudo ./install.sh

You now have the drivers installed on your system.

Start playing with Kinect

It is time to check out if your Kinect for Windows sensor works on Ubuntu. The OpenNI directory has some tools that can be used to start playing with your Kinect. Go to OpenNI/Platform/Linux/Bin/x64-Release and try them out. For example, the NiViewer tool displays both the RGB and depth output from your Kinect.

Tried with: Kinect for Windows, SensorKinect 5.1.0.25, OpenNI unstable 1.5.4.0, Linux 3.2.0-48-generic and Ubuntu 12.04 LTS

Difference between Kinect for Windows and Kinect for Xbox 360 on Linux

There are two variants of the Kinect hardware. The first is Kinect for Xbox 360, the Kinect sensor that was released to work with the Xbox 360. The second is Kinect for Windows, a Kinect sensor that is almost the same as Kinect for Xbox 360 and can be used with any computer. Kinect for Windows has some extra features like near mode. You can also distinguish this type by the Kinect for Windows label below the base of the unit.

Beware that on Linux a lot of the drivers, libraries and applications for Kinect work only with the Kinect for Xbox 360! Knowing which type of Kinect hardware you are using will save you a lot of trouble.

Each type of Kinect is identified differently by the Linux kernel. This can be seen in the identification that is printed when you list USB devices.

The output for Kinect for Xbox 360 is:

$ lsusb
Bus 001 Device 058: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor
Bus 001 Device 059: ID 045e:02ad Microsoft Corp. Xbox NUI Audio
Bus 001 Device 060: ID 045e:02ae Microsoft Corp. Xbox NUI Camera

Here 045e is the vendor ID and 02b0 is a product ID. Note that the Kinect is identified as 3 different products with a fully qualified product name, for example Microsoft Corp. Xbox NUI Camera.

The output for Kinect for Windows is:

$ lsusb
Bus 002 Device 011: ID 045e:02c2 Microsoft Corp.
Bus 002 Device 013: ID 045e:02be Microsoft Corp.
Bus 002 Device 014: ID 045e:02bf Microsoft Corp.

Notice how the product IDs are different from Xbox 360 and how the device name is just listed as Microsoft Corp. without any further description.

Tried with: Kinect for Windows, Linux 3.2.0-48-generic and Ubuntu 12.04 LTS

How to get started with Kinect for Windows on Windows

The Kinect for Windows sensor can be programmed, controlled and used in your code easily on Windows. Getting started is really easy.

  1. The Kinect has a USB input and power input. Plug the power input to a power socket and the USB input to a USB port on your computer. The light on the Kinect should turn on to green color. If the light does not turn on or it is red in color, then something is badly wrong at the hardware level. The green light on the Kinect will blink slowly. This is all right since it indicates that the Kinect is not currently controlled by any computer. Though Windows has detected the Kinect device on its USB port, it cannot yet control it because it does not have the necessary Kinect drivers.
  2. Go to the Kinect for Windows webpage, download the Kinect for Windows SDK and install it. This provides the Kinect drivers and a library that provides basic access to the output of Kinect. Once this installation is complete, Windows should be able to detect your Kinect and its light should glow green steadily. That is, it should have stopped blinking now.
  3. It is highly recommended to install the Kinect for Windows Developer Toolkit, since this provides higher level libraries, API, sample codes and tools. This can be downloaded from the Kinect for Windows webpage too and installed.
  4. After installation, it is time to take the Kinect out for a spin! Open C:\Program Files\Microsoft SDKs\Kinect\Developer Toolkit v1.7.0\Samples\bin. You can see that it is full of binaries of various Kinect programs. Try them out! For example, the Kinect Explorer tool should show you the color, depth and audio output of your Kinect.
  5. To get started on programming the Kinect, head over to C:\Program Files\Microsoft SDKs\Kinect\Developer Toolkit v1.7.0\Samples. You can see the C++, C# and VB source code of the sample programs here. This should get you started on hacking your Kinect.

Tried with: Kinect for Windows, Kinect for Windows SDK 1.7, Kinect for Windows Developer Toolkit 1.7.0 and Windows 7 x64