Hello! Im currently working on a project where I need to display a pointcloud using Kinect, which I already achieved. The result can be seen at the uploaded picture. The problem is that the RGB camera and the Depth camera are not calibrated, so the the pixels from each camera arent corresponding to each other at the moment. After searching at the Kinect SDK documentation, I saw that there is this method called KinectSensor.MapDepthFrameToColorFrame ( http://msdn.microsoft.com/en-us/library/microsoft.kinect.kinectsensor.mapdepthframetocolorframe.aspx ), which does exactly what I need to match both streams. But then again I cant seem to find this method within Unity Kinect Plugin ( http://wiki.etc.cmu.edu/unity3d/index.php/Microsoft_Kinect_-_Microsoft_SDK ). Is such method implemented? Is there another easy way to achieve the same result? I know that I can calibrate it myself by multiplying Projection and Modelview Matrixes, but that would be a bummer. Thank you all for the help!
If you check the header files from the Kinect SDK directory for the function/parameters, you can add the function yourself inside the KinectInterop class
After checking the documentation, here is my try based on your suggestion: At KinectInterop.cs, within NativeMethods class, I did this: Code (CSharp): [DllImportAttribute(@"C:\Windows\System32\Kinect10.dll", EntryPoint = "MapDepthFrameToColorFrame")] public static extern int MapDepthFrameToColorFrame( DepthImageFormat depthImageFormat, ref DepthImagePixel[] depthPixels, ColorImageFormat colorImageFormat, ref ColorImagePoint[] colorPoints); The structs are defined before NativeMethods class and goes as follow: Code (CSharp): [StructLayout(LayoutKind.Sequential)] public struct ColorImagePoint { public int X; public int Y; } [StructLayout(LayoutKind.Sequential)] public struct DepthImagePixel { public Int16 Depth; public bool IsKnownDepth; public Int16 PlayerIndex; } public enum ColorImageFormat : int { RGB = 0, YUV = 1, Bayer = 2, Undefined = 3, } public enum DepthImageFormat : int { Resolution320x240Fps30 = 0, Resolution640x480Fps30 = 1, Resolution80x60Fps30 = 2, Undefined = 3 } Now at the main file: Code (CSharp): private Kinect.ColorImagePoint[] mappedDepthLocations; private Kinect.DepthImagePixel[] depthStreamPixel; void Start () { mappedDepthLocations = new Kinect.ColorImagePoint[depthImageHeight*depthImageWidth]; depthStreamPixel = new Kinect.DepthImagePixel[depthImageHeight*depthImageWidth]; } void Update () { if (depthStream.pollDepth () && colorStream.pollColor()) { for ( int i = 0; i < depthImageWidth; i++ ) { for ( int j = 0; j < depthImageHeight; j++ ) { int index = i+j*depthImageWidth; depthStreamPixel[index].Depth = depthStream.depthImg[index]; depthStreamPixel[index].IsKnownDepth = true; depthStreamPixel[index].PlayerIndex = 0; } } Kinect.NativeMethods. MapDepthFrameToColorFrame ( Kinect.DepthImageFormat.Resolution320x240Fps30, ref depthStreamPixel, Kinect.ColorImageFormat.RGB, ref mappedDepthLocations ); } } This is giving me the following error: EntryPointNotFoundException. After double checking the Kinect SDK reference ( http://msdn.microsoft.com/en-us/library/jj883690.aspx ), Ive seen that the class defined is within the CoordinateMapper class, which is not defined, but should it really be? If thats not the problem, what could it be? Im kinda lost here, is the first time Im working with these DllImportAttribute methods.
if you look here : http://msdn.microsoft.com/en-us/library/microsoft.kinect.kinectsensor.mapdepthframetocolorframe.aspx (MSDN has some good documentation on Kinect SDK btw) It says: Obsolete starting with version 1.6; replaced by the CoordinateMapper.MapDepthFrameToColorFrame method. In versions prior to 1.6, this method maps a depth frame to a color frame. So I guess you are using an SDK version > 1.6, use the CoordinateMapper.MapDepthFrameToColorFrame instead
So, should I just use this instead? Code (CSharp): [DllImportAttribute(@"C:\Windows\System32\Kinect10.dll", EntryPoint = "CoordinateMapper.MapDepthFrameToColorFrame")] public static extern int MapDepthFrameToColorFrame( DepthImageFormat depthImageFormat, ref DepthImagePixel[] depthPixels, ColorImageFormat colorImageFormat, ref ColorImagePoint[] colorPoints);
Its been awhile, but Microsoft released an official asset that supports Kinect on Unity. Here's the link: http://wiki.etc.cmu.edu/unity3d/index.php/Microsoft_Kinect_-_Microsoft_SDK This asset allowed me to map color to depth correctly.