Code covered by the BSD License  

Highlights from
Kinect Microsoft SDK

4.27273

4.3 | 11 ratings Rate this file 44 Downloads (last 30 days) File Size: 18.2 KB File ID: #33035
image thumbnail

Kinect Microsoft SDK

by

 

27 Sep 2011 (Updated )

Video, Audio, Depth Stream and Skeleton tracking

| Watch this File

File Information
Description

This zip-file contains c++ wrapper functions for the Microsoft Kinect, Microsoft SDK Beta2 library.

To compile the code to mex-files use the Microsoft Visual Studio‚Äč (Express), and install Beta2 library:
- KinectSDK32.msi
or
- KinectSDK64.msi

Execute compile_cpp_files. Now the mex-files are ready to use.

- Example : Will show the depth and image stream from the Kinect.

- ExampleSkeleton : Will show Skeleton tracking

- ExampleMicrophone: Will audio recording

See also, the OpenNI library wrapper functions (Which is almost bug free and has more functionality):
http://www.mathworks.com/matlabcentral/fileexchange/30242-kinect-matlab

Note this is "version 0b"!, and contains the following bug:
There is a problem with stopping the Kinect Process. You have to manually kill Matlab.exe in the taskmanager to stop the process.
If some one has a solution please let me know...

Acknowledgements

This file inspired Simulink For Pcv (Point Cloud Viewer) and Simulink Support For Kinect.

MATLAB release MATLAB 7.13 (R2011b)
Other requirements Visual Studio Compiler (Express)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (33)
06 Aug 2014 Raffaele

i've worked on win 7 32bit matlab 2013b 32bit

06 Aug 2014 Raffaele

All works fine but..
there seem to be a bug in
"mxMSDeleteContext".
This function do not release kinect and if I call later "clear all" command, matlab crashes.
please keep me informed if you resolve this issue
thank you

31 Oct 2013 Sanjay Saini

Can anyone give solution of my problem i am running this code with MATLAB 2013b in 64bit. I have install KinectSDK64.msi properly in my system while i am executing compile_cpp_files it showing error like: Error: File: compile_cpp_files.m Line: 1 Column: 28
Unexpected MATLAB expression.

