private Color32[] extractColorImage(NuiImageBuffer buf) { int totalPixels = buf.m_Width * buf.m_Height; Color32[] colorBuf = colorImage; ColorBuffer cb = (ColorBuffer)Marshal.PtrToStructure(buf.m_pBuffer, typeof(ColorBuffer)); for (int pix = 0; pix < totalPixels; pix++) { colorBuf[pix].r = cb.pixels[pix].r; colorBuf[pix].g = cb.pixels[pix].g; colorBuf[pix].b = cb.pixels[pix].b; } return(colorBuf); }
//poll kinect for updated color data bool KinectInterface.pollColor() { if (!updatedColor) { updatedColor = true; IntPtr imageFramePtr = IntPtr.Zero; int hr = NativeMethods.NuiImageStreamGetNextFrame(colorStreamHandle, 100, ref imageFramePtr); if (hr == 0) { newColor = true; NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame)); NuiImageBuffer imageBuf = (NuiImageBuffer)Marshal.PtrToStructure(imageFrame.pFrameTexture, typeof(NuiImageBuffer)); colorImage = extractColorImage(imageBuf); hr = NativeMethods.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr); } } return(newColor); }
/// <summary> ///The first time in each frame that it is called, poll the kinect for updated depth (and player) data and return ///true if there is new data. Subsequent calls do nothing and return the same value. /// </summary> /// <returns> /// A <see cref="System.Boolean"/> : is there new data this frame /// </returns> bool KinectInterface.pollDepth() { if (!updatedDepth) { updatedDepth = true; IntPtr imageFramePtr = IntPtr.Zero; int hr = NativeMethods.NuiImageStreamGetNextFrame(depthStreamHandle, 100, ref imageFramePtr); if (hr == 0) { newDepth = true; NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame)); NuiImageBuffer imageBuf = (NuiImageBuffer)Marshal.PtrToStructure(imageFrame.pFrameTexture, typeof(NuiImageBuffer)); depthPlayerData = extractDepthImage(imageBuf); hr = NativeMethods.NuiImageStreamReleaseFrame(depthStreamHandle, imageFramePtr); } } return(newDepth); }
/// <summary> ///The first time in each frame that it is called, poll the kinect for updated color data and return ///true if there is new data. Subsequent calls do nothing and return the same value. /// </summary> /// <returns> /// A <see cref="System.Boolean"/> : is there new data this frame /// </returns> bool KinectInterface.pollColor() { if (!updatedColor) { updatedColor = true; IntPtr imageFramePtr = IntPtr.Zero; int hr = NativeMethods.NuiImageStreamGetNextFrame(colorStreamHandle, 100, ref imageFramePtr); if (hr == 0) { newColor = true; NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame)); //Debug.Log("ptr:" + imageFramePtr + " frame:" + imageFrame.dwFrameNumber); NuiImageBuffer imageBuf = (NuiImageBuffer)Marshal.PtrToStructure(imageFrame.pFrameTexture, typeof(NuiImageBuffer)); //Debug.Log("width:" + imageBuf.m_Width + " height:" + imageBuf.m_Height + " total:" + (imageBuf.m_Width * imageBuf.m_Height * imageBuf.m_BytesPerPixel)); colorImage = extractColorImage(imageBuf); hr = NativeMethods.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr); } } return(newColor); }
private short[] extractDepthImage(NuiImageBuffer buf) { DepthBuffer db = (DepthBuffer)Marshal.PtrToStructure(buf.m_pBuffer, typeof(DepthBuffer)); return(db.pixels); }