Kinect on Ubuntu with OpenNI

UPDATE October 2015: Verified working in Ubuntu 14.04 LTS and 15.04!

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 12.04 LTS, OpenNI 1.5.4, and NITE 1.5.2.

Please note that since writing this tutorial, we now have OpenNI and NITE 2.0, and PrimeSense have been bought by Apple. This tutorial does not work with versions 2 (though 1.5 works just fine), and there is talk of Apple stopping public access to 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.

[ad]

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.

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.

Step 2: OpenNI 1.5.4

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:

The first thing we will do is checkout the Unstable 1.5.4 tag. If you don’t do this, then the SensorKinect library won’t compile in Step 3. 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.

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.

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.

The install process for the sensor is pretty much the same as for OpenNI itself:

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.

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 1.5 (optional)

Firstly, you need to obtain NITE 1.5.2. Go to the following link and download NITE 1.5.2 for your platform..

http://www.openni.org/openni-sdk/openni-sdk-history-2/

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.

Conclusion

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).

[ad]

Published by

Michael Marner

My name is Michael, and this is my website. I am currently working as a Research Fellow at the University of South Australia's Wearable Computer Lab. I am also the chair of the board and an announcer at Adelaide based community radio station Three D Radio 93.7FM.

70 thoughts on “Kinect on Ubuntu with OpenNI”

  1. Hi,

    in the step 3, is that normal to have OpenNI path for installing, or we should use Sensor ?

    Nice step by step tutorial !

  2. Sorry for double post, i didn’t find editing tool.

    In the “apt-get install” part, best to add “git-core”.

  3. Excellent tutorial!!!

    In step 4 I got: Warning: USB events thread – failed to set priority. This might cause loss of data…
    Any ideas?

  4. The same thing happens to me. I don’t know what the cause is, but haven’t seen it cause any problems at runtime.

    Out of curiosity, does it still do it if you run as root? It may be a permissions thing…

  5. Hi

    Real nice documentation. However, I get a problem at step 3 during the install process for the sensor. When I run ./RedistMaker, it gives:
    make: Entering directory /home/-----/kinect/Sensor/Platform/Linux-x86/Build'
    make -C XnCore CFG=Release
    make[1]: Entering directory
    /home/—–/kinect/Sensor/Platform/Linux-x86/Build/XnCore’
    ../EngineLibMakefile:24: /usr/include/ni/CommonMakefile: No such file or directory
    make[1]: *** No rule to make target /usr/include/ni/CommonMakefile'. Stop.
    make[1]: Leaving directory
    /home/——/kinect/Sensor/Platform/Linux-x86/Build/XnCore’
    make: *** [XnCore] Error 2
    make: Leaving directory /home/------/kinect/Sensor/Platform/Linux-x86/Build'

    From a different post they had advised to provide a link from file /usr/include/ni/CommonMakefile to /usr/include/ni/CommonCppMakefile. I did this using:
    cd /usr/include/ni
    sudo ln -s CommonCppMakefile CommonMakefile
    However, after this when I try the installation(./RedistMaker) it gives this:
    .......
    .......
    ./Release/jutils.o: In function
    jcopy_sample_rows’:
    jutils.c:(.text+0x9c): undefined reference to xnOSMemCopy'
    ./Release/jutils.o: In function
    jzero_far’:
    jutils.c:(.text+0x36): undefined reference to xnOSMemSet'
    ./Release/jutils.o: In function
    jcopy_block_row’:
    jutils.c:(.text+0x50): undefined reference to xnOSMemCopy'
    collect2: ld returned 1 exit status
    make[1]: *** [../../Bin/Release/libXnFormats.so] Error 1
    make[1]: Leaving directory
    /home/——/kinect/Sensor/Platform/Linux-x86/Build/XnFormats’
    make: *** [XnFormats] Error 2
    make: Leaving directory `/home/—–/kinect/Sensor/Platform/Linux-x86/Build’

    Any ideas whats wrong?
    I tried installing the sensor modules from the OpenNI repo and continued with the remaining installation but the final release binaries did not work and kept saying ‘InitXmlfiles failed…..’
    For your info:
    OS: Linux 10.10
    Pro: intel xenon

  6. Hi!

    I’ve tried to run the tutorial but I’ve got an error in “git checkout -b kinect origin/kinect”: “fatal: something about git trying to chck out ‘origin/kinect’ commit” However, changing it to “git checkout -b kinect origin” appears to solve the problem. By the way, the line “cd Sensor” should also be changed to “cd SensorKinect”

    Cheers

  7. hi ,
    i was trying to execute few samples from NITE. But they are not working. I even tried to build them with
    ~/kinect/nite-bin-linux64-v1.4.2.3/Samples/Build make
    that gave error
    make -C ../Boxes.net -f Boxes.net.mak
    make[1]: Entering directory /home/nagraj/kinect/nite-bin-linux64-v1.4.2.3/Samples/Boxes.net'
    make[1]: Nothing to be done for
    all’.
    make[1]: Leaving directory /home/nagraj/kinect/nite-bin-linux64-v1.4.2.3/Samples/Boxes.net'
    make -C ../Players -f Players.mak
    make[1]: Entering directory
    /home/nagraj/kinect/nite-bin-linux64-v1.4.2.3/Samples/Players’
    g++ -o ../Bin/Release/Sample-Players ./Release/main.o ./Release/SceneDrawer.o ./Release/kbhit.o ./Release/signal_catch.o -L../Bin/Release -lglut -lOpenNI -lXnVNite_1_4_2
    /usr/bin/ld: skipping incompatible ../Bin/Release/libXnVNite_1_4_2.so when searching for -lXnVNite_1_4_2
    /usr/bin/ld: skipping incompatible /usr/lib/libXnVNite_1_4_2.so when searching for -lXnVNite_1_4_2
    /usr/bin/ld: cannot find -lXnVNite_1_4_2
    collect2: ld returned 1 exit status
    make[1]: *** [../Bin/Release/Sample-Players] Error 1

    can you help out

  8. Hi,

    Thank you very much for summing this all up, but I have hit a snag.

    After
    git clone https://github.com/avin2/SensorKinect
    cd SensorKinect
    cd Platform/Linux-x86/CreateRedist
    ./RedistMaker

    I receive an error stating.

    make[1]: warning: jobserver unavailable using -j1. Add `+’ to parent make rule.

    ../../../../Source/XnDeviseSesorv2/XnSensorAudioStream.cpp In member function ‘XnStatus XnSensorAudioStream::ReallocBuffer()’:
    ../../../../Source/XnDeviseSesorv2/XnSensorAudioStream.cpp:487:144 error: ‘xn0SCreateSharedMemoryex’ was not declared in this scope

    Do you have any thoughts on this matter?

  9. hi
    thanks for sharing
    i have a problem in step 3
    when i do
    ./RedistMaker

    bash: ./RedistMaker: Permission denied

    but when i do below

    sudo: ./RedistMaker

    sudo: ./RedistMaker: command not found

    why is that? should i :

    sudo apt-get install doxygen graphviz mono-complete

    ?????

    thx 4 the steps again

  10. hi agian

    i have done the installation:

    sudo apt-get install doxygen graphviz mono-complete

    but the problem still can’t be solved

  11. hi again again

    i have solved the problem of “sudo: ./RedistMaker: command not found”

    rigthclick file RedistMaker -properties-permissions

    select “Allow executing file as program”

  12. When running ./Sample-NiSimpleViewer I got following error:
    Open failed: Failed to set USB interface!

    Resolved with:
    sudo rmmod gspca_kinect

    Now it starts to work.

    Mattia

  13. Hi there,

    You have realy fill the gap in OpenNI documentation for using Kinect in Linux. It worked directly.

    Thanks for sharing the info.

  14. Hi
    I am getting an error in step 2

    chmod +x RedistMaker
    ./RedistMaker

    The error is:

    /bin/sh: 1: javac: not found
    make[1]: *** [../../../Bin/x64-Release/org.OpenNI.jar] Error 127
    make: *** [Wrappers/OpenNI.java] Error 2
    make: *** Waiting for unfinished jobs….
    ../../../../../Wrappers/OpenNI.net/NodeInfo.cs(51,43): warning CS0219: The variable `description’ is assigned but its value is never used
    failed to execute: make -j16 -C /home/dale/OpenNI/Platform/Linux/CreateRedist/../Build > /home/dale/OpenNI/Platform/Linux/CreateRedist/Output/BuildOpenNI.txt
    Building Failed!

    Is there an additional java dependancy required? I ran sudo apt-get install openjdk-7-jre. Any help would be greatly apreciated.

  15. It’s awesome tutorial.

    In step 3,

    I faced this error:

    ../../../../Source/XnDDK/XnFrameBufferManager.h:30: fatal error: XnEventT.h: No such file or directory
    compilation terminated

    Do I need to install some packages to resolve this?

    Cheers.

  16. Hi,

    Just thought I should chip in by saying that when using the avin2 repo for SensorKinect, you need to use the unstable branch of OpenNI.

    This can be done by just using

    git checkout unstable

    within the OpenNI directory.

    Cheers for the walkthrough by the way.

  17. Note that the current HEAD versions of OpenNI and SensorKinect (as at 01-JUNE-2012) are not compatible with each other – I had to roll back SensorKinect to 12-DEC-2012 in order to get it to compile. The HEAD version of SensorKinect seems to be developed against some internal version of OpenNI.

    And, for those uninitiated into the git universe, that’s:

    cd SensorKinect
    git checkout faf4994fceba82e6fbd3dad16f79e4399be0c184

  18. Hi

    i just found your tutorial after spending the whole day to bring openni, nite and
    kinectsensor to work on gentoo and ubuntu 😀

    But anyway thanks for sharing! maybe someone else finds it earlier =)

    Chriss

  19. Thanks a lot for the guide! I’m still having trouble getting past the Step 3. I get this error that a lot of other people seem to have faced as well

    make[1]: *** [x86-Release/Bayer.o] Error 1
    make[1]: Leaving directory `/home/mazin/Documents/Kinect/SensorKinect/Platform/Linux/Build/XnDeviceSensorV2′
    make: *** [XnDeviceSensorV2] Error 2

    I rolled back to an earlier version of the SensorKinect as Tom suggested and I’ve checkedout the unstable version of OpenNI as Andrew suggested. But I’m still getting this error. Any ideas why?

  20. Actually I got it, it was my bad

    I was supposed to run this command before beginning

    sudo apt-get install git-core cmake freeglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev doxygen graphviz mono-complete

  21. Thanks so much! This was a huge help.
    For me to get things to work, I had to download the unstable branch of OpenNI manually from their website (I’m not sure how to do that from Git), but all other instructions worked perfectly!

    Symptoms of this problem are that there are three or so undefined symbols in a header named something like XnDeviceSensorIO.h (probably not the correct name of the file, but close) around line 98. I got this to pop up while installing SensorKinect at the step “sudo ./RedistMaker”

    Thanks again!

  22. Thanks Tom for the hint about the incompatibility of the head branch of SensorKinect. I was finally able to compile the library without that XnEvent.h error.

  23. Hi
    i’m trying to get openni working on beagleboard_xm … i managed to compile the OpenNI , but KinectSensor gives XnEvent.h error. i tried to change HEAD version by “git checkout faf4994fceba82e6fbd3dad16f79e4399be0c184” but when i run the RedisMaker it says “Unknown machine type: armv7l”
    any suggestions ?

  24. did you succeed ?
    here what I did and it compiled, but untill now I have an issue with the depth map: the data arrives but the image does not appear.

    cd ~/kinect git clone git://github.com/avin2/SensorKinect.git
    emacs -nw ~/kinect/SensorKinect/Platform/Linux/Build/Common/Platform.Arm
    and remove -mfloat-abi=softfp

    emacs -nw ~/kinect/SensorKinect/Platform/Linux/CreateRedist/RedistMaker
    and modify
    make -j$(calc-jobs_number) -C ../Build
    into
    make -j1 -C ../Build

    cd ~/kinect/SensorKinect/Platform/Linux/CreateRedist
    ./RedistMaker

    cd ~/kinect/SensorKinect/Platform/Linux/Redist/Sensor-Bin-Linux-Arm-v5.1.2.1
    sudo ./install.sh

    hope this helps alex

  25. Hi,

    A really nice step by step tutorial, but i found some problem when i reach the step 2, when i want to install the OpenNI, i found this error:

    /bin/sh: 1: javac: not found
    make[1]: *** [../../../Bin/x64-Release/org.OpenNI.jar] Error 127
    make: *** [Wrappers/OpenNI.java] Error 2
    make: *** Waiting for unfinished jobs….
    ../../../../../Wrappers/OpenNI.net/NodeInfo.cs(51,43): warning CS0219: The variable `description’ is assigned but its value is never used
    failed to execute: make -j8 -C /home/chokhow/kinect/OpenNI/Platform/Linux/CreateRedist/../Build > /home/chokhow/kinect/OpenNI/Platform/Linux/CreateRedist/Output/BuildOpenNI.txt
    Building Failed!

    Then i go to the https://github.com/OpenNI/OpenNI.git there and check for the openNI. However in the website, they did mention that the source ‘platform’ were lost by mistake.

    What i can do now?

  26. Have you encountered a problem with your system not recognizing the Kinect as A Kinect? When I do lsusb it lists the 3 “parts” of the device but only the “Microsoft” part. Doesn’t say Motor, Audio.. Nothing really and nothing works with it. Can’t access it via openni or freenect or anything. It just doesn’t work. Says I don’t have a kinect device plugged in.

    When I run dmesg | tail this is what I get:

    [ 4169.746668] usb 2-1.1.2: new high-speed USB device number 18 using ehci_hcd
    [ 4169.774707] hub 2-1.1:1.0: unable to enumerate USB device on port 2
    [ 4170.549778] usb 2-1.1.1: new high-speed USB device number 19 using ehci_hcd
    [ 4173.618203] usb 2-1.1.2: new high-speed USB device number 20 using ehci_hcd

  27. Hi,

    Just after following the codings, I tried to test sample typing ./Sample-NiSimpleViewer..
    I got an error:

    One or more of the following nodes could not be enumerated:

    Can anybody help what is this error and what can be done please?

  28. I have one error in command “sudo ./RedistMaker” by Sensokinect return this:
    make[1]: *** [x64-Release/XnSensorDepthGenerator.o] Error 1
    make[1]: Leaving directory `/home/pcimobilis/Iniciacao/kinect/OpenNI/Platform/Linux/Redist/OpenNI-Bin-Dev-Linux-x64-v1.5.7.10/SensorKinect/Platform/Linux/Build/XnDeviceSensorV2′
    make: *** [XnDeviceSensorV2] Error 2
    make: *** Waiting for unfinished jobs….

    And not creat past /Redist

  29. Hi
    Thnk you for tutorial
    kinect blink green and I have not any error message but when i run a sample (anything), nothing appears on the screen…
    Thinkpad T3
    Ubuntu 12.04

    help…Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *