Using Kinect + libfreenect on Modern Linux

Here’s how I got libfreenect working on my Ubuntu 12.04 machine, running Linux kernel 3.2.   Generally, I like libfreenect because it’s pretty small and simple, about 8MB fully installed, and gives you a live depth image without much hassle.  The only thing it doesn’t do is human skeleton recognition; for that you need the much bigger and more complicated OpenNI library (howto here).

Step 0.) Install the needed software:
sudo apt-get install freeglut3-dev libxmu-dev libxi-dev build-essential cmake usbutils libusb-1.0-0-dev git-core
git clone git://github.com/OpenKinect/libfreenect.git
cd libfreenect
cmake CMakeLists.txt
make
sudo make install

Step 1.) Plug in the Kinect, both into the wall and into your USB port. Both the front LED, and power adapter plug LED, should be green (sometimes you need to plug and unplug several times for this). lsusb should show the device is connected:
lsusb
… lots of other devices …
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

Step 2.) Run the libfreenect “glview” example code:
cd libfreenect/bin
./glview
Press “f” to cycle through the video formats: lo res color, hi res color, and infrared. The IR cam is very interesting!

The source code for this example is in libfreenect/examples/glview.c.  It’s a decent place to start for your own more complex depth recognition programs: equations to convert depth to 3D points here!

———— Debugging Kinect connection ——————-

Number of devices found: 1
Could not open motor: -3
Could not open device
-> Permissions problem.
Temporary fix:
sudo chmod 777 /dev/bus/usb/001/*

Permanent fix:
sudo nano /etc/udev/rules.d/66-kinect.rules

Add this text to the file:
 # ATTR{product}=="Xbox NUI Motor"
 SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02b0", MODE="0666"
 # ATTR{product}=="Xbox NUI Audio"
 SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02ad", MODE="0666"
 # ATTR{product}=="Xbox NUI Camera"
 SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02ae", MODE="0666"

sudo /etc/init.d/udev restart
—————–
Number of devices found: 1
Could not claim interface on camera: -6
Could not open device
-> The problem: modern kernels have a video driver for Kinect.
Temporary fix:
sudo modprobe -r gspca_kinect

Permanent fix:
sudo nano /etc/modprobe.d/blacklist.conf
Add this line anywhere:
blacklist gspca_kinect
——————-
if lsusb only shows the motor, not audio or the camera:
Bus 001 Device 036: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor

This MEANS THE KINECT IS NOT POWERED via the 12V line!

Front green light blinking: Kinect is plugged into USB.
AC plug cable green light: 12V power is connected.

Solution: plug in the power cable!  If it is plugged in, unplug and replug it.

 

5 thoughts on “Using Kinect + libfreenect on Modern Linux”

  1. I installed openkinect and libfreekinect for kinect v1 (Xbox 360) and it worked fully with the glview tests and applications (cheese) until I rebooted the machine (full power off).

    The following day, only the libfree-glview command will work (can cycle using f). Cheese: device not not found (root or not).

    lsbusb lists the kinect (all aspects) at /dev/bus/usb/01/018

    I have tried to manually set cheese to use this location with no success. The location is set to chmod 777 for the entire location above.

    I’m running Ubuntu 15.04.

    Any advice on why the applications except for freekinect-glview can’t use the kinect after the first night?

    1. cheese is going to be reading from /dev/video1, not /dev/bus/usb. I suspect it stopped working because part of the standard install process is to blacklist the kernel’s gspca_kinect driver (sudo nano /etc/modprobe.d/blacklist.conf). Last time I checked, the kernel driver didn’t share well with libfreenect, but the latest I’m running is 14.04, not 15.04.

  2. I do have the modprobe.d/blacklist.conf in effect as (openkinect documentation):

    $ sudo modprobe -r gspca_kinect
    $ sudo modprobe -r gspca_main
    $ echo “blacklist gspca_kinect” |sudo tee -a /etc/modprobe.d/blacklist.conf

    I applied this many, many times in my troubleshooting after working Day #1.

    Same result on upgrade to kernel 15.10. everything works except applications other than glview.

    Tried libfreenect install on other machine; gliview ok, but this time other applications couldn’t find the kinect even on first start. Perhaps its just too out-of-date unstable.

    Does anyone believe a symbolic link from /dev/video1 to /dev/bus/usb/01/018 somehow help?

    1. That blacklist entry is intentionally designed to stop cheese (/dev/video1) from working, to allow libfreenect (/dev/bus/usb/…) to work.

      /dev/video1 is a totally different device than the /dev/bus/usb stuff, so I would not expect any kind of softlink trick to work.

      If you want /dev/video1, remove the blacklist for gspca.

  3. SOLVED. the problem is NOT libfreenect, the problem is with /dev/video0! Freenect-glview worked fine, lsusb shows kinect id as /bus/usb/01/013. The gspca_kinect driver must be called manually after the system boots to create /dev/video0! the blacklisted entry has nothing to do with it (i removed it). The command required is:

    $ sudo modprobe gspca_kinect

    This command will create video0 in /dev/ which is automatically seen by cheese, VLC, Audacity; all video so far tested works as sound is there, even recognized by firefox as a mic source.

    This forum helped: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/255678/comments #23

    Added a startup command to always run on boot; working on Ubuntu 15.10, kernel 4.2.0-18-generic, running MATE 1.10.2.

    Thanks Orion for your patience and taking the time to answer my previous questions.

Leave a Reply to Chris Cancel reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>