File Exchange

image thumbnail

Matlab Wrapper for OpenNI 2.2

version 1.1.0.0 (4.94 KB) by Camillo Taylor
A very simple wrapper that provides an interface to RGBD cameras through OpenNI v2.2

1 Download

Updated 14 Jun 2013

View License

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.

Installation:

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.

IMPORTANT:
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.

Usage:

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!!

Cite As

Camillo Taylor (2020). Matlab Wrapper for OpenNI 2.2 (https://www.mathworks.com/matlabcentral/fileexchange/42127-matlab-wrapper-for-openni-2-2), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

Niraj Desai

Ignore my previous comment. I failed to read the advice that Ivan and Rakshit offered in 2013 and 2014, respectively. Following their advice, Camillo's program successfully compiled. Also, for anyone using the Orbbec Astra S, you need OpenNI2.3 (available at the Orbbec website) rather than OpenNI2.2. Thanks to Camillo for a very useful contribution.

Niraj Desai

Has anyone gotten this to work in Windows 10? I'm asking because I've gotten errors similar to those Davide Lascar reported last year. I'm debating with myself whether it's better to try to make Camillo's wrapper work or just to start from scratch. I'd be more inclined to do the former if somebody could report success in Windows 10.

I should add that I've been using Matlab 2016a and Visual Studio Community 2015.

Hello i need some help!!!!
i followed the instruction given by Camillo. But when i run the .m file i have the following error:

>> compile_script
Building with 'Microsoft Windows SDK 7.1 (C++)'.
Error using mex
Creating library mxNI.lib and object mxNI.exp
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniFrameRelease referenced in function "public: void
__thiscall openni::VideoFrameRef::release(void)" (?release@VideoFrameRef@openni@@QAEXXZ)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniStreamStart referenced in function "public: enum
openni::Status __thiscall openni::VideoStream::start(void)" (?start@VideoStream@openni@@QAE?AW4Status@2@XZ)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniStreamStop referenced in function "public: void
__thiscall openni::VideoStream::stop(void)" (?stop@VideoStream@openni@@QAEXXZ)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniStreamReadFrame referenced in function "public:
enum openni::Status __thiscall openni::VideoStream::readFrame(class openni::VideoFrameRef *)"
(?readFrame@VideoStream@openni@@QAE?AW4Status@2@PAVVideoFrameRef@2@@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniStreamGetProperty referenced in function "public:
enum openni::Status __thiscall openni::VideoStream::getProperty(int,void *,int *)const "
(?getProperty@VideoStream@openni@@QBE?AW4Status@2@HPAXPAH@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniStreamSetProperty referenced in function "public:
enum openni::Status __thiscall openni::VideoStream::setProperty(int,void const *,int)"
(?setProperty@VideoStream@openni@@QAE?AW4Status@2@HPBXH@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniStreamIsPropertySupported referenced in function
"public: bool __thiscall openni::VideoStream::isPropertySupported(int)const "
(?isPropertySupported@VideoStream@openni@@QBE_NH@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceGetProperty referenced in function "public:
enum openni::Status __thiscall openni::Device::getProperty(int,void *,int *)const "
(?getProperty@Device@openni@@QBE?AW4Status@2@HPAXPAH@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceSetProperty referenced in function "public:
enum openni::Status __thiscall openni::Device::setProperty(int,void const *,int)"
(?setProperty@Device@openni@@QAE?AW4Status@2@HPBXH@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceIsPropertySupported referenced in function
"public: bool __thiscall openni::Device::isPropertySupported(int)const "
(?isPropertySupported@Device@openni@@QBE_NH@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceIsCommandSupported referenced in function
"public: bool __thiscall openni::Device::isCommandSupported(int)const "
(?isCommandSupported@Device@openni@@QBE_NH@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniInitialize referenced in function "public: static
enum openni::Status __cdecl openni::OpenNI::initialize(void)" (?initialize@OpenNI@openni@@SA?AW4Status@2@XZ)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniShutdown referenced in function "public: static
void __cdecl openni::OpenNI::shutdown(void)" (?shutdown@OpenNI@openni@@SAXXZ)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniGetExtendedError referenced in function "public:
static char const * __cdecl openni::OpenNI::getExtendedError(void)" (?getExtendedError@OpenNI@openni@@SAPBDXZ)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniStreamDestroy referenced in function "public: void
__thiscall openni::VideoStream::destroy(void)" (?destroy@VideoStream@openni@@QAEXXZ)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniStreamGetSensorInfo referenced in function
"private: void __thiscall openni::VideoStream::_setHandle(struct _OniStream *)"
(?_setHandle@VideoStream@openni@@AAEXPAU_OniStream@@@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceGetSensorInfo referenced in function
"public: class openni::SensorInfo const * __thiscall openni::Device::getSensorInfo(enum openni::SensorType)"
(?getSensorInfo@Device@openni@@QAEPBVSensorInfo@2@W4SensorType@2@@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceCreateStream referenced in function "public:
enum openni::Status __thiscall openni::VideoStream::create(class openni::Device const &,enum openni::SensorType)"
(?create@VideoStream@openni@@QAE?AW4Status@2@ABVDevice@2@W4SensorType@2@@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceGetInfo referenced in function "private:
enum openni::Status __thiscall openni::Device::_setHandle(struct _OniDevice *)"
(?_setHandle@Device@openni@@AAE?AW4Status@2@PAU_OniDevice@@@Z)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceClose referenced in function "public: void
__thiscall openni::Device::close(void)" (?close@Device@openni@@QAEXXZ)
mxNI.obj : error LNK2019: unresolved external symbol __imp__oniDeviceOpen referenced in function "public: enum
openni::Status __thiscall openni::Device::open(char const *)" (?open@Device@openni@@QAE?AW4Status@2@PBD@Z)
mxNI.mexw32 : fatal error LNK1120: 21 unresolved externals

Error in compile_script (line 11)
mex(['-L' OPENNI2_REDIST],'-LOpenNI2',['-I' OPENNI2_INCLUDE],'mxNI.cpp');

I have Win10 64bit , Matlab 2015b 32bit (need the 32 version cause in my project i have to use external library that works only on matlab 32bit), microsoft 7.1 SDK.

Thank you

Sorry. Clicking the download button helped :)
/Hans

This seems like exactly what I am looking for.
But where is the file mxNI.cpp? If I need to write is myself, then it would be really great if someone could post an example to get me started.
/Hans

Awesome!!! Saved my life with this.

Hi, I'm able to capture RGB images using ASTRA S and MATLAB in 480X640 resolution mode. However, I'm unable to capture clear images when I use Fps = 30
pixelFormat = PIXEL_FORMAT_RGB888
resX = 1280
resY = 720

Can anyone kindly advise in this regard.

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

Sarah

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

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*

nevermind, i got it figured out! :)

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

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!

jetsun

It can works on Windows.

Ivan

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';

Updates

1.1.0.0

Deleted an extraneous word from the Summary field

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: Kinect Matlab