4.8
4.8 | 6 ratings Rate this file 17 Downloads (last 30 days) File Size: 3.69 KB File ID: #32586 Version: 1.0
image thumbnail

Kinect SDK with Matlab

by

Yu-Hsin (view profile)

 

Mex-file with pure "Kinect for Windows SDK" implementation.

| Watch this File

File Information
Description

The file includes mexfunction code calling "Kinect for Windows SDK" to receive depth data and color image from Kinect and a Matlab code to reshape the information matries. Please see the Readme.txt for usage.

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
01 Jan 2014 Ebtesam Banafa

i have matlab 2011b when i want to do mex compile the error is :

mex getimagedata.cpp -I'C:\Program Files\Microsoft SDKs\Kinect\v1.8\inc' 'C:\Program Files\Microsoft SDKs\Kinect\v1.8\lib\amd64\MSRKinectNUI.lib'

getimagedata.cpp
getimagedata.cpp(4) : fatal error C1083: Cannot open include file: 'MSR_NuiApi.h': No such file or directory

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

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

help me pilzzzzzzz

Comment only
20 Dec 2013 sths

sths (view profile)

Hi, I've the same problem as Chris Brunskill.
Had somebody the fixed getimagedata.cpp ?

13 Feb 2013 Dadhichi

Got the solution. Sorry!

13 Feb 2013 Dadhichi

Hello,
I am getting the DepMat and RgbMat as zero matrix. There is no error so, I don't know what is wrong.
Any help, suggestions..anyone.

Thank you.

Comment only
25 Oct 2012 Spigge

Spigge (view profile)

I got this nice code working with the latest SDK (1.6) following the fixes proposed by Chris. The the depth scaling however seems not to be working correctly. Any object closer than about 1 meter from the sensor will recieve zero depth. Starting at 1 meter and moving away from the sensor, the depth value starts to increase from zero with integer steps of 8. After about 30 cm, the depth value peaks at 4080 and then starts all over from zero again counting up in steps of 8 until it reaches 4080 after another 30 cm. I suspect that there is some confusion in the code between bits and bytes somwhow. How about this for a coincidence: dividing 4080 by 8 (8 bits = 1 byte) gives 510, which corresponds well with the 16 bit depht data of the Kinect sensor. So where does things go wrong in getimagedata.cpp? Please advice, I am a wizard in Matlab but a bozo in C.

Comment only
25 Jul 2012 Kyle

Kyle (view profile)

Take back my earlier message. I am running 32 bit Matlab and Visual Studio on a 64 bit system with the 64 bit SDK.

Comment only
24 Jul 2012 Kyle

Kyle (view profile)

I am running the same stuff as Chris Brunskill and believe I followed all the instructions correctly but when I try to run the program I get these error messages:
Creating library C:\Users\Kyle\AppData\Local\Temp\mex_pX365j\templib.x and object C:\Users\Kyle\AppData\Local\Temp\mex_pX365j\templib.exp
getimagedata.obj : error LNK2019: unresolved external symbol __imp__NuiImageStreamOpen@24 referenced in function "void __cdecl KinectInit(void)" (?KinectInit@@YAXXZ)
getimagedata.obj : error LNK2019: unresolved external symbol __imp__NuiInitialize@4 referenced in function "void __cdecl KinectInit(void)" (?KinectInit@@YAXXZ)
getimagedata.obj : error LNK2019: unresolved external symbol __imp__NuiShutdown@0 referenced in function "void __cdecl KinectShutdown(void)" (?KinectShutdown@@YAXXZ)
getimagedata.obj : error LNK2019: unresolved external symbol __imp__NuiImageStreamReleaseFrame@8 referenced in function "bool __cdecl Nui_GotDepthAlert(double (* const)[640])" (?Nui_GotDepthAlert@@YA_NQAY0CIA@N@Z)
getimagedata.obj : error LNK2019: unresolved external symbol __imp__NuiImageStreamGetNextFrame@12 referenced in function "bool __cdecl Nui_GotDepthAlert(double (* const)[640])" (?Nui_GotDepthAlert@@YA_NQAY0CIA@N@Z)
getimagedata.mexw32 : fatal error LNK1120: 5 unresolved externals

C:\PROGRA~2\BIN\MEX.PL: Error: Link of 'getimagedata.mexw32' failed.

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

Anybody have any suggestions?

Comment only
20 Jun 2012 Todd Alter

Nevermind, Chris Brunskill has it under control.

Comment only
19 Jun 2012 Todd Alter

Can you please update your download so that it works with the Kinect SDK v1.5?

Comment only
11 Jun 2012 Chris Brunskill

Hi all,

I had the same problems as above and have fixed it with a little tweaking.

I am using Matlab 7.12.0a (R2011a) and Visual Studio 10 on Windows 7, all in 64 bit flavours. I have the Kinect SDK v1.5.

There are two problems. Firstly, Microsoft have changed a number of the api call names which require a little tweaking in getimagedata.cpp. Secondly, mex seems a little temperamental with where it looks for the header and library files (also, mex command in the Readme is incorrect).

