public static bool PollDepth(IntPtr depthStreamHandle, bool isNearMode, ref short[] depthPlayerData) { IntPtr imageFramePtr = IntPtr.Zero; bool newDepth = false; if (isNearMode) { KinectWrapper.NuiImageStreamSetImageFrameFlags(depthStreamHandle, NuiImageStreamFlags.EnableNearMode); } else { KinectWrapper.NuiImageStreamSetImageFrameFlags(depthStreamHandle, NuiImageStreamFlags.None); } int hr = KinectWrapper.NuiImageStreamGetNextFrame(depthStreamHandle, 0, ref imageFramePtr); if (hr == 0) { newDepth = 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); depthPlayerData = ExtractDepthImage(lockedRectPtr); frameTexture.UnlockRect(0); hr = KinectWrapper.NuiImageStreamReleaseFrame(depthStreamHandle, imageFramePtr); } return(newDepth); }
public static bool PollColor(IntPtr colorStreamHandle, ref Color32[] colorImage) { IntPtr imageFramePtr = IntPtr.Zero; bool newColor = false; int hr = KinectWrapper.NuiImageStreamGetNextFrame(colorStreamHandle, 0, 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); ExtractColorImage(lockedRectPtr, ref colorImage); frameTexture.UnlockRect(0); hr = KinectWrapper.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr); } return(newColor); }
public static bool PollColor(IntPtr colorStreamHandle, ref byte[] videoBuffer) { IntPtr imageFramePtr = IntPtr.Zero; bool newColor = false; int hr = KinectV1Wrapper.NuiImageStreamGetNextFrame(colorStreamHandle, 0, 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); Marshal.Copy(lockedRectPtr.pBits, videoBuffer, 0, videoBuffer.Length); frameTexture.UnlockRect(0); hr = KinectV1Wrapper.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr); } else { Debug.Log("color frame not ready " + hr.ToString()); } 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); }
//public static bool PollColor(IntPtr colorStreamHandle, ref byte[] videoBuffer, ref Color32[] colorImage) public static bool PollColor(IntPtr colorStreamHandle, ref Color32[] colorImage) { IntPtr imageFramePtr = IntPtr.Zero; bool newColor = false; int hr = KinectWrapper.NuiImageStreamGetNextFrame(colorStreamHandle, 0, 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); ColorBuffer cb = (ColorBuffer)Marshal.PtrToStructure(lockedRectPtr.pBits, typeof(ColorBuffer)); int totalPixels = Constants.ColorImageWidth * Constants.ColorImageHeight; for (int pix = 0; pix < totalPixels; pix++) { int ind = pix; // totalPixels - pix - 1; colorImage[ind].r = cb.pixels[pix].r; colorImage[ind].g = cb.pixels[pix].g; colorImage[ind].b = cb.pixels[pix].b; colorImage[ind].a = 255; // videoBuffer[4 * ind] = cb.pixels[pix].b; // videoBuffer[4 * ind + 1] = cb.pixels[pix].g; // videoBuffer[4 * ind + 2] = cb.pixels[pix].r; // videoBuffer[4 * ind + 3] = 255; } frameTexture.UnlockRect(0); hr = KinectWrapper.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr); } return(newColor); }