Jump to content

  • Log In with Google      Sign In   
  • Create Account


Unity 3D and Kinect wrapper (newer official SDK)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 BobXIV   Members   -  Reputation: 314

Like
0Likes
Like

Posted 23 January 2013 - 09:53 AM

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 | 
NuiInitializeFlags.UsesColor);

NativeMethods.NuiImageStreamOpen(NuiImageType.Depth, 
NuiImageResolution.resolution320x240, 0, 2, IntPtr.Zero, ref 
justDepthStreamHandle);

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

                  
// Here must be a LOCKRECT to imageFrame.pFrameTexture
                
// 
http://msdn.microsoft.com/en-us/library/nuiimagecamera.nui_image_frame.aspx

                
NuiImageBuffer imageBuf = 
(NuiImageBuffer)Marshal.PtrToStructure(imageFrame.pFrameTexture, 
typeof(NuiImageBuffer));

                
DepthBuffer db = 
(DepthBuffer)Marshal.PtrToStructure(imageBuf.m_pBuffer,typeof(DepthBuffer));
                
                                              
                
hr = NativeMethods.NuiImageStreamReleaseFrame(depthStreamHandle, 
imageFramePtr);
}

 

 

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:

 

 

 

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NuiImageFrame
{
                
public Int64 liTimeStamp;
                
public uint dwFrameNumber;
                
public NuiImageType eImageType;
                
public NuiImageResolution eResolution;
                
//[MarshalAsAttribute(UnmanagedType.LPStruct)]
                
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

 

Thanks



Sponsor:

#2 swiftcoder   Senior Moderators   -  Reputation: 9584

Like
0Likes
Like

Posted 23 January 2013 - 02:23 PM

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

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


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS