private short[] extractDepthImage(NuiLockedRect lockedRect) { DepthBuffer db = (DepthBuffer)Marshal.PtrToStructure(lockedRect.pBits,typeof(DepthBuffer)); return db.pixels; }
private Color32[] extractColorImage(NuiLockedRect buf) { int totalPixels = 640*480; Color32[] colorBuf = colorImage; ColorBuffer cb = (ColorBuffer)Marshal.PtrToStructure(buf.pBits,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; }
/// <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)); INuiFrameTexture frameTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(imageFrame.pFrameTexture); NuiLockedRect lockedRectPtr = new NuiLockedRect(); IntPtr r = IntPtr.Zero; frameTexture.LockRect(0,ref lockedRectPtr,r,0); colorImage = extractColorImage(lockedRectPtr); 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; /* KK Addition*/ /// <summary> /// Sets near mode - move this into the Awake () function /// if you do not need to constantly change between near and far mode /// current organization is this way to allow for rapid changes IF they're required /// and to allow for experimentation with the 2 modes /// </summary> if (enableNearMode) { NativeMethods.NuiImageStreamSetImageFrameFlags (depthStreamHandle, NuiImageStreamFlags.EnableNearMode); //test = NativeMethods.NuiImageStreamSetImageFrameFlags // (depthStreamHandle, NuiImageStreamFlags.TooFarIsNonZero); } else { NativeMethods.NuiImageStreamSetImageFrameFlags (depthStreamHandle, NuiImageStreamFlags.None); } int hr = NativeMethods.NuiImageStreamGetNextFrame(depthStreamHandle, 100, ref imageFramePtr); if (hr == 0){ newDepth = true; NuiImageFrame imageFrame; imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame)); INuiFrameTexture frameTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(imageFrame.pFrameTexture); NuiLockedRect lockedRectPtr = new NuiLockedRect(); IntPtr r = IntPtr.Zero; frameTexture.LockRect(0,ref lockedRectPtr,r,0); depthPlayerData = extractDepthImage(lockedRectPtr); frameTexture.UnlockRect(0); hr = NativeMethods.NuiImageStreamReleaseFrame(depthStreamHandle, imageFramePtr); } } return newDepth; }
private short[] extractDepthImage(NuiLockedRect lockedRect) { if (DepthResolution == NuiImageResolution.resolution320x240) { DepthBuffer db = (DepthBuffer)Marshal.PtrToStructure(lockedRect.pBits, typeof(DepthBuffer)); return db.pixels; } else { DepthBufferLarge db = (DepthBufferLarge)Marshal.PtrToStructure(lockedRect.pBits, typeof(DepthBufferLarge)); return db.pixels; } }