You can see the changes I have made at the following link, which also has the fixed getimagedata.cpp source.

http://www.diffnow.com/?report=2pxwz

(if anyone knows a better way to share this please let me know)

You will also see I have changed the header location to "NuiApi.h". You will need to edit this header and do the same for the NuiImageCamera.h, NuiSensor.h and NuiSkeleton.h.

http://www.diffnow.com/?report=mjcwg

I found this the was easiest way to force mex to find the headers after copying them from the Kinect SDK include folder (e.g C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include) to my Matlab working folder. Crude, but it does the job.

I also moved Kinect10.lib from the Kinect SDK amd64 lib folder (e.g C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64) to the MS VS lib folder (in my case C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64).

Then simply compile with mex specifying the kinect library filename

>> mex getimagedata.cpp -l'Kinect10'

and bingo. It works.

25 Apr 2012 Shayan Modiri

I have the same problem.
Could you please explain how can we use this function with the new SDK?
Thanks you

Comment only
20 Mar 2012 ipac

ipac (view profile)

Hello
Thank you for the code.
Actually, the following error is shown. How to solve this problem. Thank you.

'MSR_NuiApi.h': No such file or directory

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

Comment only
15 Mar 2012 Benjamin

I cannot get this code to compile. First, it complains "fatal error C1083: Cannot open include file: 'MSR_NuiApi.h': No such file or directory".

Then, if I change the include statement to #include <NuiApi.h>, I get the following:

getimagedata.cpp
getimagedata.cpp(42) : warning C4305: 'return' : truncation from 'int' to 'bool'
getimagedata.cpp(43) : error C2065: 'NuiImageBuffer' : undeclared identifier
getimagedata.cpp(43) : error C2065: 'pTexture' : undeclared identifier
getimagedata.cpp(44) : error C2065: 'KINECT_LOCKED_RECT' : undeclared identifier
getimagedata.cpp(44) : error C2146: syntax error : missing ';' before identifier 'LockedRect'
getimagedata.cpp(44) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(45) : error C2065: 'pTexture' : undeclared identifier
getimagedata.cpp(45) : error C2227: left of '->LockRect' must point to class/struct/union/generic type
type is ''unknown-type''
getimagedata.cpp(45) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(46) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(46) : error C2228: left of '.Pitch' must have class/struct/union
type is ''unknown-type''
getimagedata.cpp(48) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(48) : error C2228: left of '.pBits' must have class/struct/union
type is ''unknown-type''
getimagedata.cpp(78) : warning C4305: 'return' : truncation from 'int' to 'bool'
getimagedata.cpp(79) : error C2065: 'NuiImageBuffer' : undeclared identifier
getimagedata.cpp(79) : error C2065: 'pTexture' : undeclared identifier
getimagedata.cpp(80) : error C2065: 'KINECT_LOCKED_RECT' : undeclared identifier
getimagedata.cpp(80) : error C2146: syntax error : missing ';' before identifier 'LockedRect'
getimagedata.cpp(80) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(81) : error C2065: 'pTexture' : undeclared identifier
getimagedata.cpp(81) : error C2227: left of '->LockRect' must point to class/struct/union/generic type
type is ''unknown-type''
getimagedata.cpp(81) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(82) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(82) : error C2228: left of '.Pitch' must have class/struct/union
type is ''unknown-type''
getimagedata.cpp(84) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(84) : error C2228: left of '.pBits' must have class/struct/union
type is ''unknown-type''

I tried this with both the AMD and the x86 versions.

Comment only
07 Mar 2012 Narges M

I had the same problem and I fixed it today. As far as I know the problem arises from the differences in the libraries of the SDK beta and the newly released SDK.
What I did was that I changed this code using the "SkeletalViewer" example of the SDK sample browser, and I was able to get it running on matlab.
Hope this helps, let me know if you have further questions.

07 Mar 2012 Poinc

Poinc (view profile)

I got the recent SDK, MATLAB R2011a, and tried to compile according to instructions but got an error (too bad this would help me a lot!).

Command:
mex getimagedata.cpp -I'C:\Program Files\Microsoft SDKs\Kinect\v1.0\inc' 'C:\Program Files\Microsoft SDKs\Kinect\v1.0\lib\x86\Kinect10.lib'