My Path is ('C:\Program Files (x86)\Microsoft Research KinectSDK\')

04 Feb 2013 Adam

Hi,
I am running Kinect SDK Beta 2 with an xbox Kinect, Visual Studio 2010 and Matlab R2012b. I was getting some errors in mxMSCreateContext.cpp but fixed by including lib and inc files in same directory.

Now I am getting this:
mxMSDepth.cpp
mxMSDepth.cpp(36) : error C2065: 'INuiFrameTexture' : undeclared identifier
mxMSDepth.cpp(36) : error C2065: 'pTexture' : undeclared identifier
mxMSDepth.cpp(37) : error C2065: 'NUI_LOCKED_RECT' : undeclared identifier
mxMSDepth.cpp(37) : error C2146: syntax error : missing ';' before identifier 'LockedRect'
mxMSDepth.cpp(37) : error C2065: 'LockedRect' : undeclared identifier
mxMSDepth.cpp(38) : error C2065: 'pTexture' : undeclared identifier
mxMSDepth.cpp(38) : error C2227: left of '->LockRect' must point to class/struct/union/generic type
type is ''unknown-type''
mxMSDepth.cpp(38) : error C2065: 'LockedRect' : undeclared identifier
mxMSDepth.cpp(39) : error C2065: 'LockedRect' : undeclared identifier
mxMSDepth.cpp(39) : error C2228: left of '.Pitch' must have class/struct/union
type is ''unknown-type''
mxMSDepth.cpp(40) : error C2065: 'LockedRect' : undeclared identifier
mxMSDepth.cpp(40) : error C2228: left of '.pBits' must have class/struct/union
type is ''unknown-type''

C:\PROGRA~1\MATLAB\R2012B\BIN\MEX.PL: Error: Compile of 'mxMSDepth.cpp' failed.

31 Jul 2012 Steven Cadavid

nuiCapture can export Kinect data to Matlab

31 Jul 2012 Steven Cadavid  
02 Jul 2012 Watcharapong Chuesa-ard

I have a problem please help me, I using Matlab 2012a Windows7 x64 compile and test program to found

Invalid MEX-file 'C:\MATLAB\Kinect_Microsoft_version0c\Mex\mxMSCreateContext.mexw64': The
specified module could not be found.

Error in Example (line 5)
KinectHandles = mxMSCreateContext([2 1]);

thanks

23 May 2012 kinect

I found that do the follow change will solve the kinect hang issue:
%if(~exist('KinectHandles','var'))
KinectHandles=mxMSCreateContext([2 1]);
%end

09 May 2012 Pankaj

Huanzhong, it would be helpful if you could explain the function call changes you made to reflect newest library.
thanks

25 Apr 2012 Rod dockter

Huanzhong, could you elaborate on the changes that need to be made to the cpp files? I have a set up identical to yours.

24 Apr 2012 Huanzhong

I have made it work in Windows 7 machine with Matlab 2010a or later using 2010 c++ compiler (I only did the color, depth, and skeleton, not the audio). This is using the newest kinect sdk. Besides pointing to the correct sdk path in the compile_cpp_files.m file, you need to update all the function calls in all the .cpp files to reflect the newest library. Also, I have noticed a slight problem in the mxMSSkeleton.cpp program where the following 2 lines:

Pos[j+r+Jdimsc[0]*4] = (double) ( fx * depthwidth + 0.5f );
Pos[j+r+Jdimsc[0]*5] = (double) ( fy * depthheight + 0.5f );

should actually be:
Pos[j+r+Jdimsc[0]*4] = (double) ( fx * depthwidth)/320.0;
Pos[j+r+Jdimsc[0]*5] = (double) ( fy * depthheight)/240.0;

in order for the skeleton to show up correctly in Matlab figures assuming you have called the create context program with [2 1] parameter.

As far as stopping Kinect and restarting it, I also have encountered trouble. One thing that might help would be to clear your workspace after mxMSDeleteContext was called so the KinectHandles don't exist anymore. And maybe give a little bit time for Kinect to shutdown. Then run a new one, that works sometimes. However, still not stable.

If you need the working codes, let me know. Maybe I can email you.

And thank you Dirk-Jan Kroon very much for all your codes.

16 Apr 2012 nosyan

Thank you for good codes.

I have a problem to stop or restart the Kinect.
I've changed this code for new Kinect for Windows SDK.
In this code, after I restarted the Kinect process, MATLAB freezed.

mxMSCreateContext -> mxMSDeleteContext -> mxMSCreateContext (Freeze!).

I guess that mxMSDeleteContext has a bug.
Do somebody know about it?

05 Apr 2012 Isacc

Hi...
I have a problem to stop the Kinect process. In the file "Example.m" at the end lines says that with "mxMSDeleteContext(KinectHandles" you can stop the process. But I don't know how do it. Please, somebody can help me? or give me an example?.

30 Mar 2012 Jeff

Petter, additional clearification on the modification required to make this work with the v1.0 Kinect SDK would be greatly appriciated. Thanks.

29 Mar 2012 Alexander Wallar

Some great code. Does it work on MATLAB 2010a?

12 Mar 2012 Raphael

Petter, which SDK did you use? Can you detail the changes required in the source files?

12 Mar 2012 Petter

Since the SDK changed, the source files have to be modified. But it seems to be working well.

Also, the stopping problem is annoying.

11 Mar 2012 Raphael

I get the following error (with Matlab R2011b and Kinect SDK64)
mxMSCreateContext.cpp

Warning: MEX could not find the library "MSRKinectNUI" specified with -l option.
MEX looked for a file with one of the names:
MSRKinectNUI.lib
libMSRKinectNUI.lib
MEX looked for the library in the following directories:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64
C:\Program Files\Microsoft SDKs\Windows\v7.1\lib\x64
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB
C:\ProgramFiles\MATLAB\R2011b\extern\lib\win64
C:\ProgramFiles\MATLAB\R2011b\extern\lib\win64\microsoft
C:\Program Files (x86)\Microsoft Research KinectSDK\\lib\amd64

Contents of C:\Users\rafi\AppData\Local\Temp\mex_JN1ss6\mex_tmp.rsp:
C:\Users\rafi\AppData\Local\Temp\mex_JN1ss6\mxMSCreateContext.obj


--> link /out:"mxMSCreateContext.mexw64" /dll /export:mexFunction /LIBPATH:"C:\ProgramFiles\MATLAB\R2011b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\rafi\AppData\Local\Temp\mex_JN1ss6\templib.x" /MAP:"mxMSCreateContext.mexw64.map" @C:\Users\rafi\AppData\Local\Temp\mex_JN1ss6\mex_tmp.rsp

Creating library C:\Users\rafi\AppData\Local\Temp\mex_JN1ss6\templib.x and object C:\Users\rafi\AppData\Local\Temp\mex_JN1ss6\templib.exp
mxMSCreateContext.obj : error LNK2019: unresolved external symbol __imp_MSR_NuiCreateInstanceByIndex referenced in function mexFunction
mxMSCreateContext.mexw64 : fatal error LNK1120: 1 unresolved externals

C:\PROGRA~4\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'mxMSCreateContext.mexw64' failed.

Error using mex (line 206)
Unable to complete successfully.

Error in compile_cpp_files (line 47)
mex('-v',['-L' MicrosoftSDKPathLib],'-lMSRKinectNUI',['-I' MicrosoftSDKPathInclude],Filename);

Thanks

07 Mar 2012 Tharindu

Hi,
Can you please tell me how to generate real world coordinates from this system?

07 Mar 2012 upn

??? Error using ==> mex at 222
Unable to complete successfully.

Error in ==> compile_cpp_files at 45
mex('-v',['-L'
MicrosoftSDKPathLib],'-lMSRKinectNUI','-lMsdmo','-ldmoguids','-luuid','-lamstrmid','-lavrt',['-I'
MicrosoftSDKPathInclude],Filename); with SDK 1.0.3.19 have solution please

06 Mar 2012 Raphael

This version does not seem to work with the Kinect SDK 1.0.3.190. I was able to find a first problem due to the new name of the environment varable: KINECTSDK10_DIR. However I still get an error message when running compile_cpp: mxMSAudioClose.cpp(24) : fatal error C1083: Cannot open include file: 'MSRKinectAudio.h': No such file or directory.
If no fix is available, can anyone provide the "old" Kinect SDK with which this works? Thanks

05 Mar 2012 Tharindu

Can anyone tell how to control tilt angle of the kinect camera

19 Feb 2012 Tharindu  
06 Feb 2012 Tim

Anyone tested yet with the new version 1.0.3 SDK released 1 February 2012 ?

22 Dec 2011 Muhammad Amir

??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> compile_cpp_files at 47
mex('-v',['-L' MicrosoftSDKPathLib],'-lMSRKinectNUI',['-I' MicrosoftSDKPathInclude],Filename);

This is error I get during compile. How to solve this??

30 Nov 2011 Jnk

Nice. I would recomend to support more than one Kinect device. It is trivial to do it, just replace call to :
hr = MSR_NuiCreateInstanceByIndex((int)0, &m_pNuiInstance);

to a different number, which could be passed as a paramter of mxMSCreateContext function.

15 Nov 2011 Itay

Great work!
Would it be possible to add acquisition of the 4 voice channels, instead of just 1?

14 Nov 2011 Chi

This works great, but only with the default [imageres depthres] values in line 5 of the Example.m file. Any other value (say [2 2] instead of the default [2 1]) makes the corresponding initialization fail.

That is, I'd like to get 640x480 depth data (and reduce the video stream to 320x240 if bandwidth becomes an issue). But it gives me a 'Depth Sensor Initialization Failed' error (Line 105 of mxMSCreateContext.cpp). Any ideas how to fix this?

11 Nov 2011 Tim

New version 0c works nicely too. Beta2 Kinect SDK now has native 64bit but my Visual Studio C++ Express is 32bit only. But I installed the 64bit SDK under Win7 Pro 64bit and the code compiled and ran OK again under 32bit Matlab. Hopefully MS will fix the thread lock bug eventually.

24 Oct 2011 Dirk-Jan Kroon

*Tim

The x,y coordinates are aligned with the depth image, which is twice as small as the video-stream. Thus this code : x=(Pos(1:20,5)-0.5)*2; transfers the coordinates from depth to photo image.
But this is only true if the depth image and photo image are aligned, and I don't know if that is always true.

24 Oct 2011 Tim

Great code.
I have the same question ... what is the basis of adjusting the XY coords before plotting them over the video ?:
x=(Pos(1:20,5)-0.5)*2;
y=(Pos(1:20,6)-0.5)*2;

13 Oct 2011 lalit  
13 Oct 2011 lalit

This version worked smooth on 64 bit Windows with 32 bit Matlab. Great job!
Though within the code I would like to know the logic behind adjusting the x,y co-ordinates.

Updates
28 Sep 2011

Added Audio. Cleaned c-code and comments.

08 Nov 2011

Support Beta2 SDK

Contact us