Jump to content
  • Advertisement
Sign in to follow this  

Unity Unity 3D and Kinect wrapper (newer official SDK)

This topic is 2149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working in a wrapper to the current version of the Kinect official SDK (http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx) from C# inside Unity. The wrapper works making called through interop to the C API of the SDK. It is working in getting the skeletal information, but I’m having problems in retrieving the depth information of the camera. The problems is because I use the C API and there is no problem in making calls to a C function but to get the depth information I need to Lock a DirectX like Texture and because it is a class in this case I don’t know how to called the member function of Texture. The idea of the code I use is (not the actual code but the basic flow of calls) :


NativeMethods.NuiInitialize(NuiInitializeFlags.UsesDepthAndPlayerIndex | 
NuiInitializeFlags.UsesSkeleton | NuiInitializeFlags.UsesDepth | 

NuiImageResolution.resolution320x240, 0, 2, IntPtr.Zero, ref 

int hr = NativeMethods.NuiImageStreamGetNextFrame(justDepthStreamHandle, 100, 
ref imageFramePtr);
if (hr == 0)
NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, 

// Here must be a LOCKRECT to imageFrame.pFrameTexture

NuiImageBuffer imageBuf = 

DepthBuffer db = 
hr = NativeMethods.NuiImageStreamReleaseFrame(depthStreamHandle, 



If I do the code showed before the depth image I get is not the data instead it is just junk. My guess is that it is because the texture is not locked before accessing it but the problem is that LockRect is a member function (http://msdn.microsoft.com/en-us/library/jj663804.aspx).


The layout for the variable NuiImageBuffer imageBuf that I'm using is:




public struct NuiImageFrame
public Int64 liTimeStamp;
public uint dwFrameNumber;
public NuiImageType eImageType;
public NuiImageResolution eResolution;
public IntPtr pFrameTexture;
public uint dwFrameFlags_NotUsed;
public NuiImageViewArea ViewArea_NotUsed;




Note: the code is based in a wrapper of OpenNI for Unity. There is a Kinect wrapper also based in that OpenNI wrapper but it is from an older version of the Kinect SDK. This wrappers makes the code I show without Locking but it doesn’t work for me sad.png .


The wrapper is http://wiki.etc.cmu.edu/unity3d/index.php/Microsoft_Kinect_-_Microsoft_SDK



Share this post

Link to post
Share on other sites

[quote name='BobXIV' timestamp='1358956403' post='5024751']
I need to Lock a DirectX like Texture and because it is a class in this case I don’t know how to called the member function of Texture[/quote]

I've never used C#'s native interop in particular, but in general you would need to figure out both how the C++ compiler is name mangling member functions (varies from compiler to compiler), and what the calling convention is for member functions (is the 'this' pointer stored in a register or passed on the stack, where on the stack would it be passed?). At that point, if you are lucky, you can call the mangled function name as you would a C function, passing the this pointer as necessary.


It would probably be simpler/better to build a small wrapper library in C++ that exposes a set of C wrapper functions, and then call those wrapper functions from C#. The wrapper library could be distributed along with your script...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!