(there's no MSRKinectNUI.lib) I got an error because it was looking for #include <MSR_NuiApi.h> but the header in the inc is <NuiApi.h>

So I changed that and it now gives me:
>> mex getimagedata.cpp -I'C:\Program Files\Microsoft SDKs\Kinect\v1.0\inc' 'C:\Program Files\Microsoft SDKs\Kinect\v1.0\lib\amd64\Kinect10.lib'
getimagedata.cpp
getimagedata.cpp(42) : warning C4305: 'return' : truncation from 'int' to 'bool'
getimagedata.cpp(43) : error C2065: 'NuiImageBuffer' : undeclared identifier
getimagedata.cpp(43) : error C2065: 'pTexture' : undeclared identifier
getimagedata.cpp(44) : error C2065: 'KINECT_LOCKED_RECT' : undeclared identifier
getimagedata.cpp(44) : error C2146: syntax error : missing ';' before identifier 'LockedRect'
getimagedata.cpp(44) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(45) : error C2065: 'pTexture' : undeclared identifier
getimagedata.cpp(45) : error C2227: left of '->LockRect' must point to class/struct/union/generic type
type is ''unknown-type''
getimagedata.cpp(45) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(46) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(46) : error C2228: left of '.Pitch' must have class/struct/union
type is ''unknown-type''
getimagedata.cpp(48) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(48) : error C2228: left of '.pBits' must have class/struct/union
type is ''unknown-type''
getimagedata.cpp(78) : warning C4305: 'return' : truncation from 'int' to 'bool'
getimagedata.cpp(79) : error C2065: 'NuiImageBuffer' : undeclared identifier
getimagedata.cpp(79) : error C2065: 'pTexture' : undeclared identifier
getimagedata.cpp(80) : error C2065: 'KINECT_LOCKED_RECT' : undeclared identifier
getimagedata.cpp(80) : error C2146: syntax error : missing ';' before identifier 'LockedRect'
getimagedata.cpp(80) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(81) : error C2065: 'pTexture' : undeclared identifier
getimagedata.cpp(81) : error C2227: left of '->LockRect' must point to class/struct/union/generic type
type is ''unknown-type''
getimagedata.cpp(81) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(82) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(82) : error C2228: left of '.Pitch' must have class/struct/union
type is ''unknown-type''
getimagedata.cpp(84) : error C2065: 'LockedRect' : undeclared identifier
getimagedata.cpp(84) : error C2228: left of '.pBits' must have class/struct/union
type is ''unknown-type''

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

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

Comment only
01 Mar 2012 Yu-Hsin

Yu-Hsin (view profile)

Hi I_E,
Thanks for using my code. It's nice to know you've fixed the problem. Could you let me know what CPU you have? Thanks for your feedback!

Comment only
01 Mar 2012 I_E

I_E (view profile)

It's fixed now. I had to select the AMD64 lib instead of x86. The code works beautifully, thank you!

Comment only
01 Mar 2012 I_E

I_E (view profile)

Hello,

I am following your readme file and I'm trying to compile the .cpp file as follows:

mex getimagedata.cpp -I'C:\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\inc' 'C:\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\lib\x86\MSRKinectNUI.lib'

And I get the following response including errors:

Creating library C:\Users\ientin\AppData\Local\Temp\mex_e6LBC0\templib.x and object C:\Users\ientin\AppData\Local\Temp\mex_e6LBC0\templib.exp
getimagedata.obj : error LNK2019: unresolved external symbol __imp_NuiImageStreamOpen referenced in function "void __cdecl KinectInit(void)" (?KinectInit@@YAXXZ)
getimagedata.obj : error LNK2019: unresolved external symbol __imp_NuiInitialize referenced in function "void __cdecl KinectInit(void)" (?KinectInit@@YAXXZ)
getimagedata.obj : error LNK2019: unresolved external symbol __imp_NuiShutdown referenced in function "void __cdecl KinectShutdown(void)" (?KinectShutdown@@YAXXZ)
getimagedata.obj : error LNK2019: unresolved external symbol __imp_NuiImageStreamReleaseFrame referenced in function "bool __cdecl Nui_GotDepthAlert(double (* const)[640])" (?Nui_GotDepthAlert@@YA_NQEAY0CIA@N@Z)
getimagedata.obj : error LNK2019: unresolved external symbol __imp_NuiImageStreamGetNextFrame referenced in function "bool __cdecl Nui_GotDepthAlert(double (* const)[640])" (?Nui_GotDepthAlert@@YA_NQEAY0CIA@N@Z)
getimagedata.mexw64 : fatal error LNK1120: 5 unresolved externals

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

Do you know what's going wrong? Thank you!

Comment only
12 Jan 2012 Tingfan

@muhammad : Could you post the error msg?
@Fadel : the Kinect() function in this package along with the mex function does the job.

Comment only
14 Dec 2011 Fa Fa

Fa Fa (view profile)

hi,
can somebody give me an example, how to take photo from kinect camera with using matlab. please write an example,i have matlab 2011a.
thanks

Comment only
13 Dec 2011 Yu-Hsin

Yu-Hsin (view profile)

Hi there,
Thanks for using my code, could you paste your error message here?

Comment only
13 Dec 2011 muhammad Raza

Hi, Thanks for this good work, Its really good but unfortunately we are getting error while compiling that "getimagedata.mexw64' failed"

Can you please comment about this error. thanks

Comment only
17 Sep 2011 Tingfan

This software requires only Microsoft Kinect SDK (no Openni), which is simple and easy to use. I am using it to segment and track a ball at 640x480x30fps.

Comment only
17 Sep 2011 Tingfan  
17 Sep 2011 Tingfan  

Contact us