File Exchange

image thumbnail


version 1.0 (14.1 KB) by

Kinect, OpenNI wrapper, NITE PointViewer example, Hand Tracking, IR & Depth, matlab interface



View License

This zip-file provides a matlab interface for the NITE PointViewer example, with some c++ wrapper functions written for the Microfost Kinect, OpenNI and NITE library.

The work is based on Dirk-Jan Kroon's contribution(, description of modifications of related files are:

PointDrawer.h -- from NITE PointViewer example, functions to draw by glut are deleted.
mxNiCreateContext.cpp -- add session manager, flow control, point control, callbacks for session manager, code from NITE PointViewer example
mxNiDeleteContext.cpp -- unchange
mxNiDepth.cpp -- the index of pointer is updated
mxNiInfrared.cpp -- the index of pointer is updated
mxNiUpdateContext.cpp -- add update of session manager
mxNiHandPosition.cpp -- created, motivated by Dirk-Jan Kroon's work

the detail of the usage of each fucntion can be found in cooresponding .m file.

Since I use another camera which is similiar to Kinect except that it has no RGB sensor, there's no 'image' node in my xml file. you can modify it if you are interested, and make use of functions provided by Dirk-Jan Kroon.

./ExampleHand.m -- script for testing the PointViewer example.

The code is tested on:
Windows XP professional 32bit
matlab R2009a
compiler: Microsoft Visual C++ 2008 SP1
Sensor Driver

You need to firstly run compile_cpp_files.m to compile .cpp to mex files, check the OpenNI and NITE paths if there are errors.

when you successfully get all mex files, run ExampleHand.m to test.

Specifical thanks to Dirk-Jan Kroon for his code.

University of Macau, Macau SAR, China

Comments and Ratings (11)

hi! i managed to get your code working but unfortunately i get the same hand coordinates from the mxNiHandPosition as Martin.
i'm using a kinect, osx 10.7 (64bit) & matlabR2011b.
any ideas or suggestions what could be wrong?
kind regards and thank you in advance, christian


lev (view profile)

I too have the same error while compiling.. C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Link of 'mxNiCreateContext.mexw32' failed.
How to fix it?


After HONGMIN ZHU help, finally I can run the code with kinect and I have RGB and depth node only. Many thanks Zhu


Martin, Do you success to run Example hand file with kinect? I can't compile it, it seems error with mxNiCreateContext file but I still do not know how to solve it?
every time I compile the Mix files, I get this error : C:\PROGRA~2\MATLAB\R2010B\BIN\MEX.PL: Error: Link of 'mxNiCreateContext.mexw32' failed

I've tested it with 64bits. You can modify the compile_cpp_files.m as follows:

c = computer;
tis64 = strcmp('64',c(end-1:end));
catch me
tis64 = 0;

        error('OpenNI path not found, Please call the function like compile_cpp_files(''examplepath\openNI'')');
    OpenNiPathLib=[OpenNiPath 'Lib'];
if tis64
OpenNiPathLib=[OpenNiPath 'Lib64'];
OpenNiPathInclude=[OpenNiPath 'Include'];

if tis64
lib = '-lopenNI64';
lib = '-lopenNI';

for i=1:length(files)
    mex('-v',['-L' OpenNiPathLib],lib,['-I' OpenNiPathInclude],Filename);


Actually I used another alternative camera named like "Xtion pro" from prime sense, when I wrote this wapper. Now I have a kinect and plan to develop with Microsoft's SDK. There's not OpenNI and NITE installed currently in my computer so I can't tell which config file. You can check the google group for OpenNI.

Martin Dale

I just downloaded it today so I'm guessing it is the latest. I can't get it to track either of the hands. The return from mxNiHandPosition is constantly
hp = 1.0e+009 *

    4.2950 -0.0000 -0.0000 -0.0000 0 0

I'm new to working with the Kinect. What config file changes might be needed?


Hi, Martin,
  Is the MultipleHands.ONI file the lastest update? I tried the orignal PointViewer project in VS2008, only a parameter need to be changed in the configuration file for multiple hand tracking. But the result is not so robust and it seems to be very slow.
Sorry I haven't tried the wrap of multi-hand case.

Martin Dale

Hongmin, I've merged yours and Dirks programs and tried to use hand tracking with the MultipleHands.ONI file from the OpenNI downloads but it doesn't appear to detect any hands. Any idea why not?



hi, Brahim,
Sorry, I haven't encountered this error, but what version of matlab you used?
I found a similiar issue related to R2006b, and hope it's the cause of yours.

the mex compile properly (with Microsoft Visual C++ 2008 Express in C:\Program Files\Microsoft Visual Studio 9.0) but when running the HandExample script I get the following error:

'What() is:Access violation - no RTTI data!'

Any ideas how to fix this ?


MATLAB Release
MATLAB 7.8 (R2009a)

Inspired by: Kinect Matlab

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video