Code covered by the BSD License  

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

» Watch video

Highlights from
Matlab Wrapper for OpenNI 2.2

5.0 | 3 ratings Rate this file 27 Downloads (last 30 days) File Size: 4.94 KB File ID: #42127 Version: 1.1

Matlab Wrapper for OpenNI 2.2



07 Jun 2013 (Updated )

A very simple wrapper that provides an interface to RGBD cameras through OpenNI v2.2

| Watch this File

File Information

This submission was motivated by the Kinect Matlab submission that provided an interface to OpenNI version 1.5. There was a significant reworking of the interface in OpenNI v2.2 that necessitated a bit of a rethink. The current interface is a single mex routine that acts as a 'switchyard'. You indicate which operation you want to perform on the device via the first argument which should be an integer.


You need to install OpenNI 2.2 first before you build this mex function.

I have provided short compilation script which shows how to build the mex application. You should edit the filename variables in this script to match your system configuration.

In order to run this mex file you need to copy the contents of the OpenNI/Redist directory to your current working directory. There may be a way to avoid this by messing with your DYLD_LIBRARY_PATH but I haven't tested this.


Once you have this built you can type mxNI to see the operations that you can perform.

Known Issues:

This code assumes that you only have one OpenNI device attached

It has only been tested on MacOSX version 10.8.3.

When you run the compilation on this system their is an annoying warning regarding a dangling pragma.

This code is functional but more bells and whistles could be added. Fortunately the structure of the code is quite simple so please feel free to make it better.

Happy Hacking!!


Kinect Matlab inspired this file.

MATLAB release MATLAB 8.0 (R2012b)
Other requirements OpenNI Version 2.2
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (8)
14 Apr 2016 Shehroz Khan

When I type mxNI(0), it gives this error
"Invalid MEX-file '/my/path/to/mxNI/mxNI.mexa64': cannot open shared object file:
No such file or directory"
Even though mxNI.mexa64 exists in the directory. Can someone help please?

Comment only
02 Feb 2016 Sarah

Sarah (view profile)

Hi, after installation I tried first to initialize by "mxNI(0)"
then I got the following error:

Couldn't open device
DeviceOpen using default: no devices found

Closing the NI device
Error using mxNI
mxNI init failed

I tried to connect with the microsoft Kinect.
What is going wrong?

If anybody knows about this problem - please help me.
Thanks in advance

Comment only
11 Feb 2015 Ana Gerós

Hi, I'm getting an erro when I write "mxNI" in the command window.

The following message appears:
Invalid MEX-file 'C:\Users\Staples\Documents\mxNI\mxNI.mexw64': Impossible to locate the specified module.

In fact, after compilation, a file named "mxNI.mexw64" was created, but apparently it can not be recongnized.

Does anyone can help me? Thanks in advance*

Comment only
25 Aug 2014 Carolyn Parcheta

nevermind, i got it figured out! :)

Comment only
21 Aug 2014 Carolyn Parcheta

Hi, i am getting an error when mxNI calls openni.h that there is a null character on 1:5 (line 1, column 5?).
The line itself is just "/*******************" and is the first part of the commented header information.

The error also says the word "book" after the location 1:5... but "book" does not appear in the code anywhere, let alone on line 5.

Does anyone know what is going on and how to get past the "warning null character" error that repeats several times before crashing the code?

Many thanks in advance

Comment only
31 Mar 2014 Rakshit Kothari

Hi, I'll start with a few things to help a user.

1. Add the location of the redist folder in 'C:\Program Files\OpenNI2\Redist' to the path variable & MATlab path via advanced setting-->system variables

2. As Ivan mentioned, change

OPENNI2_INCLUDE = 'C:\Program Files\OpenNI2\Include';

OPENNI2_REDIST = 'C:\Program Files\OpenNI2\Lib';

Congratulatory part:
Code is simple, effective and a great platform for simple hacks!

26 Nov 2013 jetsun

jetsun (view profile)

It can works on Windows.

21 Sep 2013 Ivan

Ivan (view profile)

Thanks for this. Compiled fine under Windows with Matlab2010a, MSVC 10 Express, OpenNI2.2 and Windows SDK 7.1. Had to rewrite the paths:
OPENNI2_INCLUDE = 'C:\Program Files\OpenNI2\Include';
OPENNI2_REDIST = 'C:\Program Files\OpenNI2\Lib';

14 Jun 2013 1.1

Deleted an extraneous word from the Summary field

Contact us