Kinect to Matlab on OSX and linux via mex

Hi Folks,

I wrote a little demo code for getting output from the kinect into matlab on OSX and linux using a custom mex file to interface with the OpenKinect libfreenect library. This code and instructions are a quick proof of concept that I put together as part of preparing to use the kinect for a computer vision class I am teaching next semester. The code is modified from example code in the OpenKinect project. Please let me know if this is helpful and make suggestions!

good luck,

(See end for linux (ubuntu) directions)

[note libfreenect is the directory where libfreenect was installed]

First need get the libraries ( in libfreentect/lib) and header files (in libfreentect/include) from the OpenKinect project

I did this by following the "manual build under osx" instructions for the OpenKinect project here:

Those instructions include how to obtain the correct usb driver.

You should be able to check that the OpenKinect driver is working properly by running the glviewer example application


(if you followed the manual build instructions above) and seeing output from the kinect.

then download the source for the demo matlab interface code here

unpack it, and go into the directory created

IMPORTANT: edit the paths in the mex command at the beginning of test.m

Make sure that the paths for


are correct.

Connect your kinect and run test.m from the matlab command prompt.

% first call initializes the kinect interfaces and starts a thread that reads from the kinect kinect_mex();

kinect_mex(1,1); will show the available commands, test.m also demos all the commands

kinect_mex('q'); will stop the thread reading from the kinect driver (it is good to do this before quiting matlab)
For linux you need to get libfreenect setup, then very similar compiliation steps from matlab with the library names/paths modified as necessary. Here is an ubuntu (10.10) example from Charless Fowlkes:

sudo apt-add-repository ppa:arne-alamut/freenect
sudo apt-get update
sudo apt-get install freenect

mex -I/usr/include /usr/lib/ /usr/lib/