4.16667

4.2 | 6 ratings Rate this file 96 Downloads (last 30 days) File Size: 18.24 KB File ID: #33035
image thumbnail

Kinect Microsoft SDK

by Dirk-Jan Kroon

 

27 Sep 2011 (Updated 08 Nov 2011)

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 submission has inspired the following:
Simulink for Natural Interaction Device (NID)
MATLAB release MATLAB 7.13 (2011b)
Other requirements Visual Studio Compiler (Express)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (25)
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.

13 Oct 2011 lalit  
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;

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.

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.

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?

15 Nov 2011 Itay

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

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.

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

06 Feb 2012 Tim

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

19 Feb 2012 Tharindu  
05 Mar 2012 Tharindu

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

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

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

07 Mar 2012 Tharindu

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

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

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.

12 Mar 2012 Raphael

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

29 Mar 2012 Alexander Wallar

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

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.

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?.

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?

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.

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.

09 May 2012 Pankaj

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

Please login to add a comment or rating.
Updates
28 Sep 2011

Added Audio. Cleaned c-code and comments.

08 Nov 2011

Support Beta2 SDK

Tag Activity for this File
Tag Applied By Date/Time
microsoft sdk Dirk-Jan Kroon 27 Sep 2011 15:01:29
2d Dirk-Jan Kroon 27 Sep 2011 15:01:29
3d Dirk-Jan Kroon 27 Sep 2011 15:01:29
depth Dirk-Jan Kroon 27 Sep 2011 15:01:29
depth image Dirk-Jan Kroon 27 Sep 2011 15:01:29
image processing Dirk-Jan Kroon 27 Sep 2011 15:01:29
kinect Dirk-Jan Kroon 27 Sep 2011 15:01:29
mex Dirk-Jan Kroon 27 Sep 2011 15:01:29
microsoft Dirk-Jan Kroon 27 Sep 2011 15:01:29
photo Dirk-Jan Kroon 27 Sep 2011 15:01:29
prime sense Dirk-Jan Kroon 27 Sep 2011 15:01:29
reconstruction Dirk-Jan Kroon 27 Sep 2011 15:01:29
skeleton Dirk-Jan Kroon 27 Sep 2011 15:01:29
wrapper Dirk-Jan Kroon 27 Sep 2011 15:01:29

Contact us at files@mathworks.com